react native에서 키보드 감지를 하려면
Keyboard 태그에 addEventListener()를 주면 된다
import React from 'react';
import { Keyboard } from 'react-native';
export const IsKeyboard = () => {
const [isKeyboard, setIsKeyboard] = React.useState<boolean>(false);
React.useLayoutEffect(() => {
const didShow = Keyboard.addListener('keyboardWillShow', () =>
setIsKeyboard(true),
);
const didHide = Keyboard.addListener('keyboardWillHide', () =>
setIsKeyboard(false),
);
return () => {
didShow.remove();
didHide.remove();
};
}, []);
return isKeyboard;
};