UNPKG

1.57 kBJavaScriptView Raw
1import PropTypes from 'prop-types';
2import React from 'react';
3import { ColorPropType, Platform, ViewPropTypes, processColor } from 'react-native';
4import NativeLinearGradient from './NativeLinearGradient';
5export default class LinearGradient extends React.Component {
6 render() {
7 let { colors, locations, start, end, ...props } = this.props;
8 if (locations && colors.length !== locations.length) {
9 console.warn('LinearGradient colors and locations props should be arrays of the same length');
10 locations = locations.slice(0, colors.length);
11 }
12 return (<NativeLinearGradient {...props} colors={Platform.select({
13 web: colors,
14 default: colors.map(processColor),
15 })} locations={locations} startPoint={_normalizePoint(start)} endPoint={_normalizePoint(end)}/>);
16 }
17}
18LinearGradient.propTypes = {
19 ...ViewPropTypes,
20 colors: PropTypes.arrayOf(ColorPropType).isRequired,
21 locations: PropTypes.arrayOf(PropTypes.number),
22 start: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.number), PropTypes.object]),
23 end: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.number), PropTypes.object]),
24};
25function _normalizePoint(point) {
26 if (!point) {
27 return undefined;
28 }
29 if (Array.isArray(point) && point.length !== 2) {
30 console.warn('start and end props for LinearGradient must be of the format [x,y] or {x, y}');
31 return undefined;
32 }
33 return Array.isArray(point) ? point : [point.x, point.y];
34}
35//# sourceMappingURL=LinearGradient.js.map
\No newline at end of file