2015-09-30 17:06:36 +00:00
|
|
|
var React = require('react-native');
|
2016-01-27 13:16:29 +00:00
|
|
|
var flattenStyle = require('flattenStyle');
|
2015-09-30 17:06:36 +00:00
|
|
|
var { requireNativeComponent, PropTypes, View, processColor } = React;
|
|
|
|
|
|
|
|
|
|
|
|
var LinearGradient = React.createClass({
|
|
|
|
propTypes: {
|
2015-10-01 16:48:02 +00:00
|
|
|
start: PropTypes.array,
|
|
|
|
end: PropTypes.array,
|
2015-09-30 17:06:36 +00:00
|
|
|
colors: PropTypes.array.isRequired,
|
2015-12-07 18:15:01 +00:00
|
|
|
locations: PropTypes.array,
|
|
|
|
...View.propTypes,
|
2015-09-30 17:06:36 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
2015-10-01 16:48:02 +00:00
|
|
|
var {style, children, colors, locations, start, end, ...otherProps} = this.props;
|
2016-01-19 17:31:20 +00:00
|
|
|
|
|
|
|
// inherit container borderRadius until this issue is resolved:
|
|
|
|
// https://github.com/facebook/react-native/issues/3198
|
2016-01-27 13:16:29 +00:00
|
|
|
var borderRadius = flattenStyle(style).borderRadius || 0;
|
2016-01-19 17:31:20 +00:00
|
|
|
|
2015-09-30 17:06:36 +00:00
|
|
|
return (
|
|
|
|
<View style={style}>
|
|
|
|
<NativeLinearGradient
|
|
|
|
style={{position: 'absolute', top: 0, left: 0, bottom: 0, right: 0}}
|
|
|
|
colors={colors.map(processColor)}
|
2015-10-01 16:48:02 +00:00
|
|
|
start={start}
|
|
|
|
end={end}
|
2016-01-19 17:31:20 +00:00
|
|
|
locations={locations}
|
|
|
|
borderRadius={borderRadius}
|
|
|
|
/>
|
2015-09-30 17:06:36 +00:00
|
|
|
{ children }
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
var NativeLinearGradient = requireNativeComponent('BVLinearGradient', LinearGradient);
|
|
|
|
|
|
|
|
module.exports = LinearGradient;
|