From d87857e5d93c19ebee2fd84eb4910e36001ec2a3 Mon Sep 17 00:00:00 2001 From: Janic Duplessis Date: Sat, 3 Apr 2021 19:06:55 -0400 Subject: [PATCH] fix: remove calls to removed Keyboard.removeListener in useIsKeyboardShown (#9457) --- .../src/utils/useIsKeyboardShown.tsx | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/bottom-tabs/src/utils/useIsKeyboardShown.tsx b/packages/bottom-tabs/src/utils/useIsKeyboardShown.tsx index 4ab974c3..85cbd71a 100644 --- a/packages/bottom-tabs/src/utils/useIsKeyboardShown.tsx +++ b/packages/bottom-tabs/src/utils/useIsKeyboardShown.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import { Keyboard, Platform } from 'react-native'; +import { Keyboard, Platform, EmitterSubscription } from 'react-native'; export default function useIsKeyboardShown() { const [isKeyboardShown, setIsKeyboardShown] = React.useState(false); @@ -8,22 +8,22 @@ export default function useIsKeyboardShown() { const handleKeyboardShow = () => setIsKeyboardShown(true); const handleKeyboardHide = () => setIsKeyboardShown(false); + let subscriptions: EmitterSubscription[]; + if (Platform.OS === 'ios') { - Keyboard.addListener('keyboardWillShow', handleKeyboardShow); - Keyboard.addListener('keyboardWillHide', handleKeyboardHide); + subscriptions = [ + Keyboard.addListener('keyboardWillShow', handleKeyboardShow), + Keyboard.addListener('keyboardWillHide', handleKeyboardHide), + ]; } else { - Keyboard.addListener('keyboardDidShow', handleKeyboardShow); - Keyboard.addListener('keyboardDidHide', handleKeyboardHide); + subscriptions = [ + Keyboard.addListener('keyboardDidShow', handleKeyboardShow), + Keyboard.addListener('keyboardDidHide', handleKeyboardHide), + ]; } return () => { - if (Platform.OS === 'ios') { - Keyboard.removeListener('keyboardWillShow', handleKeyboardShow); - Keyboard.removeListener('keyboardWillHide', handleKeyboardHide); - } else { - Keyboard.removeListener('keyboardDidShow', handleKeyboardShow); - Keyboard.removeListener('keyboardDidHide', handleKeyboardHide); - } + subscriptions.forEach((s) => s.remove()); }; }, []);