Skip to content

Commit 0119cbc

Browse files
authored
feat(iOS, SplitView): Add support for showsSecondaryOnlyButton (#3002)
## Description Closes software-mansion/react-native-screens-labs#231 Adding setter for showsSecondaryOnlyButton which adds native button for toggling display mode to `secondaryOnly`. ### Notes: - In the pure native app, when I wanted to change this value dynamically, update for button visibility was applied after another interaction, like swiping one of columns. ## Changes - Added native setter - Updated native component in JS - Updated app ## Test code and steps to reproduce Added this prop to `SplitViewBaseApp` ## Checklist - [x] Included code example that can be used to test this change - [x] Ensured that CI passes
1 parent 260b3fd commit 0119cbc

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

ios/gamma/split-view/RNSSplitViewHostComponentView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ NS_ASSUME_NONNULL_BEGIN
2222
@property (nonatomic, readonly) UISplitViewControllerPrimaryEdge primaryEdge;
2323
@property (nonatomic, readonly) UISplitViewControllerDisplayMode displayMode;
2424
@property (nonatomic, readonly) BOOL presentsWithGesture;
25+
@property (nonatomic, readonly) BOOL showSecondaryToggleButton;
2526

2627
@end
2728

ios/gamma/split-view/RNSSplitViewHostComponentView.mm

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ @implementation RNSSplitViewHostComponentView {
1919
NSMutableArray<RNSSplitViewScreenComponentView *> *_Nonnull _reactSubviews;
2020

2121
bool _hasModifiedReactSubviewsInCurrentTransaction;
22+
// We need this information to warn users about dynamic changes to behavior being currently unsupported.
23+
bool _isShowSecondaryToggleButtonSet;
2224
}
2325

2426
- (instancetype)initWithFrame:(CGRect)frame
@@ -50,6 +52,9 @@ - (void)resetProps
5052
_primaryEdge = UISplitViewControllerPrimaryEdgeLeading;
5153
_displayMode = UISplitViewControllerDisplayModeAutomatic;
5254
_presentsWithGesture = true;
55+
_showSecondaryToggleButton = false;
56+
57+
_isShowSecondaryToggleButtonSet = false;
5358
}
5459

5560
- (void)didMoveToWindow
@@ -161,6 +166,20 @@ - (void)updateProps:(const facebook::react::Props::Shared &)props
161166
_controller.presentsWithGesture = _presentsWithGesture;
162167
}
163168

169+
if (oldComponentProps.showSecondaryToggleButton != newComponentProps.showSecondaryToggleButton) {
170+
_showSecondaryToggleButton = newComponentProps.showSecondaryToggleButton;
171+
_controller.showsSecondaryOnlyButton = _showSecondaryToggleButton;
172+
173+
if (_isShowSecondaryToggleButtonSet) {
174+
RCTLogWarn(@"[RNScreens] changing showSecondaryToggleButton dynamically is currently unsupported");
175+
}
176+
}
177+
178+
// This flag is set to true when showsSecondaryOnlyButton prop is assigned for the first time.
179+
// This allows us to identify any subsequent changes to this prop,
180+
// enabling us to warn users that dynamic changes are not supported.
181+
_isShowSecondaryToggleButtonSet = true;
182+
164183
[super updateProps:props oldProps:oldProps];
165184
}
166185

src/components/gamma/SplitViewHost.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,7 @@ import type {
99
} from '../../fabric/gamma/SplitViewHostNativeComponent';
1010

1111
export type SplitViewNativeProps = NativeProps & {
12-
// SplitView appearance
13-
14-
displayMode?: SplitViewDisplayMode;
15-
splitBehavior?: SplitViewSplitBehavior;
16-
17-
// SplitView interactions
18-
19-
presentsWithGesture?: boolean;
12+
// Overrides
2013
};
2114

2215
type SplitViewHostProps = {

src/fabric/gamma/SplitViewHostNativeComponent.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ export interface NativeProps extends ViewProps {
2828
splitBehavior?: WithDefault<SplitViewSplitBehavior, 'automatic'>;
2929
primaryEdge?: WithDefault<SplitViewPrimaryEdge, 'leading'>;
3030

31+
// NOTE: this setter cannot change the value dynamically, even in pure native app
32+
showSecondaryToggleButton?: WithDefault<boolean, false>;
33+
3134
// Interactions
3235

3336
presentsWithGesture?: WithDefault<boolean, true>;

0 commit comments

Comments
 (0)