首页 > 解决方案 > 您在 a 上指定了 `onScroll`但不是`scrollEventThrottle`

问题描述

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

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

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

您指定onScroll了 a 但不是scrollEventThrottle。您只会收到一个事件。使用16您获取所有事件,但请注意它可能会导致丢帧,如果您不需要那么高的精度,请使用更大的数字。

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

我的轮播组件代码是:

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;
}

标签: reactjsreact-nativescrollviewreact-native-scrollview

解决方案


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

使固定:

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


推荐阅读