From fe55ead1755e5dbdb351a65493dc13b03342fc53 Mon Sep 17 00:00:00 2001 From: Dmitry Gladkov Date: Wed, 25 May 2016 12:56:09 +0300 Subject: [PATCH] Ensure that locations prop array has the same length as colors array --- index.android.js | 6 +++++- index.ios.js | 13 +++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/index.android.js b/index.android.js index 11199af..496156f 100644 --- a/index.android.js +++ b/index.android.js @@ -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 } diff --git a/index.ios.js b/index.ios.js index 8285542..eb65eca 100644 --- a/index.ios.js +++ b/index.ios.js @@ -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 ( - + ); } });