Skip to content

Commit

Permalink
Fix a bug where the view state is being modified during an update. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave authored Apr 12, 2024
1 parent fc1310d commit cc95c6a
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions ElementX/Sources/Other/SwiftUI/Layout/FullscreenDialog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}

Expand Down

0 comments on commit cc95c6a

Please sign in to comment.