UNPKG

1.04 kBJavaScriptView Raw
1'use strict';
2
3import React, {
4 Component,
5 PropTypes,
6} from 'react';
7
8import {
9 View,
10 processColor,
11 requireNativeComponent,
12} from 'react-native';
13
14export default class LinearGradient extends Component {
15 static propTypes = {
16 start: PropTypes.arrayOf(PropTypes.number),
17 end: PropTypes.arrayOf(PropTypes.number),
18 colors: PropTypes.arrayOf(PropTypes.string).isRequired,
19 locations: PropTypes.arrayOf(PropTypes.number),
20 ...View.propTypes,
21 };
22
23 render() {
24 const {
25 colors,
26 locations,
27 ...otherProps,
28 } = this.props;
29 if ((colors && locations) && (colors.length !== locations.length)) {
30 console.warn('LinearGradient colors and locations props should be arrays of the same length');
31 }
32
33 return (
34 <NativeLinearGradient
35 {...otherProps}
36 colors={colors.map(processColor)}
37 locations={locations ? locations.slice(0, colors.length) : null}
38 />
39 );
40 }
41}
42
43const NativeLinearGradient = requireNativeComponent('ExponentLinearGradient', null);