Skip to content

fix: Refactor Overlay to be used as containerComponent #32

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
91 changes: 45 additions & 46 deletions src/BottomSheetView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type BottomSheetModalScreenProps = BottomSheetModalProps & {
navigation: BottomSheetNavigationProp<ParamListBase>;
};

function Overlay({ children }: { children: React.ReactNode }) {
function Overlay({ children }: { children?: React.ReactNode }) {
if (Platform.OS === 'ios') {
return (
<FullWindowOverlay>
Expand Down Expand Up @@ -132,51 +132,50 @@ export function BottomSheetView({ state, descriptors }: Props) {
return (
<>
{firstScreen.render()}
<Overlay>
{shouldRenderProvider.current && (
<BottomSheetModalProvider>
{state.routes.slice(1).map((route) => {
const { options, navigation, render } = descriptors[route.key];

const {
index,
backgroundStyle,
handleIndicatorStyle,
snapPoints,
enableDynamicSizing,
...sheetProps
} = options;

return (
<BottomSheetModalScreen
key={route.key}
// Make sure index is in range, it could be out if snapToIndex is persisted
// and snapPoints is changed.
index={Math.min(
route.snapToIndex ?? index ?? 0,
snapPoints != null ? snapPoints.length - 1 : 0,
)}
snapPoints={
snapPoints == null && !enableDynamicSizing
? DEFAULT_SNAP_POINTS
: snapPoints
}
enableDynamicSizing={enableDynamicSizing}
navigation={navigation}
backgroundStyle={[themeBackgroundStyle, backgroundStyle]}
handleIndicatorStyle={[
themeHandleIndicatorStyle,
handleIndicatorStyle,
]}
{...sheetProps}
>
{render()}
</BottomSheetModalScreen>
);
})}
</BottomSheetModalProvider>
)}
</Overlay>
{shouldRenderProvider.current && (
<BottomSheetModalProvider>
{state.routes.slice(1).map((route) => {
const { options, navigation, render } = descriptors[route.key];

const {
index,
backgroundStyle,
handleIndicatorStyle,
snapPoints,
enableDynamicSizing,
...sheetProps
} = options;

return (
<BottomSheetModalScreen
key={route.key}
// Make sure index is in range, it could be out if snapToIndex is persisted
// and snapPoints is changed.
index={Math.min(
route.snapToIndex ?? index ?? 0,
snapPoints != null ? snapPoints.length - 1 : 0,
)}
snapPoints={
snapPoints == null && !enableDynamicSizing
? DEFAULT_SNAP_POINTS
: snapPoints
}
enableDynamicSizing={enableDynamicSizing}
navigation={navigation}
backgroundStyle={[themeBackgroundStyle, backgroundStyle]}
handleIndicatorStyle={[
themeHandleIndicatorStyle,
handleIndicatorStyle,
]}
containerComponent={Overlay}
{...sheetProps}
>
{render()}
</BottomSheetModalScreen>
);
})}
</BottomSheetModalProvider>
)}
</>
);
}
Expand Down