Add proper flow types

This commit is contained in:
Connor McEwen 2016-11-08 15:05:34 -08:00
parent c719101c49
commit 8c64dcab94
2 changed files with 26 additions and 6 deletions

View File

@ -1,6 +1,15 @@
// @flow
import React, { Component, PropTypes } from 'react';
import { processColor, requireNativeComponent, StyleSheet, View } from 'react-native';
type PropsType = {
start?: Array<number>;
end?: Array<number>;
colors: Array<string>;
locations?: Array<number>;
} & typeof(View);
export default class LinearGradient extends Component {
static propTypes = {
start: PropTypes.arrayOf(PropTypes.number),
@ -9,9 +18,11 @@ export default class LinearGradient extends Component {
locations: PropTypes.arrayOf(PropTypes.number),
...View.propTypes,
};
props: PropsType;
gradientRef: any;
setNativeProps(props) {
this.c.setNativeProps(props);
setNativeProps(props: PropsType) {
this.gradientRef.setNativeProps(props);
}
render() {
@ -48,7 +59,7 @@ export default class LinearGradient extends Component {
];
return (
<View ref={(c) => { this.c = c; }} {...otherProps} style={style}>
<View ref={(component) => { this.gradientRef = component; }} {...otherProps} style={style}>
<NativeLinearGradient
style={{position: 'absolute', top: 0, left: 0, bottom: 0, right: 0}}
colors={colors.map(processColor)}

View File

@ -5,6 +5,13 @@
import React, { Component, PropTypes } from 'react';
import { processColor, requireNativeComponent, View } from 'react-native';
type PropsType = {
start?: Array<number>;
end?: Array<number>;
colors: Array<string>;
locations?: Array<number>;
} & typeof(View);
export default class LinearGradient extends Component {
static propTypes = {
start: PropTypes.arrayOf(PropTypes.number),
@ -13,9 +20,11 @@ export default class LinearGradient extends Component {
locations: PropTypes.arrayOf(PropTypes.number),
...View.propTypes,
};
props: PropsType;
gradientRef: any;
setNativeProps(props) {
this.c.setNativeProps(props);
setNativeProps(props: PropsType) {
this.gradientRef.setNativeProps(props);
}
render() {
@ -30,7 +39,7 @@ export default class LinearGradient extends Component {
return (
<NativeLinearGradient
ref={(c) => { this.c = c; }}
ref={(component) => { this.gradientRef = component; }}
{...otherProps}
colors={colors.map(processColor)}
locations={locations ? locations.slice(0, colors.length) : null}