在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 = { 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', 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