Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed "invalid attempt to spread non-iterable instance" #53

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 60 additions & 43 deletions lib/BorderShadow.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,68 @@ import {View} from 'react-native'
import Svg,{ Rect,Defs,LinearGradient,Stop,RadialGradient,Path } from 'react-native-svg'

export default class BorderShadow extends Component {
render = () => {
render = () => {

const { setting:{side="bottom",width=0,color="#000",border=0,opacity=1,inset=false,style={}}, children } = this.props
const { setting:{side="bottom",width=0,color="#000",border=0,opacity=1,inset=false,style={}}, children } = this.props

const linear = (key) => {
return [
<Stop offset="0" stopColor={color} stopOpacity={opacity} key={key+'Linear0'} />,
<Stop offset="1" stopColor={color} stopOpacity="0" key={key+'Linear1'} />
]
}
const linear = (key) => {
return [
<Stop offset="0" stopColor={color} stopOpacity={opacity} key={key+'Linear0'} />,
<Stop offset="1" stopColor={color} stopOpacity="0" key={key+'Linear1'} />
]
}

const lineWidth = border
const lineWidth = border

return (
<View style={[{position:"relative",width:width},style]}>
{(()=>{
switch (side){
case "top":
return [
<Svg height={lineWidth} width={width+lineWidth} style={{position:"absolute",top:(inset?0:-lineWidth)}}>
<Defs>
<LinearGradient id="top" x1="0%" x2="0%" y1="100%" y2="0%">{linear('BorderTop')}</LinearGradient>
<LinearGradient id="top-inset" x1="0%" x2="0%" y1="0%" y2="100%">{linear('BorderTopInset')}</LinearGradient>
</Defs>
<Rect x={0} y={0} width={width} height={lineWidth} fill={`url(#top${inset?"-inset":""})`} />
</Svg>,
...children
]
case "bottom":
return [
...children,
<Svg height={lineWidth} width={width+lineWidth} style={{position:"absolute",bottom:(inset?-lineWidth:0)}}>
<Defs>
<LinearGradient id="bottom" x1="0%" x2="0%" y1="0%" y2="100%">{linear('BorderBottom')}</LinearGradient>
<LinearGradient id="bottom-inset" x1="0%" x2="0%" y1="100%" y2="0%">{linear('BorderBottomInset')}</LinearGradient>
</Defs>
<Rect x={0} y={0} width={width} height={lineWidth} fill={`url(#bottom${inset?"-inset":""})`} />
</Svg>
]
default:
throw new Error("Wrong Type of Side! We just support 'top' and 'bottom'")
return null
}
})()}
</View>
)
}
return (
<View style={[{position:"relative", width:width },style]}>
{(()=>{
switch (side){
case "top":
return [
<Svg
height={lineWidth}
width={width+lineWidth}
style={{
position:"absolute",
top: (inset ? 0 : -lineWidth)
}}
key={'hello'}
>
<Defs>
<LinearGradient id="top" x1="0%" x2="0%" y1="100%" y2="0%">{linear('BorderTop')}</LinearGradient>
<LinearGradient id="top-inset" x1="0%" x2="0%" y1="0%" y2="100%">{linear('BorderTopInset')}</LinearGradient>
</Defs>
<Rect x={0} y={0} width={width} height={lineWidth} fill={`url(#top${inset?"-inset":""})`} />
</Svg>,
children
]
case "bottom":
return [
children,
<Svg
height={lineWidth}
width={width + lineWidth}
style={{
position:"absolute",
bottom: (inset ? -lineWidth : 0)
}}
key={'hello'}
>
<Defs>
<LinearGradient id="bottom" x1="0%" x2="0%" y1="0%" y2="100%">{linear('BorderBottom')}</LinearGradient>
<LinearGradient id="bottom-inset" x1="0%" x2="0%" y1="100%" y2="0%">{linear('BorderBottomInset')}</LinearGradient>
</Defs>
<Rect x={0} y={0} width={width} height={lineWidth} fill={`url(#bottom${inset?"-inset":""})`} />
</Svg>
]
default:
throw new Error("Wrong Type of Side! We just support 'top' and 'bottom'")
return null
}
})()}
{/* {children} */}
</View>
)
}
}
53 changes: 53 additions & 0 deletions lib/BorderShadow.old.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React, {Component} from 'react'
import {View} from 'react-native'
import Svg,{ Rect,Defs,LinearGradient,Stop,RadialGradient,Path } from 'react-native-svg'

export default class BorderShadow extends Component {
render = () => {

const { setting:{side="bottom",width=0,color="#000",border=0,opacity=1,inset=false,style={}}, children } = this.props

const linear = (key) => {
return [
<Stop offset="0" stopColor={color} stopOpacity={opacity} key={key+'Linear0'} />,
<Stop offset="1" stopColor={color} stopOpacity="0" key={key+'Linear1'} />
]
}

const lineWidth = border

return (
<View style={[{position:"relative",width:width},style]}>
{(()=>{
switch (side){
case "top":
return [
<Svg height={lineWidth} width={width+lineWidth} style={{position:"absolute",top:(inset?0:-lineWidth)}}>
<Defs>
<LinearGradient id="top" x1="0%" x2="0%" y1="100%" y2="0%">{linear('BorderTop')}</LinearGradient>
<LinearGradient id="top-inset" x1="0%" x2="0%" y1="0%" y2="100%">{linear('BorderTopInset')}</LinearGradient>
</Defs>
<Rect x={0} y={0} width={width} height={lineWidth} fill={`url(#top${inset?"-inset":""})`} />
</Svg>,
...children
]
case "bottom":
return [
...children,
<Svg height={lineWidth} width={width+lineWidth} style={{position:"absolute",bottom:(inset?-lineWidth:0)}}>
<Defs>
<LinearGradient id="bottom" x1="0%" x2="0%" y1="0%" y2="100%">{linear('BorderBottom')}</LinearGradient>
<LinearGradient id="bottom-inset" x1="0%" x2="0%" y1="100%" y2="0%">{linear('BorderBottomInset')}</LinearGradient>
</Defs>
<Rect x={0} y={0} width={width} height={lineWidth} fill={`url(#bottom${inset?"-inset":""})`} />
</Svg>
]
default:
throw new Error("Wrong Type of Side! We just support 'top' and 'bottom'")
return null
}
})()}
</View>
)
}
}