我以前在我的应用中的多个位置使用过FlatList
没有任何问题,但现在当我创建一个新的时,它似乎没有正确注册触摸/滑动。只有1/6触摸似乎注册。
点击此处视频:https://photos.app.goo.gl/NZCtVYX6GLVCQN392
这就是我使用FlatList
:
render() {
return (
<Container>
...
<FlatList
data={this.state.exercises}
renderItem={({item}) =>
<SetsRepsAndWeightItem exercise={item}/>
}
keyExtractor={item => item.name}
style={style.list}
/>
</Container>
);
}
SetsRepsAndWeightItem
:
render() {
return (
<View style={style.container}>
<View style={style.header}>
<Text style={style.headerText}>{this.props.exercise.name}</Text>
</View>
<View style={style.about}>
<TouchableWithoutFeedback onPress={this.handleSetsPressed}>
<StatisticNumber metric="Sets" value={7}/>
</TouchableWithoutFeedback>
<TouchableWithoutFeedback onPress={this.handleRepsPressed}>
<StatisticNumber metric="Reps" value={5}/>
</TouchableWithoutFeedback>
<TouchableWithoutFeedback onPress={this.handleWeightPressed}>
<StatisticNumber metric="kg" value={35}/>
</TouchableWithoutFeedback>
</View>
</View>
);
}
handleSetsPressed = () => {
console.log("sets pressed");
}
handleRepsPressed = () => {
console.log("reps pressed");
}
handleWeightPressed = () => {
console.log("weight pressed");
}
此外:TouchableWithoutFeedback
元素在触摸时未调用onPress
个函数。
Container
就像这样简单:
export default class Container extends Component {
static propTypes = {
children: Proptypes.any,
backgroundColor: Proptypes.string
};
render() {
const containerStyles = StyleSheet.flatten([
style.container,
this.props.backgroundColor ? { backgroundColor: this.props.backgroundColor } : null,
]);
return (
<TouchableWithoutFeedback onPress={() => Keyboard.dismiss()}>
<View style={containerStyles}>
{this.props.children}
</View>
</TouchableWithoutFeedback>
);
}
}
答案 0 :(得分:1)
以下两个修复程序解决了我的问题:
从onPress={() => Keyboard.dismiss()}
组件
Container
将TouchableWithoutFeedback
移至StatisticNumber
组件,并将onPress
作为道具从SetsRepsAndWeightItem