Merge pull request #129 from cpunion/master

Fix point type
This commit is contained in:
Dmitry Gladkov 2016-12-26 18:13:04 +02:00 committed by GitHub
commit e4ead962c8

View File

@ -3,19 +3,47 @@
* @flow * @flow
*/ */
import React, { Component, PropTypes } from 'react'; import React, { Component, PropTypes } from 'react';
import { processColor, requireNativeComponent, View } from 'react-native'; import { processColor, requireNativeComponent, PointPropType, View } from 'react-native';
const deprecatedPropType = require('react-native/Libraries/Utilities/deprecatedPropType.js');
const convertPoint = (name, point) => {
if (Array.isArray(point)) {
console.warn(
`LinearGradient '${name}' property shoule be an object with fields 'x' and 'y', ` +
'Array type is deprecated.'
);
return {
x: point[0],
y: point[1]
};
}
return point;
};
type PropsType = { type PropsType = {
start?: Array<number>; start?: Array<number> | {x: number, y: number};
end?: Array<number>; end?: Array<number> | {x: number, y: number};
colors: Array<string>; colors: Array<string>;
locations?: Array<number>; locations?: Array<number>;
} & typeof(View); } & typeof(View);
export default class LinearGradient extends Component { export default class LinearGradient extends Component {
static propTypes = { static propTypes = {
start: PropTypes.arrayOf(PropTypes.number), start: PropTypes.oneOfType([
end: PropTypes.arrayOf(PropTypes.number), 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(PropTypes.string).isRequired, colors: PropTypes.arrayOf(PropTypes.string).isRequired,
locations: PropTypes.arrayOf(PropTypes.number), locations: PropTypes.arrayOf(PropTypes.number),
...View.propTypes, ...View.propTypes,
@ -29,6 +57,8 @@ export default class LinearGradient extends Component {
render() { render() {
const { const {
start,
end,
colors, colors,
locations, locations,
...otherProps ...otherProps
@ -41,6 +71,8 @@ export default class LinearGradient extends Component {
<NativeLinearGradient <NativeLinearGradient
ref={(component) => { this.gradientRef = component; }} ref={(component) => { this.gradientRef = component; }}
{...otherProps} {...otherProps}
start={convertPoint('start', start)}
end={convertPoint('end', end)}
colors={colors.map(processColor)} colors={colors.map(processColor)}
locations={locations ? locations.slice(0, colors.length) : null} locations={locations ? locations.slice(0, colors.length) : null}
/> />