type ToastType = 'success' | 'error';
import React from 'react';
import _Toast from 'react-native-toast-message';
export default {
  show(
    text: string,
    type: ToastType = 'success',
    duration: number = 3500,
    hide: () => void | undefined = () => {},
  ) {
    // _Toast.hide();
    _Toast.show({
      text1: '提示',
      text2: text,
      type,
      visibilityTime: duration,
      onHide: hide,
    });
  },
  useBlur(
    navigation: any,
    customFunc: (() => void) | null = null,
  ) {
    React.useEffect(() => {
      const unsubscribe = navigation.addListener('blur', () => {
        // do something
        _Toast.hide();
        if (customFunc != null) {
          customFunc();
        }
      });
      return unsubscribe;
    }, [navigation]);
  },
};

export const Toast = _Toast;
