Skip to content

Commit 025fa21

Browse files
zoontekkkafar
authored andcommitted
Extract helper for conditional application
1 parent 0df7981 commit 025fa21

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

@@ -258,24 +277,6 @@ export const InnerScreen = React.forwardRef<View, ScreenProps>(
258277
...props
259278
} = rest;
260279

261-
const {
262-
// Filter out edge-to-edge related props
263-
navigationBarColor,
264-
navigationBarTranslucent,
265-
statusBarColor,
266-
statusBarTranslucent,
267-
...edgeToEdgeFriendlyProps
268-
} = props;
269-
270-
if (__DEV__) {
271-
controlEdgeToEdgeValues({
272-
navigationBarColor,
273-
navigationBarTranslucent,
274-
statusBarColor,
275-
statusBarTranslucent,
276-
});
277-
}
278-
279280
if (active !== undefined && activityState === undefined) {
280281
console.warn(
281282
'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',
@@ -320,13 +321,7 @@ export const InnerScreen = React.forwardRef<View, ScreenProps>(
320321
return (
321322
<DelayedFreeze freeze={freeze}>
322323
<AnimatedScreen
323-
{...(EDGE_TO_EDGE
324-
? {
325-
...edgeToEdgeFriendlyProps,
326-
navigationBarTranslucent: true,
327-
statusBarTranslucent: true,
328-
}
329-
: props)}
324+
{...props}
330325
/**
331326
* This messy override is to conform NativeProps used by codegen and
332327
* our Public API. To see reasoning go to this PR:
@@ -428,7 +423,12 @@ export const ScreenContext = React.createContext(InnerScreen);
428423
const Screen = React.forwardRef<View, ScreenProps>((props, ref) => {
429424
const ScreenWrapper = React.useContext(ScreenContext) || InnerScreen;
430425

431-
return <ScreenWrapper {...props} ref={ref} />;
426+
return (
427+
<ScreenWrapper
428+
{...(EDGE_TO_EDGE ? transformEdgeToEdgeProps(props) : props)}
429+
ref={ref}
430+
/>
431+
);
432432
});
433433

434434
Screen.displayName = 'Screen';

0 commit comments

Comments
 (0)