1

伙计们我试图模拟 Instagram 个人资料,react-native-reanimated通过长按来预览照片,而不是PanGestureHandler我们可以喜欢这张照片。但是我在这里遇到了困难,当我想长按照片时,我想将当前按下的图像更改为状态,因此弹出窗口将呈现当前按下的照片,但 PanGestureState立即更改为CANCEL并结束流。如果我不这样做setState,所有手势处理程序都运行良好..

请帮助,我是 react-native-reanimated 的新手,人们对此并没有太多分享

这是我渲染单个照片组件的代码...

import { TouchableOpacity, PanGestureHandler, LongPressGestureHandler } from 'react-native-reanimated';

class Instagram extend Component {

 ...........

  renderItem = (photo, index) => {
    return (
      <TouchableOpacity
        key={index}
        activeOpacity={0.7}
        onPressIn={() => this.setState({currentImage: photo.image})} //when i try to set the state, onGestureEvent on PanGestureHandler immediately canceled
        onPress={this.onTapItem}
      >
        <LongPressGestureHandler
          ref={this.longPressRef}
          simultaneousHandlers={[this.panGestureRef, this.longPressRef]}
          onHandlerStateChange={this.onLongPressStateChange}
        >
          <Animated.View>
            <PanGestureHandler
              ref={this.panGestureRef}
              simultaneousHandlers={[this.longPressRef, this.scrollRef]}
              onGestureEvent={this.onPanGestureHandler}
              onHandlerStateChange={e => console.log(e.nativeEvent.state, 'PAN STATE <<<<<<')}
            >
              <Animated.Image
                style={styles.photoItem(index)}
                source={{ uri: photo.image }}
              />
            </PanGestureHandler>
          </Animated.View>
        </LongPressGestureHandler>
      </TouchableOpacity>
    );
  };

   ..........
}

4

0 回答 0