Ensure that locations prop array has the same length as colors array

This commit is contained in:
Dmitry Gladkov 2016-05-25 12:56:09 +03:00
parent 937af7ec70
commit fe55ead175
2 changed files with 16 additions and 3 deletions

View File

@ -13,6 +13,10 @@ var LinearGradient = React.createClass({
render: function() {
var { style, children, colors, locations, start, end, ...otherProps } = this.props;
if ((colors && locations) && (colors.length !== locations.length)) {
console.warn('LinearGradient colors and locations props should be arrays of the same length');
}
// inherit container borderRadius until this issue is resolved:
// https://github.com/facebook/react-native/issues/3198
var flatStyle = style && StyleSheet.flatten(style);
@ -38,7 +42,7 @@ var LinearGradient = React.createClass({
colors={colors.map(processColor)}
start={start}
end={end}
locations={locations}
locations={locations ? locations.slice(0, colors.length) : null}
borderRadii={borderRadiiPerCorner}
/>
{ children }

View File

@ -17,9 +17,18 @@ var LinearGradient = React.createClass({
},
render: function() {
var { colors, ...otherProps } = this.props;
var { 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)} />
<NativeLinearGradient
{...otherProps}
colors={colors.map(processColor)}
locations={locations ? locations.slice(0, colors.length) : null}
/>
);
}
});