Skip to content

Commit

Permalink
Fix point type
Browse files Browse the repository at this point in the history
  • Loading branch information
cpunion committed Dec 7, 2016
1 parent 4c5c2d8 commit 23b9606
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions index.ios.js
Expand Up @@ -3,19 +3,47 @@
* @flow
*/
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 = {
start?: Array<number>;
end?: Array<number>;
start?: Array<number> | {x: number, y: number};
end?: Array<number> | {x: number, y: number};
colors: Array<string>;
locations?: Array<number>;
} & typeof(View);

export default class LinearGradient extends Component {
static propTypes = {
start: PropTypes.arrayOf(PropTypes.number),
end: PropTypes.arrayOf(PropTypes.number),
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(PropTypes.string).isRequired,
locations: PropTypes.arrayOf(PropTypes.number),
...View.propTypes,
Expand All @@ -29,6 +57,8 @@ export default class LinearGradient extends Component {

render() {
const {
start,
end,
colors,
locations,
...otherProps
Expand All @@ -41,6 +71,8 @@ export default class LinearGradient extends Component {
<NativeLinearGradient
ref={(component) => { this.gradientRef = component; }}
{...otherProps}
start={convertPoint('start', start)}
end={convertPoint('end', end)}
colors={colors.map(processColor)}
locations={locations ? locations.slice(0, colors.length) : null}
/>
Expand Down

0 comments on commit 23b9606

Please sign in to comment.