Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions ios/gamma/split/RNSSplitScreenController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,40 @@ public class RNSSplitScreenController: UIViewController {
return
}

let ancestorView = findSplitHostController()?.view
assert(
ancestorView != nil,
"[RNScreens] Expected to find RNSSplitHost component for RNSSplitScreen component"
)
guard let splitHostController = findSplitHostController(),
let ancestorView = splitHostController.view
else {
assertionFailure(
"[RNScreens] Expected to find RNSSplitHost component for RNSSplitScreen component")
return
}

var targetFrame = splitScreenComponentView.bounds

///
/// When a UISplitViewController collapses into a single column, it hides columns and pushes
/// them onto a UINavigationController stack. To optimize resources, UIKit
/// does NOT update the frames of these off-screen views - they retain their old widths.
///
/// When navigating back to a hidden column, UIKit performs the transition animation, but skips calling
/// `setFrame:` on our actual component view, relying on AutoLayout to resize the content.
///
/// However, Yoga is expecting absolute values. If we rely strictly on the component's current frame
/// during this transition, Yoga will receive the stale width and then calculate the layout incorrectly, breaking the UI.
///
/// To fix this, if the SplitView is collapsed, we know the column must span the entire screen.
/// We preemptively extract the host's bounds and send them as the target frame to the ShadowTree,
/// ensuring the column renders at full width.
///
if splitHostController.isCollapsed {
targetFrame = ancestorView.convert(ancestorView.bounds, to: splitScreenComponentView)
}

shadowStateProxy.updateShadowState(
ofComponent: splitScreenComponentView, inContextOfAncestorView: ancestorView)
ofComponent: splitScreenComponentView,
withFrame: targetFrame,
inContextOfAncestorView: ancestorView
)
}

///
Expand Down
Loading