1import * as React from 'react'; 2import { Platform, processColor } from 'react-native'; 3import NativeLinearGradient from './NativeLinearGradient'; 4/** 5 * Renders a native view that transitions between multiple colors in a linear direction. 6 */ 7export class LinearGradient extends React.Component { 8 render() { 9 const { colors, locations, start, end, ...props } = this.props; 10 let resolvedLocations = locations; 11 if (locations && colors.length !== locations.length) { 12 console.warn('LinearGradient colors and locations props should be arrays of the same length'); 13 resolvedLocations = locations.slice(0, colors.length); 14 } 15 return (React.createElement(NativeLinearGradient, { ...props, colors: Platform.select({ 16 web: colors, 17 default: colors.map(processColor), 18 }), locations: resolvedLocations, startPoint: _normalizePoint(start), endPoint: _normalizePoint(end) })); 19 } 20} 21function _normalizePoint(point) { 22 if (!point) { 23 return undefined; 24 } 25 if (Array.isArray(point) && point.length !== 2) { 26 console.warn('start and end props for LinearGradient must be of the format [x,y] or {x, y}'); 27 return undefined; 28 } 29 return Array.isArray(point) ? point : [point.x, point.y]; 30} 31//# sourceMappingURL=LinearGradient.js.map