From 7cb26e65e149223782925aa1f69139a82f842e4a Mon Sep 17 00:00:00 2001 From: Westin Newell Date: Wed, 27 Mar 2024 11:58:24 -0700 Subject: [PATCH] Fix first layout needing update on iOS 15 --- .../Sources/SwiftUIScreen.swift | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/WorkflowSwiftUIExperimental/Sources/SwiftUIScreen.swift b/WorkflowSwiftUIExperimental/Sources/SwiftUIScreen.swift index cef7f03c6..73539c241 100644 --- a/WorkflowSwiftUIExperimental/Sources/SwiftUIScreen.swift +++ b/WorkflowSwiftUIExperimental/Sources/SwiftUIScreen.swift @@ -150,13 +150,11 @@ private final class ModeledHostingController: UIHostingCon preferredContentSize = size } } - } else if !swiftUIScreenSizingOptions.isEmpty { - if swiftUIScreenSizingOptions.contains(.preferredContentSize) { - let size = view.sizeThatFits(view.frame.size) + } else if swiftUIScreenSizingOptions.contains(.preferredContentSize) { + let size = view.sizeThatFits(view.frame.size) - if preferredContentSize != size { - preferredContentSize = size - } + if preferredContentSize != size { + preferredContentSize = size } } } @@ -173,12 +171,10 @@ private final class ModeledHostingController: UIHostingCon } private func setNeedsLayoutBeforeFirstLayoutIfNeeded() { - if #available(iOS 16.0, *), - swiftUIScreenSizingOptions.contains(.preferredContentSize) { + if swiftUIScreenSizingOptions.contains(.preferredContentSize) { // Without manually calling setNeedsLayout here it was observed that a call to // layoutIfNeeded() immediately after loading the view would not perform a layout, and - // therefore would not update the preferredContentSize on the first layout in - // viewDidLayoutSubviews() below. + // therefore would not update the preferredContentSize in viewDidLayoutSubviews(). view.setNeedsLayout() } }