Open gamingumar opened 5 years ago
Can I close action sheet when user taps outside of it? do you get any solution for this?
If you put cancelButtonIndex={??}
option will enable close on press on backdrop.
check destructiveButtonIndex in your source. you can skip it and it'll work
@naytun was entirely right with his first version of the comment, not sure why you changed it.
This should do the job(at least worked for me): cancelButtonIndex={-1}
Update: I understand why, it will replace the last button in the list with a destructive button.
Okay, I finally found a way to fix it. For that, you will need to patch the file in node modules and save it. here are the steps:
"scripts": { "postinstall": "patch-package" }
to your package.json
b) run npm i patch-package
Your_Project\node_modules\react-native-actionsheet\lib\ActionSheetCustom.js
_cancel = () => { this.hide(); //add this line! const { cancelButtonIndex } = this.props // 保持和 ActionSheetIOS 一致, // 未设置 cancelButtonIndex 时,点击背景不隐藏 ActionSheet if (utils.isset(cancelButtonIndex)) { this.hide(cancelButtonIndex) } }
npx patch-package react-native-actionsheet
. This will create a new folder in your project that will consist "your patch" for this component.remove destructiveButtonIndex
and use cancelButtonIndex
will gives dismiss-able backdrop.
I have created PR https://github.com/facebook/react-native/pull/31972 after approving this PR you can change the color of cancel button by cancelButtonTintColor
Can I close action sheet when user taps outside of it?