【发布时间】:2019-06-04 13:46:03
【问题描述】:
我在使用 TouchableOpacity 和 react-native-maps 时遇到问题。
我有一个带有 MapView 和一个 View 的 View,里面有一个绝对定位的 TouchableOpacity,如下面的代码:
<View style={{ flex: 1, flexDirection: 'column-reverse' }}>
<MapView style={{ flex: 1 }} />
<View style={{ height: 55 }}>
<TouchableOpacity style={{ position: 'absolute', top: 100 }}>
<Text>Button</Text>
</TouchableOpacity>
</View>
</View>
当我在这种情况下单击 TouchableOpacity 时,它按预期工作,但我需要我的内部视图具有白色背景色,如下所示:
<View style={{ flex: 1, flexDirection: 'column-reverse' }}>
<MapView style={{ flex: 1 }} />
<View style={{ height: 55, backgroundColor: '#ffffff' }}>
<TouchableOpacity style={{ position: 'absolute', top: 100 }}>
<Text>Button</Text>
</TouchableOpacity>
</View>
</View>
但是,一旦我将 backgroundColor 标签放入样式中,TouchableOpacity 就完全停止工作,并且 MapView 上方的所有点击实际上都被视为地图本身的点击。
有人知道如何解决这个问题吗?我确实需要在 View 中有一个背景,所以无法删除它。
【问题讨论】:
-
您是否尝试过禁用
View上的pointerEvents属性?当backgroundColornottransparent时,它可能在到达TouchableOpacity之前捕获/吞下事件。 -
刚刚尝试过(我不知道 PointerEvents),但不幸的是它仍然不起作用。对我来说,目前的快速解决方案是将两个组件放在另一个视图中,并在这个外部视图中设置背景。
标签: react-native react-native-maps