Skip to content

Commit 29b675d

Browse files
committed
Extract helper for conditional application
1 parent 5b914b5 commit 29b675d

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

src/components/Screen.tsx

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,32 @@ function resolveSheetInitialDetentIndex(
157157
return index;
158158
}
159159

160+
function transformEdgeToEdgeProps(props: ScreenProps): ScreenProps {
161+
const {
162+
// Filter out edge-to-edge related props
163+
statusBarColor,
164+
statusBarTranslucent,
165+
navigationBarColor,
166+
navigationBarTranslucent,
167+
...rest
168+
} = props;
169+
170+
if (__DEV__) {
171+
controlEdgeToEdgeValues({
172+
statusBarColor,
173+
statusBarTranslucent,
174+
navigationBarColor,
175+
navigationBarTranslucent,
176+
});
177+
}
178+
179+
return {
180+
...rest,
181+
statusBarTranslucent: true,
182+
navigationBarTranslucent: true,
183+
};
184+
}
185+
160186
function isIndexInClosedRange(
161187
value: number,
162188
lowerBound: number,
@@ -184,13 +210,6 @@ export const InnerScreen = React.forwardRef<View, ScreenProps>(
184210
enabled = screensEnabled(),
185211
freezeOnBlur = freezeEnabled(),
186212
shouldFreeze,
187-
188-
// edge-to-edge related props
189-
navigationBarColor,
190-
navigationBarTranslucent,
191-
statusBarColor,
192-
statusBarTranslucent,
193-
194213
...rest
195214
} = props;
196215

@@ -250,24 +269,6 @@ export const InnerScreen = React.forwardRef<View, ScreenProps>(
250269
...props
251270
} = rest;
252271

253-
const {
254-
// Filter out edge-to-edge related props
255-
navigationBarColor,
256-
navigationBarTranslucent,
257-
statusBarColor,
258-
statusBarTranslucent,
259-
...edgeToEdgeFriendlyProps
260-
} = props;
261-
262-
if (__DEV__) {
263-
controlEdgeToEdgeValues({
264-
navigationBarColor,
265-
navigationBarTranslucent,
266-
statusBarColor,
267-
statusBarTranslucent,
268-
});
269-
}
270-
271272
if (active !== undefined && activityState === undefined) {
272273
console.warn(
273274
'It appears that you are using old version of react-navigation library. Please update @react-navigation/bottom-tabs, @react-navigation/stack and @react-navigation/drawer to version 5.10.0 or above to take full advantage of new functionality added to react-native-screens',
@@ -310,13 +311,7 @@ export const InnerScreen = React.forwardRef<View, ScreenProps>(
310311
return (
311312
<DelayedFreeze freeze={freeze}>
312313
<AnimatedScreen
313-
{...(EDGE_TO_EDGE
314-
? {
315-
...edgeToEdgeFriendlyProps,
316-
navigationBarTranslucent: true,
317-
statusBarTranslucent: true,
318-
}
319-
: props)}
314+
{...props}
320315
/**
321316
* This messy override is to conform NativeProps used by codegen and
322317
* our Public API. To see reasoning go to this PR:
@@ -418,7 +413,12 @@ export const ScreenContext = React.createContext(InnerScreen);
418413
const Screen = React.forwardRef<View, ScreenProps>((props, ref) => {
419414
const ScreenWrapper = React.useContext(ScreenContext) || InnerScreen;
420415

421-
return <ScreenWrapper {...props} ref={ref} />;
416+
return (
417+
<ScreenWrapper
418+
{...(EDGE_TO_EDGE ? transformEdgeToEdgeProps(props) : props)}
419+
ref={ref}
420+
/>
421+
);
422422
});
423423

424424
Screen.displayName = 'Screen';

0 commit comments

Comments
 (0)