mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-03 07:06:04 +00:00
finish gradients refactor
This commit is contained in:
+32
-31
@@ -1,48 +1,49 @@
|
||||
import {PropTypes} from 'react';
|
||||
import stopsOpacity from '../lib/stopsOpacity';
|
||||
import React, {PropTypes} from 'react';
|
||||
import {numberProp} from '../lib/props';
|
||||
import Gradient from './Gradient';
|
||||
import {RADIAL_GRADIENT} from '../lib/extract/extractBrush';
|
||||
import insertColorStopsIntoArray from '../lib/insertProcessor';
|
||||
|
||||
|
||||
function RadialGradientGenerator(stops, fx, fy, rx, ry, cx, cy) {
|
||||
let brushData = [RADIAL_GRADIENT, ...[fx, fy, rx, ry, cx, cy].map(prop => prop.toString())];
|
||||
insertColorStopsIntoArray(stops, brushData, 7);
|
||||
this._brush = brushData;
|
||||
}
|
||||
import createReactNativeComponentClass from 'react/lib/createReactNativeComponentClass';
|
||||
import {RadialGradientAttributes} from '../lib/attributes';
|
||||
|
||||
class RadialGradient extends Gradient{
|
||||
static displayName = 'RadialGradient';
|
||||
static propTypes = {
|
||||
fx: numberProp,
|
||||
fy: numberProp,
|
||||
fx: numberProp.isRequired,
|
||||
fy: numberProp.isRequired,
|
||||
rx: numberProp,
|
||||
ry: numberProp,
|
||||
cx: numberProp,
|
||||
cy: numberProp,
|
||||
cx: numberProp.isRequired,
|
||||
cy: numberProp.isRequired,
|
||||
r: numberProp,
|
||||
id: PropTypes.string.isRequired
|
||||
};
|
||||
|
||||
render() {
|
||||
let {
|
||||
fx,
|
||||
fy,
|
||||
rx,
|
||||
ry,
|
||||
cx,
|
||||
cy,
|
||||
r
|
||||
} = this.props;
|
||||
return super.render(
|
||||
(stops, opacity) => {
|
||||
static defaultProps = {
|
||||
fx: '50%',
|
||||
fy: '50%',
|
||||
cx: '50%',
|
||||
cy: '50%',
|
||||
r: '50%'
|
||||
};
|
||||
|
||||
render() {
|
||||
let {props} = this;
|
||||
return <RNSVGRadialGradient
|
||||
fx={props.fx.toString()}
|
||||
fy={props.fy.toString()}
|
||||
rx={(props.rx || props.r).toString()}
|
||||
ry={(props.ry || props.r).toString()}
|
||||
cx={props.cx.toString()}
|
||||
cy={props.cy.toString()}
|
||||
gradient={this.getGradient()}
|
||||
name={props.id}
|
||||
/>;
|
||||
|
||||
return new RadialGradientGenerator(stopsOpacity(stops, opacity), ...[fx, fy, rx || r, ry || r, cx, cy]);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const RNSVGRadialGradient = createReactNativeComponentClass({
|
||||
validAttributes: RadialGradientAttributes,
|
||||
uiViewClassName: 'RNSVGRadialGradient'
|
||||
});
|
||||
|
||||
export default RadialGradient;
|
||||
export {RadialGradientGenerator};
|
||||
|
||||
Reference in New Issue
Block a user