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

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

Open yarelosa opened this issue 1 year ago • 1 comments

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch @codler/[email protected] 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.

yarelosa avatar Jun 26 '24 00:06 yarelosa