我使用具有大量项目的FlatList.我收到了来自Expo XDE的警告.
VirtualizedList:你有一个很快更新的大型列表 - 确保你的renderItem函数呈现遵循React性能最佳实践的组件,如PureComponent,shouldComponentUpdate等.{"dt":13861,"prevDt":1498372326027,"contentLength": 6624}
我在FlatList中使用了一些优化方法,例如PureComponent,但我仍然得到这个警告.在我描述我的优化之前,你能否告诉我,即使FlatList被优化,是否仍会出现此警报?或者它可能表明性能的实际问题?我问,因为我的FlatList的表现很好.
我已经使用panResponder和ScrollView实现了拖放列表。我希望即使在触摸项目时也可以滚动列表。问题是当我做手势滚动时项目会移动。当然,我也希望能够移动该项目,但是现在它具有与滚动相同的手势。我想通过仅在长按(1.5秒)后才拖动元素来克服它。如何执行呢?我认为可以将Touchable用作onPressIn / onPressOut的元素,如此处所述:http : //browniefed.com/blog/react-native-press-and-hold-button-actions/并以某种方式在该时间段后启用panResponder ,但我不知道如何以编程方式启用它。
现在,这是我在列表中的元素代码:
class AccountItem extends Component {
constructor(props) {
super(props);
this.state = {
pan: new Animated.ValueXY(),
zIndex: 0,
}
this.panResponder = PanResponder.create({
onStartShouldSetPanResponder: () => true,
onPanResponderGrant: (e, gestureState) => {
this.setState({ zIndex: 100 });
this.props.disableScroll();
},
onPanResponderMove: Animated.event([null, {
dx: this.state.pan.x,
dy: this.state.pan.y,
}]),
onPanResponderRelease: (e, gesture) => {
this.props.submitNewPositions();
Animated.spring(
this.state.pan,
{toValue:{ x:0, y:0 }}
).start();
this.setState({ zIndex: 0 });
this.props.enableScroll();
}
})
}
meassureMyComponent = (event) => {
const { setElementPosition …Run Code Online (Sandbox Code Playgroud)