Skip to content

Instantly share code, notes, and snippets.

@karthironald
Created May 1, 2020 17:26
Show Gist options
  • Save karthironald/8a2fc38e4ef74cd113b1f7deb163ee9f to your computer and use it in GitHub Desktop.
Save karthironald/8a2fc38e4ef74cd113b1f7deb163ee9f to your computer and use it in GitHub Desktop.
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