Created
February 6, 2023 10:33
-
-
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.
This file contains hidden or 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
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