mirror of
https://github.com/zoriya/react-native-svg.git
synced 2025-12-06 07:06:11 +00:00
45 lines
1.1 KiB
JavaScript
45 lines
1.1 KiB
JavaScript
import React, {
|
|
PropTypes
|
|
} from 'react-native';
|
|
|
|
import stopsOpacity from '../lib/stopsOpacity';
|
|
import {numberProp} from '../lib/props';
|
|
import Gradient from './Gradient';
|
|
import {LINEAR_GRADIENT} from '../lib/extract/extractBrush';
|
|
import insertColorStopsIntoArray from '../lib/insertProcessor';
|
|
|
|
function LinearGradientGenerator(stops, x1, y1, x2, y2) {
|
|
var brushData = [LINEAR_GRADIENT, x1, y1, x2, y2];
|
|
insertColorStopsIntoArray(stops, brushData, 5);
|
|
this._brush = brushData;
|
|
}
|
|
|
|
|
|
class LinearGradient extends Gradient{
|
|
static displayName = 'LinearGradient';
|
|
static propTypes = {
|
|
x1: numberProp,
|
|
x2: numberProp,
|
|
y1: numberProp,
|
|
y2: numberProp,
|
|
id: PropTypes.string.isRequired
|
|
};
|
|
|
|
render() {
|
|
let {
|
|
x1,
|
|
y1,
|
|
x2,
|
|
y2
|
|
} = this.props;
|
|
return super.render(
|
|
(stops, opacity) => {
|
|
return new LinearGradientGenerator(stopsOpacity(stops, opacity), ...[x1, y1, x2, y2]);
|
|
}
|
|
);
|
|
}
|
|
}
|
|
|
|
export default LinearGradient;
|
|
export {LinearGradientGenerator};
|