question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BottomSheetBackdrop: customize behavior on press

See original GitHub issue

Feature 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

  1. I wonder if 'collapse' should snaps to zero instead… not sure what’s the best. I do favor the proposed implementation, since the consumer can still use a numbered index (0) for the desired behavior.
  2. closeOnPress would be deprecated by this new prop. While these props coexist, I believe it would be sensible that pressBehavior takes precedence over closeOnPress when both are defined. We could also print a warning.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:8
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
jsamrcommented, Mar 21, 2021

@gorhom I’m plannig to take a shot very soon! I’ll post one PR on master, and one on v3 branch.

1reaction
gorhomcommented, Mar 27, 2021

thanks @jsamr for the amazing work you’ve done!

this feature is now available for v3 & v2 🎉

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found