From 25e94d9d7f86f9d9ad457bb9a7cb7f8cd97a0f17 Mon Sep 17 00:00:00 2001 From: Doug <6060466+pixlwave@users.noreply.github.com> Date: Fri, 12 Apr 2024 10:45:29 +0100 Subject: [PATCH] Fix a bug where the view state is being modified during an update. (#2686) --- .../Other/SwiftUI/Layout/FullscreenDialog.swift | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/ElementX/Sources/Other/SwiftUI/Layout/FullscreenDialog.swift b/ElementX/Sources/Other/SwiftUI/Layout/FullscreenDialog.swift index 3649ea933..3d33b48b0 100644 --- a/ElementX/Sources/Other/SwiftUI/Layout/FullscreenDialog.swift +++ b/ElementX/Sources/Other/SwiftUI/Layout/FullscreenDialog.swift @@ -135,12 +135,21 @@ struct FullscreenDialog: 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 + } + } } }