我有一个 FlatList,其中包含 Touchables 作为它的 renderItems。出于某种原因,除非您在其中一个可触摸设备上开始滚动,否则滚动将不起作用。也就是说,如果我单击项目之间的空间(填充/边距)并尝试滚动,它就不起作用。
<Modal
onStartShouldSetResponder={() => true}
animationType="slide"
transparent={true}
visible={modalVisible}>
<View onStartShouldSetResponder={() => true} style={styles.modalView}>
<Text style={styles.modalText}>Comments</Text>
<FlatList
onStartShouldSetResponder={() => true}
data={comments}
renderItem={(item) => {
return <Comment key={item.item.text} item={item.item} />;
}}></FlatList>
</View>
</Modal>
如您所见,我尝试将 onStartShouldSetResponder 放在任何地方,但它似乎没有做任何事情。
作为参考,这是 Comment 组件的样子:
const Comment = ({item}) => {
console.log('NOTHING MAKES SENSSEEE');
console.log('comment id, cluck id', item.cluck, data.id, data.username);
return (
<View key={item.text} style={styles.commentWrapperStyle}>
<View style={{flex: 1, flexDirection: 'row'}}>
<Image
source={{
uri: item.user.photoURL,
}}
style={styles.profileStyle}
/>
<TouchableOpacity
onPress={() => {
setReplyPlaceholder(`Reply to ${item.user.name}`);
inputEl.current.focus();
setSendFunction(
() =>
function (event) {
if (event.nativeEvent.text.trim() !== '') {
const user = firebase.auth().currentUser;
var db = firebase.firestore();
const id = 'UbWIMWFCOGbs00S2ZcPN';
const newReplies = item.replies + 1;
console.log(item.replies, item.children);
item.children.push({
user: {
name: user.displayName,
photoURL: user.photoURL,
userId: user.uid,
},
cluck: data.id,
text: event.nativeEvent.text,
likes: 2,
});
db.collection('comments').doc(id).update({
replies: newReplies,
children: item.children,
});
setComment('');
}
},
);
}}
style={{}}>
<View style={{flex: 1, flexDirection: 'row'}}>
<Text style={styles.textBold}>{item.user.name}</Text>
<Text style={styles.textBold}>
{renderPostTime(new Date(), item.date)}
</Text>
</View>
<Text style={styles.commentTextStyle}>{item.text}</Text>
</TouchableOpacity>
</View>
<RepliesButton item={item} />
</View>
);
};
在图像上开始滚动也不做任何事情。由于某种原因,滚动只响应 Touchable。