Hello,
I’m trying to use react-native-modal-selector (Modal Selector) but the modal don’t want to close on android when i try to update the state of my parent component.
Here is my code :
Children component :
<ModalSelector
data={data}
initValue="Référence dalle"
cancelText={"Annuler"}
animationType="none"
onChange={item => {
this.setState({ selected_item: item.key });
this.props.setState("test", "test");
}}
/>
Parent component :
_setState(name, value) {
console.log(name + " " + value);
this.setState({ [name]: value });
}
<InputSlabReference
slab_ref={this.state.slab_ref}
setState={this._setState}
/>
But if i do the following, it’s working :
<ModalSelector
data={data}
initValue="Référence dalle"
cancelText={"Annuler"}
animationType="none"
onChange={item => {
this.setState({ selected_item: item.key });
}}
/>
In the source code of Modal Selector, i found this :
onChange = (item) => {
if (Platform.OS === 'android' || !Modal.propTypes.onDismiss) {
// RN >= 0.50 on iOS comes with the onDismiss prop for Modal which solves RN issue #10471
this.props.onChange(item);
}
this.setState({ selected: this.props.labelExtractor(item), changedItem: item });
this.close();
}
Can somebody explain to me what I’m doing wrong?
Thanks