React native 知道哪个元素与React Native';谁是应答者?
我正在使用PanResponder进行拖放,但我只希望组件的一部分成为启动拖放的“目标”。ScrollView中包含许多元素,在“目标”之外的元素上拖动应该像往常一样滚动React native 知道哪个元素与React Native';谁是应答者?,react-native,React Native,我正在使用PanResponder进行拖放,但我只希望组件的一部分成为启动拖放的“目标”。ScrollView中包含许多元素,在“目标”之外的元素上拖动应该像往常一样滚动 const Dragger = () => { return ( <View {...panResponder.panHandlers}> <View style={{ flexDirection: 'row' }}>
const Dragger = () => {
return (
<View {...panResponder.panHandlers}>
<View style={{ flexDirection: 'row' }}>
<Text>Drag me</Text>
<Text>Im not draggable</Text>
</View>
<View style={{ flexDirection: 'row' }}>
<Text>Drag me</Text>
<Text>Im not draggable</Text>
</View>
</View>
)
}
const Parent = () => {
return(
<ScrollView>
<Text>Stuff</Text>
<Dragger />
<Text>Stuff</Text>
<ScrollView/>
)
}
您的问题是从一些我在您发布的链接中找不到的片段开始的,因此我从这些片段开始创建了一个fork。 因此,为了让PanResponder在灰色框上拖动事件,而不是在文本输入上拖动事件,您应该在项目组件上执行以下操作:
<View style={[styles.item, { backgroundColor: item.backgroundColor }]} >
<View style={styles.handle} {...panResponder.panHandlers} />
<TextInput style={styles.input}>{item.id}</TextInput>
</View>
{item.id}
对于PanResponder,我使用了
下面是一个关于您的代码的示例,您可以尝试它
希望这有帮助!告诉我这是否对您不起作用。您是否尝试在要使其不可拖动的组件上设置
pointerEvents=“none”
?能否提供组件的可视示例?我已经做了一些类似的东西,但有着component@ivanmoskalev这对我来说不起作用,我需要它来响应其他触摸事件,例如专注于输入或滚动。@WiliamBrochensquejunior我更新了我的问题。
<View style={[styles.item, { backgroundColor: item.backgroundColor }]} >
<View style={styles.handle} {...panResponder.panHandlers} />
<TextInput style={styles.input}>{item.id}</TextInput>
</View>