Created
May 1, 2020 17:26
-
-
Save karthironald/8a2fc38e4ef74cd113b1f7deb163ee9f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct ContentView: View { | |
let products = ["iPhone", "iPad", "iMac", "MacBook", "Watch", "AppleTv"] | |
@State private var shouldShowSlider = false | |
@State private var size: CGFloat = 20.0 | |
var body: some View { | |
NavigationView { | |
VStack { | |
Section { | |
Toggle(isOn: $shouldShowSlider) { | |
Text("Wanna change font size?") | |
} | |
}.padding() | |
if shouldShowSlider { | |
Slider(value: $size, in: 15...30, label: { | |
Text("Font size") | |
}).padding() | |
.onAppear { print("🟠 Appear") } | |
.onDisappear { print("🟠 Disappear") } | |
} | |
Section { | |
List(products, id: \.self) { product in | |
NavigationLink(destination: DetailView(productName: product)) { | |
Text(product) | |
.font(.system(size: self.size)) | |
} | |
} | |
.navigationBarTitle(Text("Products")) | |
.onAppear { print("🟢 OnAppear") } | |
.onDisappear { print("🟢 OnDisappear") } | |
} | |
} | |
} | |
.onAppear { print("🔴 OnAppear") } | |
.onDisappear { print("🔴 OnDisappear") } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment