Skip to content

Instantly share code, notes, and snippets.

@kirti-swiggy
Created February 6, 2023 10:33
Show Gist options
  • Save kirti-swiggy/72ee65acacdbf97282a135edecf7f828 to your computer and use it in GitHub Desktop.
Save kirti-swiggy/72ee65acacdbf97282a135edecf7f828 to your computer and use it in GitHub Desktop.
ViewModifier to track when the View is visible if it's embedded in ScrollView.
struct VisibilityModifier: ViewModifier{
let positionOffset : Double
let height = UIScreen.main.bounds.height
func body(content: Content) -> some View {
GeometryReader { geometry in
let position = geometry.frame(in: CoordinateSpace.global).midY
ZStack {
Color.clear
if height >= (position + positionOffset) {
content
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment