whitespectre/rn-modal-presenter

ERROR TypeError: onDismiss is not a function.

Closed this issue · 2 comments

Hi,
Thank you for providing great package.

I've considered to use rn-modal-presenter to hold modals in queue, so that I can show modals one by one.
I tried your Example code first and got error.
Could you please help me to resolve this errror?

[Error]

 ERROR  TypeError: onDismiss is not a function. (In 'onDismiss()', 'onDismiss' is an instance of Class)

[Code]
I changed App.tsx in Example not to pass close button, so I thought that onDismiss called instead like onPress={button.action ?? dismiss} in CustomAlert.tsx.
Or should I set close button?

Here is my code.

App.tsx

import React from 'react';
import {Button, SafeAreaView, StyleSheet} from 'react-native';
import {showCustomAlert} from './src/CustomAlert';
import {ModalPresenterParent} from 'rn-modal-presenter';

const App = () => {
  const showAlertFromAlert = () => {
    const modalHandler = showCustomAlert(
      'Alert',
      'This alert was triggered from another alert',
      [
        {
          title: 'Show Another Alert',
          action: showAlertFromAlert,
        },
        {
          title: 'Close',
          action: undefined,               // set undefined to call  `onPress={button.action ?? dismiss}` in CustomAlert.tsx
        },
      ],
    );
  };

  return (
    <ModalPresenterParent>
      <SafeAreaView style={styles.container}>
        <Button title="Show Modal" onPress={showAlertFromAlert} />
      </SafeAreaView>
    </ModalPresenterParent>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
});

export default App;

Thank you.

Hi @yoshifumi4423 ! thanks for reporting this. We recently made a change to the lib's API to add support for queues and for callback blocks when a modal is dismissed, but forgot to update the example. I'll do it now and open a PR. Thanks!

@yoshifumi4423 I just fixed the example and added an example on how to enqueue modals as well (a simple one, but you can play with more complex cases as stated in the documentation).

Hope it helps, and thanks for using this lib!