Skip to content

Instantly share code, notes, and snippets.

@lhoward
Created October 31, 2020 21:37
Show Gist options
  • Select an option

  • Save lhoward/b2edc60db631c788c9d155760c759a09 to your computer and use it in GitHub Desktop.

Select an option

Save lhoward/b2edc60db631c788c9d155760c759a09 to your computer and use it in GitHub Desktop.
import SwiftUI
struct IsVisibleModifier: ViewModifier {
@Binding var isVisible: Bool
func body(content: Content) -> some View {
content
.onAppear {
self.isVisible = true
}
.onDisappear {
self.isVisible = false
}
}
}
extension View {
public func isVisible(_ isVisible: Binding<Bool>) -> some View {
return self.modifier(IsVisibleModifier(isVisible: isVisible))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment