-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ios.js
86 lines (78 loc) · 2.35 KB
/
index.ios.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
* @providesModule LinearGradient
* @flow
*/
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { processColor, PointPropType, View, ViewPropTypes } from 'react-native';
import type { ViewProps } from 'react-native/Libraries/Components/View/ViewPropTypes';
const deprecatedPropType = require('react-native/Libraries/Utilities/deprecatedPropType.js');
const ColorPropType = require('react-native/Libraries/StyleSheet/ColorPropType.js');
import NativeLinearGradient from './nativeLinearGradient';
const convertPoint = (name, point) => {
if (Array.isArray(point)) {
console.warn(
`LinearGradient '${name}' property should be an object with fields 'x' and 'y', ` +
'Array type is deprecated.'
);
return {
x: point[0],
y: point[1]
};
}
return point;
};
type PropsType = {
start?: Array<number> | {x: number, y: number};
end?: Array<number> | {x: number, y: number};
colors: Array<string>;
locations?: Array<number>;
} & ViewProps;
export default class LinearGradient extends Component {
static propTypes = {
start: PropTypes.oneOfType([
PointPropType,
deprecatedPropType(
PropTypes.arrayOf(PropTypes.number),
'Use point object with {x, y} instead.'
)
]),
end: PropTypes.oneOfType([
PointPropType,
deprecatedPropType(
PropTypes.arrayOf(PropTypes.number),
'Use point object with {x, y} instead.'
)
]),
colors: PropTypes.arrayOf(ColorPropType).isRequired,
locations: PropTypes.arrayOf(PropTypes.number),
...ViewPropTypes,
};
props: PropsType;
gradientRef: any;
setNativeProps(props: PropsType) {
this.gradientRef.setNativeProps(props);
}
render() {
const {
start,
end,
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 (
<NativeLinearGradient
ref={(component) => { this.gradientRef = component; }}
{...otherProps}
startPoint={convertPoint('start', start)}
endPoint={convertPoint('end', end)}
colors={colors.map(processColor)}
locations={locations ? locations.slice(0, colors.length) : null}
/>
);
}
}