codler / react-native-keyboard-aware-scroll-view

A ScrollView component that handles keyboard appearance and automatically scrolls to focused TextInput.
https://www.npmjs.com/package/@codler/react-native-keyboard-aware-scroll-view
38 stars 16 forks source link

KeyboardAwareHOC.js Issue in responder.scrollResponderScrollTo is not a function #17

Open yarelosa opened 5 months ago

yarelosa commented 5 months ago

Hi! πŸ‘‹

Firstly, thanks for your work on this project! πŸ™‚

Today I used patch-package to patch @codler/react-native-keyboard-aware-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/@codler/react-native-keyboard-aware-scroll-view/lib/KeyboardAwareHOC.js b/node_modules/@codler/react-native-keyboard-aware-scroll-view/lib/KeyboardAwareHOC.js
index 855c968..a16719d 100644
--- a/node_modules/@codler/react-native-keyboard-aware-scroll-view/lib/KeyboardAwareHOC.js
+++ b/node_modules/@codler/react-native-keyboard-aware-scroll-view/lib/KeyboardAwareHOC.js
@@ -241,12 +241,32 @@ function KeyboardAwareHOC(

     scrollToPosition = (x: number, y: number, animated: boolean = true) => {
       const responder = this.getScrollResponder()
-      responder && responder.scrollResponderScrollTo({ x, y, animated })
-    }
+      if (!responder) {
+        return
+      }
+      if (responder.scrollResponderScrollTo) {
+        // React Native < 0.65
+        responder.scrollResponderScrollTo({ x, y, animated })
+        } else if (responder.scrollTo) {
+        // React Native >= 0.65
+        responder.scrollTo({ x, y, animated })
+        }
+        // responder && responder.scrollResponderScrollTo({ x, y, animated })
+      }

-    scrollToEnd = (animated?: boolean = true) => {
+      scrollToEnd = (animated?: boolean = true) => {
       const responder = this.getScrollResponder()
-      responder && responder.scrollResponderScrollToEnd({ animated })
+      if (!responder) {
+       return
+      }
+      if (responder.scrollResponderScrollTo) {
+        // React Native < 0.65
+        responder.scrollResponderScrollTo({ x, y, animated })
+        } else if (responder.scrollTo) {
+        // React Native >= 0.65
+        responder.scrollTo({ x, y, animated })
+      }
+      // responder && responder.scrollResponderScrollToEnd({ animated })
     }

     scrollForExtraHeightOnAndroid = (extraHeight: number) => {

This issue body was partially generated by patch-package.

AyoCodess commented 3 months ago

Hi! πŸ‘‹

Firstly, thanks for your work on this project! πŸ™‚

Today I used patch-package to patch @codler/react-native-keyboard-aware-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/@codler/react-native-keyboard-aware-scroll-view/lib/KeyboardAwareHOC.js b/node_modules/@codler/react-native-keyboard-aware-scroll-view/lib/KeyboardAwareHOC.js
index 855c968..a16719d 100644
--- a/node_modules/@codler/react-native-keyboard-aware-scroll-view/lib/KeyboardAwareHOC.js
+++ b/node_modules/@codler/react-native-keyboard-aware-scroll-view/lib/KeyboardAwareHOC.js
@@ -241,12 +241,32 @@ function KeyboardAwareHOC(

     scrollToPosition = (x: number, y: number, animated: boolean = true) => {
       const responder = this.getScrollResponder()
-      responder && responder.scrollResponderScrollTo({ x, y, animated })
-    }
+      if (!responder) {
+        return
+      }
+      if (responder.scrollResponderScrollTo) {
+        // React Native < 0.65
+        responder.scrollResponderScrollTo({ x, y, animated })
+        } else if (responder.scrollTo) {
+        // React Native >= 0.65
+        responder.scrollTo({ x, y, animated })
+        }
+        // responder && responder.scrollResponderScrollTo({ x, y, animated })
+      }

-    scrollToEnd = (animated?: boolean = true) => {
+      scrollToEnd = (animated?: boolean = true) => {
       const responder = this.getScrollResponder()
-      responder && responder.scrollResponderScrollToEnd({ animated })
+      if (!responder) {
+       return
+      }
+      if (responder.scrollResponderScrollTo) {
+        // React Native < 0.65
+        responder.scrollResponderScrollTo({ x, y, animated })
+        } else if (responder.scrollTo) {
+        // React Native >= 0.65
+        responder.scrollTo({ x, y, animated })
+      }
+      // responder && responder.scrollResponderScrollToEnd({ animated })
     }

     scrollForExtraHeightOnAndroid = (extraHeight: number) => {

This issue body was partially generated by patch-package.

can you make a fork?