首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >react-native-swiper奇怪行为

react-native-swiper奇怪行为
EN

Stack Overflow用户
提问于 2018-06-15 01:48:14
回答 2查看 3.9K关注 0票数 0

在我的应用程序中,我使用了react-native-swiper组件。最初它工作正常,但最近它有一个奇怪的行为。它有5个窗口,像这样滑动。1-2-3-4-5-1

它刷了7次,物品是这样的。从第一个开始。我可以向左划一次。向右滑动5次。这就是全部。

我该如何解决这个问题?我使用的是1.5.6版本

代码语言:javascript
复制
import React from "react";
import { Dimensions } from "react-native";
import Swiper from "react-native-swiper";
import SwiperWindow from "../SwiperWindow/SwiperWindow";

const height = Dimensions.get("window").height * 0.3;

const swiperContainer = props => (
  <Swiper height={height} 
    showsButtons={true}
    showsPagination={false}>

    {props.featuredWorkouts.map(featuredWorkout => {
      return(
      <SwiperWindow
        key={featuredWorkout.featuredWorkoutId}
        imageSource={featuredWorkout.postImage}
        workoutTitle={featuredWorkout.title}
      />)
    })}
  </Swiper>
);

export default swiperContainer;
EN

回答 2

Stack Overflow用户

发布于 2018-08-06 16:45:51

从这个线程,https://github.com/leecade/react-native-swiper/issues/569

看起来这个问题可以通过,

我观察到,如果在父组件中调用setState,则会触发swiper组件的componentWillReceiveProps,nextProps与当前swiper组件的props完全相同。而且还会调用swiper组件的setState和initState,因此swiper状态会变得混乱。

为了解决这个问题,我在componentWillReceiveProps中临时添加了if (nextProps.index === this.props.index) return;。

此解决方案由HuiSF在此线程中提供。

票数 0
EN

Stack Overflow用户

发布于 2021-03-15 12:17:27

添加key={allPins.length}。在Swiper内部,如下所示,它对我有效

代码语言:javascript
复制
<Swiperkey={allPins.length}}>
</Swiper>

这里的allPins.length只是dynamicArray.length

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50863207

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档