Skip to content

Instantly share code, notes, and snippets.

@lucianoschillagi
Created November 8, 2024 21:30
Show Gist options
  • Save lucianoschillagi/f3f302ac97479672af72dc65d123fcdf to your computer and use it in GitHub Desktop.
Save lucianoschillagi/f3f302ac97479672af72dc65d123fcdf to your computer and use it in GitHub Desktop.
SwiftUI View Lifecycle Methods (onAppear, onDisappear)
import SwiftUI
struct ContentView: View {
@State private var isSheetPresented: Bool = false
var body: some View {
VStack {
Button("Show Sheet") {
isSheetPresented = true
}
.font(.title)
.sheet(isPresented: $isSheetPresented) {
SheetView()
}
}
}
}
struct SheetView: View {
var body: some View {
VStack {
Text("This is a sheet view!")
.font(.title)
.bold()
.padding()
}
.onAppear() {
print("Sheet is appear!")
}
.onDisappear {
print("Sheet has disappeared!")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment