npm 类型错误:响应者,scrollResponderScrollTo不是函数

ruyhziif  于 2023-01-17  发布在  其他
关注(0)|答案(2)|浏览(150)

在我的React native expo项目中,我面临着IOS模拟器和真实的IOS设备的问题。实际上我使用的是React native:“0.65.1”,我试了64. 0,和65. 2,但没有用。
错误为

TypeError: responder.scrollResponderScrollTo is not a function. (In 'responder.scrollResponderScrollTo({
        x: x,
        y: y,
        animated: animated
      })', 'responder.scrollResponderScrollTo' is undefined)

花了几个小时后,我发现这个问题将基于'react-native-keyboard-aware-scroll-view'这个npm,但我还没有在我的项目中使用它.那么我们如何解决这个问题

yfwxisqw

yfwxisqw1#

这是一个open GitHub issue for react-native-keyboard-aware-scroll-view
假设您使用的是react-native 0.65.2,那么您可以通过更新react-native-keyboard-aware-scroll-view version 0.9.5来修复此问题。

mccptt67

mccptt672#

更新 /node_modules/@codler/react-native-keyboard-aware-scroll-view/lib/KeyboardAwareHOC.js 文件第244行中的以下代码。

scrollToPosition = (x: number, y: number, animated: boolean = true) => {
  const responder = this.getScrollResponder()
  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) => {
  const responder = this.getScrollResponder()
  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 })
}

相关问题