react-native#EmitterSubscription TypeScript Examples

The following examples show how to use react-native#EmitterSubscription. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: sheetmanager.tsx    From react-native-actions-sheet with MIT License 6 votes vote down vote up
/**
   * An async hide function. This is useful when you want to show one ActionSheet after closing another.
   *
   * @param id id of the ActionSheet to show
   * @param data An data to pass to the ActionSheet. Will be available from `onClose` prop.
   */
  static async hide(id: string, data?: unknown): Promise<boolean> {
    return new Promise((resolve) => {
      let sub: EmitterSubscription;
      const fn = () => {
        resolve(true);
        sub?.remove();
      };
      sub = DeviceEventEmitter.addListener(`onclose_${id}`, fn);
      DeviceEventEmitter.emit(`hide_${id}`, data);
    });
  }
Example #2
Source File: index.tsx    From react-native-bottomsheet-reanimated with MIT License 6 votes vote down vote up
useKeyboard = (isEnable = true): [number] => {
  const showSubscription = useRef<EmitterSubscription>();
  const hideSubscription = useRef<EmitterSubscription>();
  const [keyboardHeight, setKeyboardHeight] = useState(0);

  function onKeyboardWillShow(e: KeyboardEvent): void {
    setKeyboardHeight(e.endCoordinates.height);
  }

  function onKeyboardWillHide(): void {
    setKeyboardHeight(0);
  }

  useEffect(() => {
    if (isEnable) {
      const keyboardShowEvent =
        Platform.OS === 'android' ? 'keyboardDidShow' : 'keyboardWillShow';
      const keyboardHideEvent =
        Platform.OS === 'android' ? 'keyboardDidHide' : 'keyboardWillHide';
      showSubscription.current = Keyboard.addListener(
        keyboardShowEvent,
        onKeyboardWillShow
      );
      hideSubscription.current = Keyboard.addListener(
        keyboardHideEvent,
        onKeyboardWillHide
      );
    }
    return (): void => {
      showSubscription.current?.remove();
      hideSubscription.current?.remove();
    };
  }, [isEnable]);

  return [keyboardHeight];
}
Example #3
Source File: GoPremium.tsx    From SQL-Play with GNU Affero General Public License v3.0 5 votes vote down vote up
purchaseUpdate: EmitterSubscription
Example #4
Source File: GoPremium.tsx    From SQL-Play with GNU Affero General Public License v3.0 5 votes vote down vote up
purchaseError: EmitterSubscription
Example #5
Source File: index.d.ts    From react-native-actions-sheet with MIT License 5 votes vote down vote up
sheetManagerHideEvent: EmitterSubscription | null;
Example #6
Source File: index.d.ts    From react-native-actions-sheet with MIT License 5 votes vote down vote up
sheetManagerShowEvent: EmitterSubscription | null;
Example #7
Source File: index.d.ts    From react-native-actions-sheet with MIT License 5 votes vote down vote up
keyboardShowSubscription: EmitterSubscription | null;
Example #8
Source File: index.d.ts    From react-native-actions-sheet with MIT License 5 votes vote down vote up
KeyboardHideSubscription: EmitterSubscription | null;
Example #9
Source File: index.tsx    From react-native-actions-sheet with MIT License 5 votes vote down vote up
sheetManagerHideEvent: EmitterSubscription | null = null;
Example #10
Source File: index.tsx    From react-native-actions-sheet with MIT License 5 votes vote down vote up
sheetManagerShowEvent: EmitterSubscription | null = null;
Example #11
Source File: index.tsx    From react-native-actions-sheet with MIT License 5 votes vote down vote up
keyboardShowSubscription: EmitterSubscription | null = null;
Example #12
Source File: index.tsx    From react-native-actions-sheet with MIT License 5 votes vote down vote up
KeyboardHideSubscription: EmitterSubscription | null = null;
Example #13
Source File: Main.tsx    From DoobooIAP with MIT License 5 votes vote down vote up
purchaseUpdateSubscription: EmitterSubscription
Example #14
Source File: Main.tsx    From DoobooIAP with MIT License 5 votes vote down vote up
purchaseErrorSubscription: EmitterSubscription
Example #15
Source File: index.tsx    From react-native-network-client with Apache License 2.0 5 votes vote down vote up
onClientErrorSubscription?: EmitterSubscription;