Fix new keyboard API

This commit is contained in:
Zhiyuan Zheng 2021-10-10 21:58:36 +02:00
parent 83433dd434
commit 567a09d6c6
1 changed files with 8 additions and 10 deletions

View File

@ -55,20 +55,18 @@ const ScreenCompose: React.FC<RootStackScreenProps<'Screen-Compose'>> = ({
const [hasKeyboard, setHasKeyboard] = useState(false) const [hasKeyboard, setHasKeyboard] = useState(false)
useEffect(() => { useEffect(() => {
Keyboard.addListener('keyboardWillShow', _keyboardDidShow) const keyboardShown = Keyboard.addListener('keyboardWillShow', () =>
Keyboard.addListener('keyboardWillHide', _keyboardDidHide) setHasKeyboard(true)
)
const keyboardHidden = Keyboard.addListener('keyboardWillHide', () =>
setHasKeyboard(false)
)
return () => { return () => {
Keyboard.removeListener('keyboardWillShow', _keyboardDidShow) keyboardShown.remove()
Keyboard.removeListener('keyboardWillHide', _keyboardDidHide) keyboardHidden.remove()
} }
}, []) }, [])
const _keyboardDidShow = () => {
setHasKeyboard(true)
}
const _keyboardDidHide = () => {
setHasKeyboard(false)
}
const localAccount = useSelector(getInstanceAccount, (prev, next) => const localAccount = useSelector(getInstanceAccount, (prev, next) =>
prev?.preferences && next?.preferences prev?.preferences && next?.preferences