shimohq / react-native-prompt-android

A polyfill library for Alert.prompt on Android platform, working both on Android and iOS platform.
MIT License
130 stars 75 forks source link

How can prevent close prompt #60

Open ahoirg opened 3 years ago

ahoirg commented 3 years ago

In short, what I want to do is: I open a pop-up. There are 3 options. add to cart, auto add serial number and cancel. If the input is empty, I want the add to cart button to return an error and the screen not to turn off.

import prompt from 'react-native-prompt-android';

export async function getSerialNumber() {
  return new Promise((resolve, reject) => {
    prompt(
      i18n.translate('MISSING_PRODUCT_SERIAL'),
      i18n.translate('MISSING_PRODUCT_SERIAL_CONTEXT'),
      [
        {
          text: i18n.translate('CANCEL'),
          style: 'cancel',
          onPress: () => {
            reject();
          },
        },
        (() => {
          if (
            configuration.IsRfidApplicable &&
            configuration.AnonymousRfidSerialNumber != undefined
          )
            return {
              text: i18n.translate('ANONYMOUS_SERIAL_NUMBER'),
              onPress: () => {
                resolve(configuration.AnonymousRfidSerialNumber);
              },
            };
          else return {};
        })(),
        {
          text: i18n.translate('ADD_TO_CART'),
          onPress: (serialNumber) => {
            if (serialNumber) {
              resolve(serialNumber);
            } else {  // ------> HERE, My Problem
              notifyMessage(i18n.translate('PLEASE_FILL_PRODUCT_SERIAL'));

            }
          },
        },
      ],
      {
        type: 'numeric',
        cancelable: false,
        placeholder: i18n.translate('PRODUCT_SERIAL_NUMBER'),
      },
    );
  });
}

If the serial number is not entered in the input, I just want to show notification when the add to cart button is pressed. It's okay to show notification. But the pop-up screen closes. The window closes because onPress returns a void type.