Skip to content

Commit 260b3fd

Browse files
authored
feat(iOS, SplitView): Add support for presentsWithGesture prop (#3001)
## Description SplitView installs its own GestureRecognizer for changing the display mode. There's a method `presentsWithGesture` which can disable this GestureRecognizer. In this PR I am adding a setter for this API from the JS native component. ## Changes - Updated example - Added native setter - Updated JS native component definition ## Test code and steps to reproduce Updated `SplitViewBaseApp` https://github.com/user-attachments/assets/a5cf2bd3-0183-4258-89bf-34c84b7ed589 ## Checklist - [x] Included code example that can be used to test this change - [x] Ensured that CI passes Closes software-mansion/react-native-screens-labs#230
1 parent 346d86d commit 260b3fd

File tree

5 files changed

+21
-13
lines changed

5 files changed

+21
-13
lines changed

apps/src/tests/TestSplitView/SplitViewBaseApp.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const SplitViewBaseApp = () => {
2323
const [buttonState4, setButtonState4] = React.useState('Initial');
2424

2525
return (
26-
<SplitViewHost displayMode='oneOverSecondary' primaryEdge='leading' splitBehavior='tile'>
26+
<SplitViewHost displayMode='twoBesideSecondary' primaryEdge='leading' presentsWithGesture={false} splitBehavior='tile'>
2727
<SplitViewScreen>
2828
<View style={[styles.container, { backgroundColor: Colors.RedDark100 }]}>
2929
<TestButton setButtonState={setButtonState} />

ios/gamma/split-view/RNSSplitViewHostComponentView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
2121
@property (nonatomic, readonly) UISplitViewControllerSplitBehavior splitBehavior;
2222
@property (nonatomic, readonly) UISplitViewControllerPrimaryEdge primaryEdge;
2323
@property (nonatomic, readonly) UISplitViewControllerDisplayMode displayMode;
24+
@property (nonatomic, readonly) BOOL presentsWithGesture;
2425

2526
@end
2627

ios/gamma/split-view/RNSSplitViewHostComponentView.mm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ - (void)resetProps
4949
_splitBehavior = UISplitViewControllerSplitBehaviorAutomatic;
5050
_primaryEdge = UISplitViewControllerPrimaryEdgeLeading;
5151
_displayMode = UISplitViewControllerDisplayModeAutomatic;
52+
_presentsWithGesture = true;
5253
}
5354

5455
- (void)didMoveToWindow
@@ -155,6 +156,11 @@ - (void)updateProps:(const facebook::react::Props::Shared &)props
155156
_controller.preferredDisplayMode = _displayMode;
156157
}
157158

159+
if (oldComponentProps.presentsWithGesture != newComponentProps.presentsWithGesture) {
160+
_presentsWithGesture = newComponentProps.presentsWithGesture;
161+
_controller.presentsWithGesture = _presentsWithGesture;
162+
}
163+
158164
[super updateProps:props oldProps:oldProps];
159165
}
160166

src/components/gamma/SplitViewHost.tsx

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ export type SplitViewNativeProps = NativeProps & {
1313

1414
displayMode?: SplitViewDisplayMode;
1515
splitBehavior?: SplitViewSplitBehavior;
16+
17+
// SplitView interactions
18+
19+
presentsWithGesture?: boolean;
1620
};
1721

1822
type SplitViewHostProps = {
@@ -46,12 +50,9 @@ const isValidDisplayModeForSplitBehavior = (
4650
);
4751
};
4852

49-
function SplitViewHost({
50-
children,
51-
displayMode,
52-
primaryEdge,
53-
splitBehavior,
54-
}: SplitViewHostProps) {
53+
function SplitViewHost(props: SplitViewHostProps) {
54+
const { displayMode, splitBehavior } = props;
55+
5556
React.useEffect(() => {
5657
if (displayMode && splitBehavior) {
5758
const isValid = isValidDisplayModeForSplitBehavior(
@@ -72,12 +73,8 @@ function SplitViewHost({
7273
}, [displayMode, splitBehavior]);
7374

7475
return (
75-
<SplitViewHostNativeComponent
76-
displayMode={displayMode}
77-
style={styles.container}
78-
splitBehavior={splitBehavior}
79-
primaryEdge={primaryEdge}>
80-
{children}
76+
<SplitViewHostNativeComponent {...props} style={styles.container}>
77+
{props.children}
8178
</SplitViewHostNativeComponent>
8279
);
8380
}

src/fabric/gamma/SplitViewHostNativeComponent.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ export interface NativeProps extends ViewProps {
2727
displayMode?: WithDefault<SplitViewDisplayMode, 'automatic'>;
2828
splitBehavior?: WithDefault<SplitViewSplitBehavior, 'automatic'>;
2929
primaryEdge?: WithDefault<SplitViewPrimaryEdge, 'leading'>;
30+
31+
// Interactions
32+
33+
presentsWithGesture?: WithDefault<boolean, true>;
3034
}
3135

3236
export default codegenNativeComponent<NativeProps>('RNSSplitViewHost', {});

0 commit comments

Comments
 (0)