Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can prevent close prompt #60

Open
ahoirg opened this issue Aug 2, 2021 · 0 comments
Open

How can prevent close prompt #60

ahoirg opened this issue Aug 2, 2021 · 0 comments

Comments

@ahoirg
Copy link

ahoirg commented Aug 2, 2021

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.

@ahoirg ahoirg changed the title How can prevent close prompt on React Native How can prevent close prompt Aug 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant