mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 01:20:12 +00:00
Use onScrollGeometryChange to hide the scrollable media caption fade. (#5559)
Fixes a hang on macOS and more closely aligns with Android.
This commit is contained in:
+12
-13
@@ -333,21 +333,21 @@ private struct CaptionScrollView: View {
|
|||||||
@State private var shouldShowFade = false
|
@State private var shouldShowFade = false
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ZStack(alignment: .bottom) {
|
|
||||||
ScrollView(.vertical) {
|
ScrollView(.vertical) {
|
||||||
captionContent
|
captionContent
|
||||||
.background {
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
GeometryReader { geometry in
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
shouldShowFade = geometry.size.height > maxHeight
|
|
||||||
}
|
|
||||||
return Color.clear
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.frame(maxHeight: maxHeight)
|
|
||||||
.padding(16)
|
.padding(16)
|
||||||
|
}
|
||||||
|
.onScrollGeometryChange(for: Bool.self) { geometry in
|
||||||
|
geometry.contentOffset.y >= geometry.contentSize.height - geometry.containerSize.height - geometry.contentInsets.bottom
|
||||||
|
} action: { _, isBottomVisible in
|
||||||
|
if shouldShowFade == isBottomVisible {
|
||||||
|
withAnimation(.elementDefault) { shouldShowFade = !isBottomVisible }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.scrollBounceBehavior(.basedOnSize)
|
||||||
|
.frame(maxHeight: maxHeight)
|
||||||
|
.overlay(alignment: .bottom) {
|
||||||
if shouldShowFade {
|
if shouldShowFade {
|
||||||
LinearGradient(stops: [.init(color: .clear, location: 0.0),
|
LinearGradient(stops: [.init(color: .clear, location: 0.0),
|
||||||
.init(color: .black.opacity(0.5), location: 1.0)],
|
.init(color: .black.opacity(0.5), location: 1.0)],
|
||||||
@@ -356,7 +356,6 @@ private struct CaptionScrollView: View {
|
|||||||
.frame(height: 40)
|
.frame(height: 40)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.frame(maxWidth: .infinity, alignment: .leading)
|
|
||||||
.background {
|
.background {
|
||||||
BlurEffectView(style: .systemChromeMaterial)
|
BlurEffectView(style: .systemChromeMaterial)
|
||||||
.ignoresSafeArea()
|
.ignoresSafeArea()
|
||||||
|
|||||||
Reference in New Issue
Block a user