Ensure that locations prop array has the same length as colors array
This commit is contained in:
parent
937af7ec70
commit
fe55ead175
|
@ -13,6 +13,10 @@ var LinearGradient = React.createClass({
|
||||||
render: function() {
|
render: function() {
|
||||||
var { style, children, colors, locations, start, end, ...otherProps } = this.props;
|
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:
|
// inherit container borderRadius until this issue is resolved:
|
||||||
// https://github.com/facebook/react-native/issues/3198
|
// https://github.com/facebook/react-native/issues/3198
|
||||||
var flatStyle = style && StyleSheet.flatten(style);
|
var flatStyle = style && StyleSheet.flatten(style);
|
||||||
|
@ -38,7 +42,7 @@ var LinearGradient = React.createClass({
|
||||||
colors={colors.map(processColor)}
|
colors={colors.map(processColor)}
|
||||||
start={start}
|
start={start}
|
||||||
end={end}
|
end={end}
|
||||||
locations={locations}
|
locations={locations ? locations.slice(0, colors.length) : null}
|
||||||
borderRadii={borderRadiiPerCorner}
|
borderRadii={borderRadiiPerCorner}
|
||||||
/>
|
/>
|
||||||
{ children }
|
{ children }
|
||||||
|
|
13
index.ios.js
13
index.ios.js
|
@ -17,9 +17,18 @@ var LinearGradient = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function() {
|
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 (
|
return (
|
||||||
<NativeLinearGradient {...otherProps} colors={colors.map(processColor)} />
|
<NativeLinearGradient
|
||||||
|
{...otherProps}
|
||||||
|
colors={colors.map(processColor)}
|
||||||
|
locations={locations ? locations.slice(0, colors.length) : null}
|
||||||
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue