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

Custom back handler in action sheet

Open aayush301 opened this issue 2 years ago • 7 comments

How can I add custom back button handler for 'hardwareBackPress' event in the action sheet?

The ActionSheet component seems not to provide such a prop for adding the custom back button handler. Although, it has a prop 'closeOnPressBack' for just specifying whether we want to close the sheet on pressing back button. So that's of no use.

aayush301 avatar Oct 06 '22 11:10 aayush301

What is your use case for a custom handler?

ammarahm-ed avatar Oct 09 '22 13:10 ammarahm-ed

Suppose, the action sheet contains some text inputs and when the back button is pressed, before the action sheet is closed, the data validation first takes place. Only after data validation, the action sheet can be closed, otherwise it can show, for example, some kind of alert.

aayush301 avatar Oct 09 '22 14:10 aayush301

In our app we are using @react-navigation/native, please can you tell me if its possible to prevent the Android hardware back button closing the action sheet?

NeilM-BG avatar Feb 15 '23 09:02 NeilM-BG

@NeilM-BG there is a prop 'closeOnPressBack' which defaults to true. You can set it to false to prevent back button closing the action sheet.

aayush301 avatar Feb 15 '23 09:02 aayush301

I've tried closeOnPressBack={false} and its not working

NeilM-BG avatar Feb 15 '23 09:02 NeilM-BG

It might be possible that you may have set some other custom back handler for the same screen.

aayush301 avatar Feb 15 '23 09:02 aayush301

closeOnPressBack={false} works well for us. But it would still be nice to be able to run some method when user clicks back button. same as what we have for backdrop closeOnPressBack to enable/disable closing sheet on backdrop press onTouchPressBack method that gets called when user clicks on backdrop closeOnPressBack to enable/disable closing sheet on back press we're missing now the method that's called on back press

ziga-hvalec avatar Jul 15 '24 07:07 ziga-hvalec