zoukankan      html  css  js  c++  java
  • React Native 安卓添加阴影

    在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

  • 相关阅读:
    IT名词备忘录——汇编
    逆转链表的实现
    编写安全的代码的一些技巧
    extern c 谈
    回调函数
    职场必备八个黄金句型
    CString类的用法介绍和自己动手写的CString类
    61条面向对象设计的经验原则(转贴)
    sprintf的用法
    VisualStudioVS2010统计代码行数
  • 原文地址:https://www.cnblogs.com/zhanghuiyun/p/8478921.html
Copyright © 2011-2022 走看看