react-native - 如何修复包裹在 TouchableOpacity 中的 Icon 的奇怪行为?
问题描述
我有一个 MapView,里面有一个固定的市场供用户拖动地图并设置当前位置,一个保存更改的按钮和一个包裹在可触摸不透明度中以设置当前位置的图标。我的问题是有时包装 TouchableOpacity 的 Icon 出现在右上角。
地图视图的代码
<Modal
animationType="slide"
transparent={false}
visible={modalVisible}
onRequestClose={() => { }}
>
<MapView
style={styles.map}
onRegionChangeComplete={this.onRegionChange}
initialRegion={region || initialCoordinates}
ref={(el) => { this.mapViewModal = el }}
>
<View pointerEvents="none" style={[styles.markerFixed, { marginBottom: 52 }]}>
<Ionicons style={styles.marker} pointerEvents="none" name="ios-pin" size={72} />
</View>
<TouchableOpacity onPress={this.setMapCurrentLocation} style={styles.arrowWrapper}>
<FontAwesome name="location-arrow" style={styles.locationArrow} size={42} />
</TouchableOpacity>
</MapView>
<View style={styles.mapButtonWrapper}>
<RkButton
style={styles.mapButton}
onPress={this.handleAdjustClick}
>
{i18n.t('Adjust')}
</RkButton>
</View>
</Modal>
款式:
arrowWrapper: {
position: 'absolute',
backgroundColor: 'white',
borderRadius: 100,
textAlign: 'center',
width: 50,
height: 50,
padding: 5,
right: 10,
bottom: 75,
justifyContent: 'flex-end',
alignItems: 'flex-end'
},
locationArrow: {
color: primaryColor,
alignSelf: 'center'
},
有人知道如何解决这个问题吗?
解决方案
通过将 TouchableOpacity 移出 MapView 并包装到 View 中进行修复:
<Modal
animationType="slide"
transparent={false}
visible={modalVisible}
onRequestClose={() => { }}
>
<MapView
style={styles.map}
onRegionChangeComplete={this.onRegionChange}
initialRegion={region || initialCoordinates}
ref={(el) => { this.mapViewModal = el }}
>
<View pointerEvents="none" style={[styles.markerFixed, { marginBottom: 52 }]}>
<Ionicons style={styles.marker} pointerEvents="none" name="ios-pin" size={72} />
</View>
</MapView>
<View style={styles.arrowWrapper}>
<TouchableOpacity onPress={this.setMapCurrentLocation}>
<FontAwesome name="location-arrow" style={styles.locationArrow} size={42} />
</TouchableOpacity>
</View>
<View style={styles.mapButtonWrapper}>
<RkButton
style={styles.mapButton}
onPress={this.handleAdjustClick}
>
{i18n.t('Adjust')}
</RkButton>
</View>
</Modal>
推荐阅读
- javascript - 定义一个函数 lastIndexOf?
- reactjs - 如何使用 gorilla/mux 在 GO 中提供带有我的 html 的 bundle.js 文件
- javascript - 如何防止 Electron 应用中断 macOS 系统关机?
- apache-spark - Spark 结构化流写入流到 Hive ORC 分区外部表
- ios - IOS/Objective-C:Objective-C 中的简单库,可以在没有 Cocoapods 的情况下制作简单的条形图
- cypher - 如何使用 neo4j 找到闭合循环
- android - Android 8.0 oreo 中的 MediaRecorder
- android - 突然出现错误时无法看到 logcat 启动最后一个活动
- xamarin.android - 检查用户是否在 xamarin.android 中使用 xamarin.googleplayservices.auth 登录
- regex - 匹配单词之前的所有单词(如果存在或不存在)