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

ModalSelector reset when close modal #179

Open EloiseIncrociati opened 1 year ago

EloiseIncrociati commented 1 year ago

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)}
                />

Capture d’écran 2022-09-22 à 10 45 54

If validate the date, go back to this point and didn't keep the option. The result I want : Capture d’écran 2022-09-22 à 10 50 23 What I have : Capture d’écran 2022-09-22 à 10 56 31

=> 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.