peacechen / react-native-modal-selector

A cross-platform (iOS / Android), selector/picker component for React Native that is highly customizable and supports sections.
MIT License
369 stars 129 forks source link

Add prop for onCancel #155

Open scousino opened 4 years ago

scousino commented 4 years ago

Add a prop that accepts a callback that will execute when the user presses the cancel button.

Right now, I'm manually controlling the visibility of the ModalSelector, but I have no way to when the user has selected cancel other than onModalClose, but I can't use that because I'm manually controlling the visibility.

peacechen commented 3 years ago

The cancel button fires close() which calls this.props.onModalClose(item). That always fires when the cancel button is pressed. https://github.com/peacechen/react-native-modal-selector/blob/master/index.js#L193

If you're creating the button yourself, you have complete control over its callback. I might not be understanding your question fully. Please submit a PR if a change is required in this library.

scousino commented 3 years ago

Yes if you look at that exact method you referred to, the close() method sets the visibility of the modal explicitly. However, I'm trying to control the visibility of the Modal manually like the doc indicates. But this explicit setting of the visibility by the package while I'm trying to rightfully be in full control of visibility breaks that functionality/understanding.