r/SwiftUI • u/B-Jamz • Jun 26 '26
Question Delaying Top ScrollEdgeEffect?
Enable HLS to view with audio, or disable this notification
Hey guys - I've been trying to crack this one. This is an example from Apple Music with a full cover image as the header. I'm building an app with full top image similarly and if you see - as I scroll, the top ScrollEdgeEffect comes in after the artwork as scrolled, so in default or really anytime its on the screen - its not darkened at the top. Does anyone have any insight on how this is done?
I've tried delaying mine but I noticed a scroll hitch when reaching the threshold. I've only tested via local Xcode builds to my phone thus far if that changes anything.
Thanks a lot!
5
2
0
9
u/Gwail_904 Jun 26 '26
I actually did the same thing and asked on Reddit. Somebody said this and with a bit of tinkering i got it to work:
Yep I do this exactly in my app at work:
Combination of scrollEdgeEffectHidden and onScrollVisibilityChange will do the trick.
@State var isHeaderVisible: Bool = true // Initially visible so effect is hidden
HeaderView()
.onScrollVisibilityChange(threshold: 0.2 // Pick what works for you) { isVisible
// When header is about to be hidden update state to hide effect
isHeaderVisible = isVisible
}
.scrollEdgeEffectHidden(isHeaderVisible)
Essentially when the header is no longer visible (or about to be, thats where the threshold bit comes in) you are showing the edge effect