Created
November 8, 2024 21:30
-
-
Save lucianoschillagi/f3f302ac97479672af72dc65d123fcdf to your computer and use it in GitHub Desktop.
SwiftUI View Lifecycle Methods (onAppear, onDisappear)
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 { | |
@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