Skip to content
Merged
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
21 changes: 20 additions & 1 deletion src/components/gamma/split-view/SplitViewHost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
SplitViewHostProps,
SplitViewSplitBehavior,
} from './SplitViewHost.types';
import SplitViewScreen from './SplitViewScreen';

// According to the UIKit documentation: https://developer.apple.com/documentation/uikit/uisplitviewcontroller/displaymode-swift.enum
// Only specific pairs for displayMode - splitBehavior are valid and others may lead to unexpected results.
Expand Down Expand Up @@ -59,8 +60,26 @@ function SplitViewHost(props: SplitViewHostProps) {
}
}, [preferredDisplayMode, preferredSplitBehavior]);

const children = React.Children.toArray(props.children);

const columns = children.filter(
// @ts-ignore - type is valid attribute for child
child => child.type === SplitViewScreen.Column,
);

const inspectors = children.filter(
// @ts-ignore - type is valid attribute for child
child => child.type === SplitViewScreen.Inspector,
);

return (
<SplitViewHostNativeComponent {...props} style={styles.container}>
<SplitViewHostNativeComponent
// UISplitViewController requires the number of columns to be specified at initialization and it cannot be changed dynamically later.
// By using a specific key in this form, we can detect changes in the number of React children.
// This enables us to fully recreate the SplitView when necessary, ensuring the correct column configuration is always applied.
key={`columns-${columns.length}-inspectors-${inspectors.length}`}
{...props}
style={styles.container}>
{props.children}
</SplitViewHostNativeComponent>
);
Expand Down
Loading