简体   繁体   English

使用 panResponder 时,如何在平面列表中拖放单个项目?

[英]How can I drag and drop single item in flatlist when use panResponder?

I use flatList for render each item from array data.我使用 flatList 来渲染数组数据中的每个项目。 I want to drag and drop each item flatlist so I used panResponder and aminated API.我想拖放每个项目平面列表,所以我使用了 panResponder 和胺化 API。 But when I drag and drop, it moving all item in flatList at the same time.但是当我拖放时,它会同时移动 flatList 中的所有项目。 How can I move only 1 item that I click in this.如何仅移动我在其中单击的 1 个项目。

 return (
  <Animated.View
    key={item.index}
    {...this.panResponder.panHandlers}
    style={this.state.pan.getLayout()}>
    <View
      key={item.index}
      style={[styles.event, {
        left: item.left + 50,
        height: item.height,
        width: item.width,
        top: item.top
      }]}
    >
      {this.props.renderEvent ? this.props.renderEvent(item) : (

        <TouchableOpacity
          activeOpacity={0.5}
          onPress={() => this._onEventTapped(this.props.events[item.index])}
        >
          <Text numberOfLines={1} style={styles.eventTitle}>{item.title || 'Event'}</Text>

          {numberOfLines > 1
            ? <Text
              numberOfLines={numberOfLines - 1}
              style={[styles.eventSummary]}
            >
              {item.summary || ' '}
            </Text>
            : null}
          {numberOfLines > 2
            ? <Text style={styles.eventTimes} numberOfLines={1}>{moment(item.start).format(formatTime)} - {moment(item.end).format(formatTime)}</Text>
            : null}
        </TouchableOpacity>

      )}

    </View>
  </Animated.View>
)

enter image description here在此处输入图片说明

you could try this lib:https://github.com/computerjazz/react-native-draggable-flatlist你可以试试这个库:https ://github.com/computerjazz/react-native-draggable-flatlist

it does exactly what you need.它完全符合您的需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM