-
Notifications
You must be signed in to change notification settings - Fork 86
Open
Description
I was having this, to run some code only on the first time , not after details screen popped
public extension View {
func onFirstAppear(_ action: @escaping () -> Void) -> some View {
modifier(FirstAppear(action: action))
}
}
private struct FirstAppear: ViewModifier {
let action: () -> Void
// Use this to only fire your block one time
@State private var hasAppeared = false
func body(content: Content) -> some View {
// And then, track it here
content.onAppear {
guard !hasAppeared else { return }
hasAppeared = true
action()
}
}
}
Metadata
Metadata
Assignees
Labels
No labels