您在 <ScrollView> 上指定了 `onScroll` 而不是 `scrollEventThrottle`

You specified `onScroll` on a <ScrollView> but not `scrollEventThrottle`

我在我的代码中使用 react-native 的 Scrollview。

<ScrollView style={styles.productlist} >
         <CarouselComponent images={images}/>
</ScrollView>

它在应用程序上运行良好,没有错误也没有警告,但在控制台中我反复收到以下消息:

You specified onScroll on a but not scrollEventThrottle. You will only receive one event. Using 16 you get all the events but be aware that it may cause frame drops, use a bigger number if you don't need as much precision.

不知道少了什么,我没有传递 onScroll 道具但仍然收到此消息。 任何建议...

我的 Carousel 组件代码是:

const renderImages = (image, index) => {
  return (
    <Image
      key={index}
      style={styles.carouselImage} 
      source={{ uri: image.large }} 
    />
  );
}
const CarouselComponent = (props) => {
  const { images: { alternate = [] } = {} } = props;
  if (alternate.length > 0) {
    return (
      <Carousel
        delay={3000}
        autoplay
        style={styles.carouselLayout}
        bullets
        chosenBulletStyle={globalStyle.proDetCarSelectBullet}
        bulletStyle={globalStyle.productDetailBullet}
        bulletsContainerStyle={globalStyle.proDetCarBullet}              
        isLooped
        currentPage={0}
      >
        {alternate.map((image, index) => renderImages(image, index))}          
      </Carousel>
    );
  }

  return null;
}

您可能使用的是 react-native-looped-carousel 的旧版本。在 github 上有一个 issue,它在 27 天前已修复,描述了您的问题。

修复:

更新到最新版本的 react-native-looped-carousel 应该可以解决您的问题。作为替代方案,您可以通过手动添加 scrollEventThrottle 来修复错误。参见 here

您的代码没有任何问题,问题已包含在 react-native-looped-carousel 中,作为此处的问题说明:https://github.com/phil-r/react-native-looped-carousel/issues/269

我建议你搜索另一个图书馆。 React-native 的代码一直在以非常快的方式增长,每个库都应该经常更新。

为了学习新知识,scrollEventThrottle 属性定义了滚动时 onScroll 事件将被触发的次数。数字越大,触发事件的次数就越少。 16 是最精确的值。