BottomSheetBackdrop: customize behavior on press
See original GitHub issueFeature Request
Provide a new prop for BottomSheetBackdrop
component, pressBehavior
, which can have the following values:
Press Behavior | Description |
---|---|
'none' |
Pressing the backdrop does nothing. Equivalent to closeOnPress=false . |
'close' |
Pressing the backdrop closes the sheet. Equivalent to closeOnPress=true . |
'collapse' |
Pressing the backdrop collapses the sheet (snap to disappearsOnIndex index). |
number | Pressing the backdrop snaps to the provided index. |
Why it is needed
Currently, the only customization is via closeOnPress
, which causes the sheet to be completely closed when the user presses the backdrop. I believe it is a very frequent scenario when the library consumer wants the sheet to be collapsed instead.
Possible implementation
const BottomSheetBackdropComponent = ({
disappearsOnIndex = DEFAULT_DISAPPEARS_ON_INDEX,
pressBehavior = DEFAULT_PRESS_BEHAVIOR
}) => {
const { collapse, snapTo, close } = useBottomSheet();
//...
const handleOnPress = useCallback(() => {
if (pressBehavior === 'close') {
close()
} else if (pressBehavior === 'collapse') {
snapTo(disappearsOnIndex)
} else if (typeof pressBehavior === 'number') {
snapTo(pressBehavior)
}
}, [close, snapTo, disappearsOnIndex]);
// ...
}
Code sample
const Backdrop = (props: BottomSheetBackdropProps) => <BottomSheetBackdrop pressBehavior="collapse" {...props} />
Remarks
I wonder ifI do favor the proposed implementation, since the consumer can still use a numbered index ('collapse'
should snaps to zero instead… not sure what’s the best.0
) for the desired behavior.closeOnPress
would be deprecated by this new prop. While these props coexist, I believe it would be sensible thatpressBehavior
takes precedence overcloseOnPress
when both are defined. We could also print a warning.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:8
- Comments:5 (5 by maintainers)
Top Results From Across the Web
How do you use this with the backdrop component? · Issue #187
you could look at the default BottomSheetBackdrop props , you can customise it base on your ... Close sheet when user press on...
Read more >Custom Backdrop | React Native Bottom Sheet - GitHub Pages
Custom Backdrop. To add a backdrop to your sheet you will need to pass the prop backdropComponent to the BottomSheet component.
Read more >Bottom sheet is not getting closed in react native android
I am using @gorhom/bottom-sheet library to create my bottomsheet which have some weird behaviour in android devices.
Read more >gorhom/bottom-sheet - npm
A performant interactive bottom sheet with fully configurable options . Latest version: 4.4.5, last published: 3 months ago.
Read more >A React Native Bottom Sheet with Fully Configurable Options
Extracting scrollable content to allow developers customize the sheet content, like integrate React Navigation as the sheet content.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@gorhom I’m plannig to take a shot very soon! I’ll post one PR on master, and one on v3 branch.
thanks @jsamr for the amazing work you’ve done!
this feature is now available for
v3
&v2
🎉