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

[Bug]: Can't able to use Gorhom bottom sheet in child components #2045

Open
devchandhana12 opened this issue Nov 18, 2024 · 7 comments
Open
Labels
bug Something isn't working

Comments

@devchandhana12
Copy link

Version

v5

Reanimated Version

v3

Gesture Handler Version

v2

Platforms

iOS, Android

What happened?

Hi, does anyone have any solution to this which I'm currently facing. I've a need to use gorhom bottom sheet inside a child component, when the bottom sheet is supposed to open at the bottom of the screen, currently it's opening at the place where the component starts in a screen. Will be attaching the screen shot for reference.
Screenshot from 2024-11-18 17-32-13

Reproduction steps

I've tried replicating the issue below please click on tap me to find the issue

Reproduction sample

https://snack.expo.dev/2sTFgkI93fIJEas1Qp2tB

Relevant log output

No response

@devchandhana12 devchandhana12 added the bug Something isn't working label Nov 18, 2024
@devchandhana12
Copy link
Author

@gorhom can you please help me resolve this issue

@fobos531
Copy link
Contributor

@devchandhana12 You need to use the BottomSheetModal in this case, not BottomSheet.

@devchandhana12
Copy link
Author

I've solved the issue by wrapping it inside portals,
Install @gorham/portal library and wrap your app in side it and then wrap your bottom sheet code inside it so that it will over write it's parents style and will be visible on top and at bottom.

@devchandhana12
Copy link
Author

I've resolved the issue by adding portals, I've used gorhom portal library, wrapped my app inside it and then wrapped my bottom sheet code inside it. Now, it's over written it's parents styles and it displayed on top of everything. Thanks !!

@zhrgns
Copy link

zhrgns commented Nov 20, 2024

Here is the solution; Use BottomSheetModal in CustomSheetComponent.
Then, wrap your screen component with BottomSheetModalProvider where you need to render CustomSheetComponent.
<BottomSheetModal ref={ref} onChange={onChange} enablePanDownToClose={true} backdropComponent={renderBackdrop} handleIndicatorStyle={styles.draggableIcon}> <BottomSheetView> <View> </View> </BottomSheetView> </BottomSheetModal>

@gencw
Copy link

gencw commented Dec 7, 2024

@devchandhana12 hello Can you tell me how you solved it? Reproduction sample

@devchandhana12
Copy link
Author

devchandhana12 commented Dec 9, 2024

@gencw

So, I've tried solving it with by wrapping it up in portal's but it reduced the performance of app greatly, so I've used BottomSheetModal

import React, {forwardRef, useMemo} from 'react';
import {
BottomSheetBackdrop,
BottomSheetModal,
BottomSheetView,
} from '@gorhom/bottom-sheet';

export type Ref = BottomSheetModal;

interface Props {
children: React.ReactNode;
height?: string;
}

const CustomBottomSheet = forwardRef<Ref, Props>(({children, height}, ref) => {
// Memoized default snap points for optimization
const defaultSnapPoints = useMemo(() => ['100%'], []);

return (
<BottomSheetModal
ref={ref}
keyboardBehavior="extend"
enableContentPanningGesture={false}
snapPoints={defaultSnapPoints}
backdropComponent={props => (
<BottomSheetBackdrop
{...props}
disappearsOnIndex={-1}
appearsOnIndex={0}
/>
)}
style={{flex: 1}}
detached
animateOnMount={true}
enableDynamicSizing={true}
enablePanDownToClose={true}>
<BottomSheetView style={[styles.container, {bottom: 20}]}>
{children}


);
});

export default React.memo(CustomBottomSheet);

this is the component which I've created

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants