react-native-keyboard-avoiding-scroll-view icon indicating copy to clipboard operation
react-native-keyboard-avoiding-scroll-view copied to clipboard

Fix: Deprecated currentlyFocusedField

Open anduong96 opened this issue 1 year ago • 1 comments

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-keyboard-avoiding-scroll-view/dist/KeyboardAvoidingContainer.js b/node_modules/react-native-keyboard-avoiding-scroll-view/dist/KeyboardAvoidingContainer.js
index fadc258..6a9ead3 100644
--- a/node_modules/react-native-keyboard-avoiding-scroll-view/dist/KeyboardAvoidingContainer.js
+++ b/node_modules/react-native-keyboard-avoiding-scroll-view/dist/KeyboardAvoidingContainer.js
@@ -111,7 +111,10 @@ export function useKeyboardAvoidingContainerProps({ stickyFooter, containerStyle
             if (keyboardLayoutRef.current)
                 return;
             const { endCoordinates: newKeyboardLayout } = event;
-            const newFocusedTextInputNodeHandle = NativeTextInput.State.currentlyFocusedField();
+            const newFocusedTextInputNodeHandle = NativeTextInput.State.currentlyFocusedInput
+                ? findNodeHandle(NativeTextInput.State.currentlyFocusedInput())
+                : NativeTextInput.State.currentlyFocusedField();
+
             const newStickyFooterNodeHandle = findNodeHandle(stickyFooterRef.current);
             const [newFocusedTextInputLayout, newStickyFooterLayout,] = await Promise.all([
                 newFocusedTextInputNodeHandle
@@ -154,35 +157,7 @@ export function useKeyboardAvoidingContainerProps({ stickyFooter, containerStyle
             keyboardWillHideSub.remove();
         };
     }, [updateOffsets]);
-    useEffect(() => {
-        const textInputEvents = hijackTextInputEvents();
-        // We watch for the switch between two text inputs and update offsets
-        // accordingly.
-        // A switch between two text inputs happens when a keyboard is shown
-        // and another text input is currently being focused on.
-        const sub = textInputEvents.addListener('textInputDidFocus', newFocusedTextInputNodeHandle => {
-            requestAnimationFrame(async () => {
-                if (!keyboardLayoutRef.current ||
-                    !focusedTextInputLayoutRef.current) {
-                    return;
-                }
-                const newFocusedTextInputLayout = newFocusedTextInputNodeHandle
-                    ? await measureInWindow(newFocusedTextInputNodeHandle)
-                    : null;
-                focusedTextInputLayoutRef.current = newFocusedTextInputLayout
-                    ? {
-                        ...newFocusedTextInputLayout,
-                        screenY: newFocusedTextInputLayout.screenY +
-                            scrollViewOffsetRef.current,
-                    }
-                    : newFocusedTextInputLayout;
-                updateOffsets();
-            });
-        });
-        return () => {
-            sub.remove();
-        };
-    }, [scrollViewOffset, updateOffsets]);
+
     const scrollViewContentContainerStyle = useMemo(() => {
         const flatContentContainerStyleProp = StyleSheet.flatten(contentContainerStyleProp) || {};
         let scrollViewContentBottomInsetProp = 0;

This issue body was partially generated by patch-package.

anduong96 avatar Feb 28 '24 03:02 anduong96