Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: detect edge-to-edge and bypass some props #2464

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"homepage": "https://github.com/software-mansion/react-native-screens#readme",
"dependencies": {
"react-freeze": "^1.0.0",
"react-native-is-edge-to-edge": "^1.1.6",
"warn-once": "^0.1.0"
},
"peerDependencies": {
Expand Down
39 changes: 38 additions & 1 deletion src/components/Screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import React from 'react';
import { Animated, View, Platform } from 'react-native';
import {
controlEdgeToEdgeValues,
isEdgeToEdge,
} from 'react-native-is-edge-to-edge';

import TransitionProgressContext from '../TransitionProgressContext';
import DelayedFreeze from './helpers/DelayedFreeze';
Expand Down Expand Up @@ -49,6 +53,8 @@ interface ViewConfig extends View {
};
}

const EDGE_TO_EDGE = isEdgeToEdge();

// This value must be kept in sync with native side.
const SHEET_FIT_TO_CONTENTS = [-1];
const SHEET_COMPAT_LARGE = [1.0];
Expand Down Expand Up @@ -151,6 +157,32 @@ function resolveSheetInitialDetentIndex(
return index;
}

function transformEdgeToEdgeProps(props: ScreenProps): ScreenProps {
const {
// Filter out edge-to-edge related props
statusBarColor,
statusBarTranslucent,
navigationBarColor,
navigationBarTranslucent,
...rest
} = props;

if (__DEV__) {
controlEdgeToEdgeValues({
statusBarColor,
statusBarTranslucent,
navigationBarColor,
navigationBarTranslucent,
});
}

return {
...rest,
statusBarTranslucent: true,
navigationBarTranslucent: true,
};
}

function isIndexInClosedRange(
value: number,
lowerBound: number,
Expand Down Expand Up @@ -381,7 +413,12 @@ export const ScreenContext = React.createContext(InnerScreen);
const Screen = React.forwardRef<View, ScreenProps>((props, ref) => {
const ScreenWrapper = React.useContext(ScreenContext) || InnerScreen;

return <ScreenWrapper {...props} ref={ref} />;
return (
<ScreenWrapper
{...(EDGE_TO_EDGE ? transformEdgeToEdgeProps(props) : props)}
ref={ref}
/>
);
});

Screen.displayName = 'Screen';
Expand Down
Loading