import * as React from 'react' import { View, ViewStyle, StyleSheet, ViewProperties } from 'react-native' const { Svg, Rect, Defs, LinearGradient, Stop, RadialGradient, Path } = require('react-native-svg') const alpha = require('color-alpha') interface BoxShadowProperties extends ViewProperties { settings: { width?: number height?: number color?: string border?: number radius?: number opacity?: number x?: number y?: number } } class BoxShadow extends React.Component { linear(key: string, opacity: number, color: string) { return [ , ] } radial(key: string, opacity: number, color: string, offset: number) { return [ , , ] } render() { const { settings, children, ...others } = this.props const { width = 0, height = 0, color = "#000", border = 0, radius = 0, opacity = 1, x = 0, y = 0, } = settings const lineWidth = border, rectWidth = width - radius * 2, rectHeight = height - radius * 2 const outerWidth = lineWidth + radius const middleOffset = radius / outerWidth return ( {this.linear('BoxTop', opacity, color)} {this.linear('BoxBottom', opacity, color)} {this.linear('BoxLeft', opacity, color)} {this.linear('BoxRight', opacity, color)} {this.radial('BoxLeftTop', opacity, color, middleOffset)} {this.radial('BoxLeftBottom', opacity, color, middleOffset)} {this.radial('BoxRightTop', opacity, color, middleOffset)} {this.radial('BoxRightBottom', opacity, color, middleOffset)} {children} ) } } export class ShadowView extends React.Component { render() { const { style, children, ...otherProps } = this.props const styleObject = StyleSheet.flatten(this.props.style) const { shadowColor, shadowOffset, shadowOpacity, shadowRadius, ...other } = styleObject const { width, height, margin, marginHorizontal, marginVertical, marginTop, marginRight, marginBottom, marginLeft, position, left, right, bottom, top, flex, alignSelf, flexBasis, flexGrow, flexShrink, ...innerStyle } = other as any const { borderRadius } = innerStyle const outerStyle = { width, height, margin, marginHorizontal, marginVertical, marginTop, marginRight, marginBottom, marginLeft, position, left, right, bottom, top, flex, alignSelf, flexBasis, flexGrow, flexShrink, } const shadowSettings = { width, height, opacity: shadowOpacity * 0.5, border: shadowRadius * 1.15, radius: borderRadius, color: shadowColor, x: shadowOffset.width, y: shadowOffset.height } return ( {children} ) } } export default ShadowView