mirror of
https://github.com/status-im/react-native-linear-gradient.git
synced 2025-01-22 05:28:58 +00:00
commit
e4ead962c8
42
index.ios.js
42
index.ios.js
@ -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}
|
||||||
/>
|
/>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user