Files
react-native-svg/elements/LinearGradient.js
Horcrux 3c56ad3dd7 refactor LinearGradient and RadialGradient
refactor LinearGradient and RadialGradient
and add fillOpacity support for LinearGradient and RadialGradient
2016-01-28 18:12:59 +08:00

51 lines
1.3 KiB
JavaScript

import React, {
Component,
PropTypes,
ART,
Children
} from 'react-native';
let {
LinearGradient: ARTLinearGradient
} = ART;
import stopsOpacity from '../lib/stopsOpacity';
import Gradient from './Gradient';
let propType = PropTypes.oneOfType([PropTypes.string, PropTypes.number]);
class LinearGradient extends Gradient{
static displayName = 'LinearGradient';
static propTypes = {
x1: propType,
x2: propType,
y1: propType,
y2: propType,
id: PropTypes.string
};
render() {
let {
x1,
y1,
x2,
y2
} = this.props;
let gradientProps = [x1, y1, x2, y2];
return super.render(
gradientProps,
function (factories, stops, boundingBox, opacity) {
return new ARTLinearGradient(
stopsOpacity(stops, opacity),
factories[0](boundingBox.width),
factories[1](boundingBox.height),
factories[2](boundingBox.width),
factories[3](boundingBox.height)
);
},
function (stops, opacity) {
return new ARTLinearGradient(stopsOpacity(stops, opacity), ...gradientProps);
}
);
}
}
export default LinearGradient;