在RN中,陰影屬性是只對IOS生效,在安卓中,要是設置的是黑色的陰影,可以通過設置elevation屬性,但是如果是其他顏色的陰影的時候就需要使用特殊的方式:
SVG + react-native-shadow插件:
import React, {Component} from 'react';
import {
StyleSheet,
Text,
View,
Image,
WebView,
ScrollView,
NativeModules,
TouchableHighlight,
} from 'react-native';
import {BoxShadow} from 'react-native-shadow';
const {MeiyouRNBridge} = NativeModules,
{windowWidth, windowHeight} = MConfig;
export default class SortList extends MBase {
constructor(props) {
super(props);
this.state = {
};
}
componentWillMount() {
super.componentWillMount();
MeiyouRNBridge.setLoadingState(0);
}
componentDidMount() {
super.componentDidMount();
}
render() {
const shadowOpt = {
width: 160,
height: 170,
color: '#e47854',
border: 2,
radius: 3,
opacity: 0.2,
x: 0,
y: 3,
style: {
marginVertical: 5}};
return (
<BoxShadow setting={shadowOpt}>
<TouchableHighlight style={styles.box}>
<Text>ddddd</Text>
</TouchableHighlight>
</BoxShadow>
);
}
}
const styles = StyleSheet.create({
wrap: {
flex: 1,
// backgroundColor: MConfig.Color.primaryColor,
},
box: {
position: 'relative',
width: 160,
height: 170,
backgroundColor: '#fff',
borderRadius: 3,
borderWidth: 1,
overflow: 'hidden',
},
});
注意:
1、SVG的版本與RN的版本相對應(必須的,不然沒有效果哦~~~具體查看react-native-svg文檔信息):https://github.com/react-native-community/react-native-svg
2、react-native-shadow插件:https://www.npmjs.com/package/react-native-shadow
