Skip to content

Fix: Deprecated currentlyFocusedField #40

@anduong96

Description

@anduong96

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch react-native-keyboard-avoiding-scroll-view@1.0.1 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions