react-native-linear-gradient/index.ios.js

38 lines
1.0 KiB
JavaScript
Raw Normal View History

/**
* @providesModule LinearGradient
* @flow
*/
import React, { Component, PropTypes } from 'react';
2016-05-05 10:12:40 +00:00
import { processColor, requireNativeComponent, View } from 'react-native';
2015-09-29 16:43:22 +00:00
export default class LinearGradient extends Component {
static propTypes = {
start: PropTypes.arrayOf(PropTypes.number),
end: PropTypes.arrayOf(PropTypes.number),
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
locations: PropTypes.arrayOf(PropTypes.number),
...View.propTypes,
};
2016-06-12 20:21:55 +00:00
render() {
const {
colors,
locations,
...otherProps
} = this.props;
if ((colors && locations) && (colors.length !== locations.length)) {
console.warn('LinearGradient colors and locations props should be arrays of the same length');
}
return (
<NativeLinearGradient
{...otherProps}
colors={colors.map(processColor)}
locations={locations ? locations.slice(0, colors.length) : null}
/>
);
2015-09-29 16:43:22 +00:00
}
}
const NativeLinearGradient = requireNativeComponent('BVLinearGradient', null);