Skip to content

Commit

Permalink
Fix first layout needing update on iOS 15
Browse files Browse the repository at this point in the history
  • Loading branch information
n8chur committed Mar 27, 2024
1 parent b54de19 commit 7cb26e6
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions WorkflowSwiftUIExperimental/Sources/SwiftUIScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,11 @@ private final class ModeledHostingController<Model, Content: View>: 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
}
}
}
Expand All @@ -173,12 +171,10 @@ private final class ModeledHostingController<Model, Content: View>: 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()
}
}
Expand Down

0 comments on commit 7cb26e6

Please sign in to comment.