react-native-bottom-sheet icon indicating copy to clipboard operation
react-native-bottom-sheet copied to clipboard

Backdrop custom onPress event?

Open avanavana opened this issue 3 years ago • 0 comments

Feature Request

Hi,

This is an awesome library. Only thing is—the press events are all enumerated and I can't pass a custom onPress handler to the BottomSheetBackdrop component.

I need to do this because I am opening and closing the BottomSheet with another UI pressable (in the header to be exact), and I need to clear the state that says the bottom sheet is open in order to change that header button's icon back from 'closed' form to 'open'.

I tried passing the exact custom backdrop provided in the docs and wrapping in in a RN Pressable component and then passing a custom onPress handler to it, but I just get weird, incomprehensible errors:

Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it' s defined in, or you might have mixed up default and named imports., before I passed an animatedIndex prop equal to 1 (max index) to the backdrop in the render method, and then

TypeError: undefined is not an object (evaluating 'x.__nodeId') afterwards.

Any help would be greatly appreciated. I basically just need to call a the set() method of a useState state instance along with the BottomSheet's close method.

I'm also curious—why did you make these Backdrop press behaviors enumberable instead of letting devs just pass their own handlers?

Thanks.

Why it is needed

Devs need to be able to do other things along with the expand, collapse, and close pressBehaviors.

Possible implementation

Just allow custom handlers to be passed as well as the enumberable values. Or add a "custom" enumerable value, and yet another prop called customPressBehavior.

Code sample

This requires only basic react, just add a "custom" enumerable value to the pressBehaviors list, and then add a new prop for customPressBehavior which accepts a handler function. Then if that custom behavior is present as a prop, apply it to the onPress event of the native lib Backdrop component.

avanavana avatar Sep 04 '22 21:09 avanavana