Skip to content

Commit

Permalink
fix: android focus
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySerfaty committed Feb 5, 2024
1 parent 7019aa7 commit af7f15d
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/RichText/RichText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const RichText = ({
avoidIosKeyboard,
autofocus,
}: RichTextProps) => {
const { keyboardHeight: iosKeyboardHeight } = useKeyboard();
const { keyboardHeight: iosKeyboardHeight, isKeyboardUp } = useKeyboard();
const source: WebViewProps['source'] = DEV
? { uri: DEV_SERVER_URL }
: { html: customSource || editorHTML };
Expand All @@ -72,16 +72,21 @@ export const RichText = ({

useEffect(() => {
if (editor.webviewRef.current && Platform.OS === 'android') {
if (iosKeyboardHeight) {
editor.webviewRef.current.injectJavaScript(`
document.querySelector('.ProseMirror').style.paddingBottom = '${TOOLBAR_HEIGHT}px';
`);
editor.updateScrollThresholdAndMargin(TOOLBAR_HEIGHT);
if (iosKeyboardHeight && isKeyboardUp) {
setTimeout(() => {
editor.webviewRef.current &&
editor.webviewRef.current.injectJavaScript(`
document.querySelector('.ProseMirror').style.paddingBottom = '${TOOLBAR_HEIGHT}px';
`);
editor.updateScrollThresholdAndMargin(TOOLBAR_HEIGHT);
}, 200);
} else {
editor.webviewRef.current.injectJavaScript(`
setTimeout(() => {
editor.webviewRef.current.injectJavaScript(`

Check failure on line 85 in src/RichText/RichText.tsx

View workflow job for this annotation

GitHub Actions / lint

'editor.webviewRef.current' is possibly 'null'.
document.querySelector('.ProseMirror').style.paddingBottom = '0px';
`);
editor.updateScrollThresholdAndMargin(0);
editor.updateScrollThresholdAndMargin(0);
}, 200);
}
}
// On iOS we want to control the scroll and not use the scrollview that comes with react-native-webview
Expand All @@ -105,7 +110,7 @@ export const RichText = ({
editor.updateScrollThresholdAndMargin(0);
}
}
}, [avoidIosKeyboard, editor, iosKeyboardHeight]);
}, [avoidIosKeyboard, editor, iosKeyboardHeight, isKeyboardUp]);

return (
<>
Expand Down

0 comments on commit af7f15d

Please sign in to comment.