Fix a bug where the view state is being modified during an update. (#2686)

This commit is contained in:
Doug
2024-04-12 10:45:29 +01:00
committed by GitHub
parent 46d5057f8e
commit 25e94d9d7f

View File

@@ -135,12 +135,21 @@ struct FullscreenDialog<Content: View, BottomContent: View>: View {
func updateBackgroundVisibility(scrollView: UIScrollView) {
guard dynamicTypeSize < .accessibility1 else {
showsBackground = true
if !showsBackground {
showsBackground = true
}
return
}
let insetHeight = scrollView.adjustedContentInset.top + scrollView.adjustedContentInset.bottom
let availableHeight = scrollView.frame.height - insetHeight
showsBackground = scrollView.contentSize.height < availableHeight
DispatchQueue.main.async { // Don't modify the state during a view update.
let insetHeight = scrollView.adjustedContentInset.top + scrollView.adjustedContentInset.bottom
let availableHeight = scrollView.frame.height - insetHeight
let shouldShowBackground = scrollView.contentSize.height < availableHeight
if showsBackground != shouldShowBackground {
showsBackground = shouldShowBackground
}
}
}
}