【发布时间】:2020-05-14 04:19:06
【问题描述】:
这就是我想要做的:
我正在尝试在地图视图上放置一个透明的圆圈(如放大镜),并在两侧覆盖深蓝色。这就是我目前所拥有的(故意是黑色的):
import React from 'react';
import {
StyleSheet,
Text,
View,
} from 'react-native';
import MapView from 'react-native-maps';
const GEOFENCE_RANGE = 0.01;
const OrderMap = props => {
return (
<View style={[props.style, styles.container]} >
<MapView style={styles.map}
scrollEnabled={false}
initialRegion={{
latitude: 37.78825,
longitude: -122.4324,
}}
/>
<View style={styles.overlay}>
<View style={styles.circle}/>
</View>
</View>
)
};
const styles = StyleSheet.create({
container: {
position: 'relative',
},
map: {
flex: 1,
},
overlay: {
backgroundColor: 'rgba(21,31,53, 0.5)',
position: 'absolute',
top: 0,
right: 0,
bottom: 0,
left: 0,
alignItems: 'center',
justifyContent: 'center',
},
circle: {
backgroundColor: 'black', // <---------------------------
borderRadius: 100,
alignSelf: 'stretch',
flex: 1,
margin: 50,
}
});
export default OrderMap;
当我尝试将 styles.overlay 更改为使用 backgroundColor: 'transparent' 时,它只会使整个东西变成深蓝色。
有没有办法做到这一点?
附:我正在使用反应原生地图https://github.com/airbnb/react-native-maps
【问题讨论】:
-
这不能单独使用 React Native 样式来实现。你可以使用
react-native-svg,或者编写一个自定义的原生模块来使用 android.graphics/CoreGraphics 渲染一个蒙版的圆圈。我之前已经实现过,让我看看我是否可以将它打包用于开源发布。 -
感谢@jevakallio。我开始研究那个包裹,会告诉你进展如何
-
你做过了吗?我有样品问题。请分享您的解决方案
标签: react-native