react-native-modal-selector
react-native-modal-selector copied to clipboard
ModalSelector reset when close modal
I have a component in my react native app that use a ModalSelector to choose option of type I want. If option A, it shows a button which open a modal to select a date with library react-native-calendars. When I close the modal without validate the dates I picked, the option in modal selector stay. But if I validate, ModalSelector reset and show my text 'select a type' (initValue) of my ModalSelector. It keep in memory the choice, but didn't show it in ModalSelector.
My ModalSelector at beginning :
<ModalSelector
style={{marginBottom: 15}}
optionContainerStyle={{backgroundColor: '#FFFFFF'}}
optionTextStyle={{color: '#89559e', fontWeight: 'bold'}}
selectTextStyle={{color: '#89559e', fontWeight: '500'}}
data={listAbs}
initValue={I18n.t(
'message.myapp.action.selectionnerType',
)}
cancelText={I18n.t('message.myapp.action.annuler')}
keyExtractor={(item) => item.code}
labelExtractor={(item) => item.params.libelle}
onChange={(option) => setCodeAbs(option)}
/>

If validate the date, go back to this point and didn't keep the option. The result I want :
What I have :

=> I have the problem because the component was too long, so I dispatch it in different components, the component calendar picker was in another component, and the modal in the parent component. If I put my calendar picker component into the parent component, I dont have the problem I describe here. But its a problem I dont have with the children component selectFile, and same problem with children component select hours which use react-native-calendars too.
The filepicker close itself, we can see the same problem with a react native Alert. When we close it, modal selector reset. Seems it reset when we close modals, but not all modals, i dont understand.