react-native-actions-sheet
react-native-actions-sheet copied to clipboard
Custom back handler in action sheet
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.
What is your use case for a custom handler?
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.
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 there is a prop 'closeOnPressBack' which defaults to true. You can set it to false to prevent back button closing the action sheet.
I've tried closeOnPressBack={false}
and its not working
It might be possible that you may have set some other custom back handler for the same screen.
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