1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-16 00:14:34 +02:00

iOS: Fixes #11711: Fix Markdown toolbar partially covered by keyboard on some iOS devices (#12027)

This commit is contained in:
Henry Heino
2025-03-29 05:46:37 -07:00
committed by GitHub
parent 6bc1965ec0
commit 18ebd16428
8 changed files with 86 additions and 258 deletions

View File

@ -0,0 +1,35 @@
import { useEffect, useMemo, useState } from 'react';
import { Dimensions, Keyboard } from 'react-native';
const useKeyboardState = () => {
const [keyboardVisible, setKeyboardVisible] = useState(false);
const [hasSoftwareKeyboard, setHasSoftwareKeyboard] = useState(false);
const [isFloatingKeyboard, setIsFloatingKeyboard] = useState(false);
useEffect(() => {
const showListener = Keyboard.addListener('keyboardDidShow', () => {
setKeyboardVisible(true);
setHasSoftwareKeyboard(true);
});
const hideListener = Keyboard.addListener('keyboardDidHide', () => {
setKeyboardVisible(false);
});
const floatingListener = Keyboard.addListener('keyboardWillChangeFrame', (evt) => {
const windowWidth = Dimensions.get('window').width;
// If the keyboard isn't as wide as the window, the floating keyboard is disabled.
// See https://github.com/facebook/react-native/issues/29473#issuecomment-696658937
setIsFloatingKeyboard(evt.endCoordinates.width < windowWidth);
});
return (() => {
showListener.remove();
hideListener.remove();
floatingListener.remove();
});
});
return useMemo(() => {
return { keyboardVisible, hasSoftwareKeyboard, isFloatingKeyboard };
}, [keyboardVisible, hasSoftwareKeyboard, isFloatingKeyboard]);
};
export default useKeyboardState;