mirror of
https://github.com/zoriya/react-native-svg.git
synced 2025-12-20 05:55:10 +00:00
refactor LinearGradient and RadialGradient and add fillOpacity support for LinearGradient and RadialGradient
51 lines
1.3 KiB
JavaScript
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;
|
|
|