import * as React from 'react'; import { Text, View, ViewStyle } from 'react-native'; import Svg, { Defs, LinearGradient, Path, RadialGradient, Rect, Stop, } from 'react-native-svg'; export interface IMDBoxShadowProps { width?: number; height?: number; color?: string; border?: number; radius?: number; opacity?: number; x?: number; y?: number; style?: ViewStyle; } function colorRgb (color: string) { const reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/; let sColor = color.toLowerCase(); const rgb = []; if (sColor && reg.test(sColor)) { if (sColor.length === 4) { let sColorNew = '#'; for (let i = 1; i < 4; i += 1) { sColorNew += sColor.slice(i, i + 1).concat(sColor.slice(i, i + 1)); } sColor = sColorNew; } for (let i = 1; i < 7; i += 2) { rgb.push(parseInt('0x' + sColor.slice(i, i + 2), 10)); } return rgb; } else { throw Error('Invalid Color!'); } } export default class MDBoxShadow extends React.PureComponent { public static defaultProps = { width: 0, height: 0, color: '#000', border: 0, radius: 0, opacity: 1, x: 0, y: 0, }; public render () { const { width = 0, height = 0, color = '#000', border = 0, radius = 0, opacity = 1, x = 0, y = 0, style, children } = this.props!; const lineWidth = border; const rectWidth = width - radius * 2; const rectHeight = height - radius * 2; const rgb = colorRgb(color); const outerWidth = lineWidth + radius; return ( {this.linear('BoxTop')} {this.linear('BoxBottom')} {this.linear('BoxLeft')} {this.linear('BoxRight')} {this.radial('BoxLeftTop')} {this.radial('BoxLeftBottom')} {this.radial('BoxRightTop')} {this.radial('BoxRightBottom')} {typeof children === 'string' ? children : children} ); } private linear (key: string) { const { color, opacity, border = 0 } = this.props; const element1 = ( ); const element2 = ( ); return [element1, element2]; } private radial (key: string) { const { color, opacity, radius = 0, border = 0 } = this.props; const lineWidth = border; const element1 = ( ); const element2 = ( ); const element3 = ( ); return [element1, element2, element3]; } }