Live video on the AT Protocol
at next 41 lines 1.4 kB view raw
1import { useEffect, useState } from "react"; 2import { Keyboard } from "react-native"; 3 4export function useKeyboard() { 5 const [isKeyboardVisible, setIsKeyboardVisible] = useState(false); 6 const [keyboardHeight, setKeyboardHeight] = useState(0); 7 useEffect(() => { 8 const willShowSubscription = Keyboard.addListener( 9 "keyboardWillShow", 10 (e) => { 11 // setIsKeyboardVisible(true); 12 setKeyboardHeight(e.endCoordinates.height); 13 console.log("keyboardWillShow", e.endCoordinates.height); 14 }, 15 ); 16 const willHideSubscription = Keyboard.addListener( 17 "keyboardWillHide", 18 (e) => { 19 // setIsKeyboardVisible(false); 20 setKeyboardHeight(0); 21 console.log("keyboardWillHide", e.endCoordinates.height); 22 }, 23 ); 24 const showSubscription = Keyboard.addListener("keyboardDidShow", (e) => { 25 setIsKeyboardVisible(true); 26 setKeyboardHeight(e.endCoordinates.height); 27 console.log("keyboardDidShow", e.endCoordinates.height); 28 }); 29 const hideSubscription = Keyboard.addListener("keyboardDidHide", () => { 30 setIsKeyboardVisible(false); 31 setKeyboardHeight(0); 32 }); 33 return () => { 34 showSubscription.remove(); 35 hideSubscription.remove(); 36 willShowSubscription.remove(); 37 }; 38 }, []); 39 40 return { isKeyboardVisible, keyboardHeight }; 41}