/* * @Author: mingwei * @Date: 2022-06-30 15:28:29 * @LastEditors: mingwei * @LastEditTime: 2022-07-01 09:11:29 * @FilePath: /react-native-dev-sdk/src/tools/utils/shadow/BoxShadow.tsx * @Description: */ import { Component } from 'react'; import { View } from 'react-native'; import { colorRgb } from './tools'; import Svg, { Rect, Defs, LinearGradient, Stop, RadialGradient, Path } from 'react-native-svg'; export type BoxSettingShadowType = { width: number; height: number; color: string; border: number; radius: number; opacity: number; x: number; y: number; style: any; }; export class BoxShadow extends Component<{ setting: BoxSettingShadowType; children: any }> { render = () => { //get the shadow settings and give them default values const { setting: { width = 0, height = 0, color = '#000', border = 0, radius = 0, opacity = 1, x = 0, y = 0, style = {}, }, children, } = this.props; //define the lengths const lineWidth = border, rectWidth = width - radius * 2, rectHeight = height - radius * 2; //format the color let rgb = colorRgb(color); //the same parts for gradients const linear = key => { return [ , , ]; }; const radial = key => { return [ , , , ]; }; const outerWidth = lineWidth + radius; //return a view ,whose background is a svg picture return ( {linear('BoxTop')} {linear('BoxBottom')} {linear('BoxLeft')} {linear('BoxRight')} {radial('BoxLeftTop')} {radial('BoxLeftBottom')} {radial('BoxRightTop')} {radial('BoxRightBottom')} {children} ); }; }