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

Alert used inside of react-native-modal-selector is being hidden while Modal Closes #165

Open Muirik opened 3 years ago

Muirik commented 3 years ago

After updating my react-native expo app to SDK 42 I am noticing that the alert used inside of react-native-modal-selector is being hidden immediately, before the user has time to act. This only occurs in iOS - not on Android. I am using version 2.0.7 of react-native-modal-selector.

Specifically, I need the alert to remain open until the user has pushed one of the two buttons to make a selection. Right now if I navigate to a different tab I see that the alert is still open and visible, but within the tab where I first open the alert it disappears before the user has a chance to make a selection.

    <ModalSelector
      data={showSessionTypes(props.types)}
      onChange={async (option) => {
        if(
          RESTRICTED_SESSION_TYPES.includes(option.customKey) &&
          props.restrictedSessions.length > 0
        ) {
          Alert.alert(
            'Session already conducted',
            'Please ensure you are accessing the correct client.',
            [
              {
                text: 'OK',
                onPress: () => {},
                style: 'cancel',
              },
            ],
            {cancelable: false},
          );
          return;
        }
    />

NOTE: If I wrap the alert in a setTimeout the alert remains open/visible:

     setTimeout(() => {
        Alert.alert(
         'Session already conducted',
         'Please ensure you are accessing the correct client.',
          [
            {
              text: 'Cancel',
              onPress: () => {},
              style: 'cancel',
            },
            {
              text: 'Create Session',
              onPress: async () => {
                await createSession(option.customKey, props);
              },
            },
          ],
          {cancelable: false},
        );
      }, 510);

If this bug is unresolvable, is there an event I can wait for before loading the alert?