Javascript 平面列表/滚动视图不';不要在可触摸屏之间滚动
我有一个平面列表,其中包含可触摸的内容作为其渲染。出于某种原因,除非您在其中一个触摸屏上启动滚动,否则滚动无法工作。也就是说,如果我单击项目之间的空格(填充/边距)并尝试滚动,它将不起作用Javascript 平面列表/滚动视图不';不要在可触摸屏之间滚动,javascript,react-native,scrollview,touchableopacity,react-native-modal,Javascript,React Native,Scrollview,Touchableopacity,React Native Modal,我有一个平面列表,其中包含可触摸的内容作为其渲染。出于某种原因,除非您在其中一个触摸屏上启动滚动,否则滚动无法工作。也就是说,如果我单击项目之间的空格(填充/边距)并尝试滚动,它将不起作用 <Modal onStartShouldSetResponder={() => true} animationType="slide" transparent={true}
<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>
true}
animationType=“幻灯片”
透明={true}
可见={modalVisible}>
true}style={styles.modalView}>
评论
真的}
数据={comments}
renderItem={(项目)=>{
返回;
}}>
正如你所看到的,我试着在所有地方都安装了StartShouldSetResponder,但它似乎没有任何作用
以下是注释组件的外观,仅供参考:
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>
);
};
const Comment=({item})=>{
console.log('nothingsensseee');
log('comment id,cluck id',item.cluck,data.id,data.username);
返回(
{
setReplyPlaceholder(`Reply to${item.user.name}`);
inputEl.current.focus();
设置结束函数(
() =>
功能(事件){
if(event.nativeEvent.text.trim()!=''){
const user=firebase.auth().currentUser;
var db=firebase.firestore();
const id='UbWIMWFCOGbs00S2ZcPN';
const newreplays=item.replays+1;
console.log(item.replays,item.children);
item.children.push({
用户:{
名称:user.displayName,
photoURL:user.photoURL,
userId:user.uid,
},
cluck:data.id,
文本:event.nativeEvent.text,
喜欢:2,,
});
db.collection('comments').doc(id).更新({
答复:新的答复,
子项:item.children,
});
setComment(“”);
}
},
);
}}
样式={}>
{item.user.name}
{renderPostTime(新日期(),item.Date)}
{item.text}
);
};
在图像上启动滚动也没有任何作用。由于某些原因,滚动条只对可触摸的对象做出响应。我通过大量使用手势响应系统修复了它: 具体来说,我必须用一个包装在scrollview中的视图替换我的平面列表。该视图的属性为onMoveShouldSetResponder={(evt)=>true}:
对}>
...
我原来的无反馈触摸屏把我需要更换的东西都包起来了
<View onStartShouldSetResponder={()=>{
setState(true);
return false;
}}
>
...
</View>
{
设置状态(真);
返回false;
}}
>
...
返回false之前的setState很重要,因为它允许我做我想做的事情,而不会阻止ScrollView在需要时控制触摸
无论如何,所有这些都破坏了我最初作为renderItem组件的内部可触摸性,因此我不得不用响应道具替换类似的视图
<View onStartShouldSetResponder={()=>{
setState(true);
return false;
}}
>
...
</View>