react-native-image-viewer icon indicating copy to clipboard operation
react-native-image-viewer copied to clipboard

No Animation When Index Is Controlled By Parent

Open helsonxiao opened this issue 4 years ago • 5 comments

Animation works

<Modal visible={true} transparent={true}>
  <ImageViewer imageUrls={images} />
</Modal>

Animation doesn't work

<Modal visible={true} transparent={true}>
  <ImageViewer imageUrls={images} index={index} onChange={onChange} />
</Modal>

Workaround

  public componentDidUpdate(prevProps: Props, prevState: State) {
    if (prevProps.index !== this.props.index) {
      this.loadImage(this.props.index || 0);

      this.jumpToCurrentImage({ animated: true });
    }
  }

  public jumpToCurrentImage(params?: IJumpParams) {
    const _params = {
      animated: false,
      ...params,
    };

    this.positionXNumber =
      this.width *
      (this.state.currentShowIndex || 0) *
      (I18nManager.isRTL ? 1 : -1);
    this.standardPositionX = this.positionXNumber;
    if (!_params.animated) {
      this.positionX.setValue(this.positionXNumber);
      return;
    }
    Animated.timing(this.positionX, {
      toValue: this.positionXNumber,
      easing: Easing.linear,
      duration: this.props.pageAnimateTime,
      useNativeDriver: !!this.props.useNativeDriver,
    }).start();
  }

helsonxiao avatar May 28 '20 03:05 helsonxiao

If this workaround is acceptable, I will pull a request in this weekend.

helsonxiao avatar May 28 '20 03:05 helsonxiao

Any update on this issue ?

karanjhinga avatar Sep 27 '20 22:09 karanjhinga

hi,

I had the same issue too.

But when I change my onChange not to modify the index then it solved the issue.

co2nut avatar Nov 04 '20 11:11 co2nut

looking forward to this PR!

bneigher avatar Dec 26 '20 04:12 bneigher

This repo is not active for some time.

How to fix it?

  1. Copy all source codes into your project with my workaround(must be a project using typescript)
  2. Fork this repo and republish your own version

helsonxiao avatar Jan 04 '21 16:01 helsonxiao