From af7f15ddbc47091407d3a9a596bb2cde85874b2b Mon Sep 17 00:00:00 2001 From: GuySerfaty Date: Mon, 5 Feb 2024 19:27:19 +0200 Subject: [PATCH 1/2] fix: android focus --- src/RichText/RichText.tsx | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/RichText/RichText.tsx b/src/RichText/RichText.tsx index d56964e..cfb62a1 100644 --- a/src/RichText/RichText.tsx +++ b/src/RichText/RichText.tsx @@ -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 }; @@ -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(` 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 @@ -105,7 +110,7 @@ export const RichText = ({ editor.updateScrollThresholdAndMargin(0); } } - }, [avoidIosKeyboard, editor, iosKeyboardHeight]); + }, [avoidIosKeyboard, editor, iosKeyboardHeight, isKeyboardUp]); return ( <> From 546f41e9dc99bc64b5bcf9f509ff69846474cf7c Mon Sep 17 00:00:00 2001 From: GuySerfaty Date: Mon, 5 Feb 2024 19:28:55 +0200 Subject: [PATCH 2/2] fix: int --- src/RichText/RichText.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/RichText/RichText.tsx b/src/RichText/RichText.tsx index cfb62a1..35efda4 100644 --- a/src/RichText/RichText.tsx +++ b/src/RichText/RichText.tsx @@ -82,7 +82,8 @@ export const RichText = ({ }, 200); } else { setTimeout(() => { - editor.webviewRef.current.injectJavaScript(` + editor.webviewRef.current && + editor.webviewRef.current.injectJavaScript(` document.querySelector('.ProseMirror').style.paddingBottom = '0px'; `); editor.updateScrollThresholdAndMargin(0);