mirror of
https://github.com/zoriya/react-native-svg.git
synced 2025-12-20 14:05:09 +00:00
support stroke in pattern.
support stroke="url(#pattern)"
This commit is contained in:
@@ -1,63 +1,19 @@
|
||||
import rgba from '../rgba';
|
||||
import {LinearGradientGenerator} from '../../elements/LinearGradient';
|
||||
import {RadialGradientGenerator} from '../../elements/RadialGradient';
|
||||
import extractBrush from './extractBrush';
|
||||
import fillReg from './patternReg';
|
||||
|
||||
let fillPatterns = {};
|
||||
|
||||
function isGradient(obj) {
|
||||
return obj instanceof LinearGradientGenerator || obj instanceof RadialGradientGenerator;
|
||||
}
|
||||
|
||||
function set(id, pattern) {
|
||||
fillPatterns[id] = pattern;
|
||||
}
|
||||
|
||||
function remove(id) {
|
||||
delete fillPatterns[id];
|
||||
}
|
||||
import patterns from './patterns';
|
||||
|
||||
const fillRules = {
|
||||
evenodd: 0,
|
||||
nonzero: 1
|
||||
};
|
||||
|
||||
function fillFilter(props) {
|
||||
function fillFilter(props, dimensions) {
|
||||
let {fill} = props;
|
||||
|
||||
if (fill === 'none') {
|
||||
return null;
|
||||
} if (fill) {
|
||||
|
||||
if (isGradient(fill)) {
|
||||
return fill;
|
||||
}
|
||||
|
||||
let fillOpacity = +props.fillOpacity;
|
||||
if (isNaN(fillOpacity)) {
|
||||
fillOpacity = 1;
|
||||
}
|
||||
|
||||
// 尝试匹配 fill="url(#pattern)"
|
||||
let matched = fill.match(fillReg);
|
||||
|
||||
if (matched) {
|
||||
let patternName = `${matched[1]}:${props.svgId}`;
|
||||
let pattern = fillPatterns[patternName];
|
||||
|
||||
if (pattern) {
|
||||
if (pattern.length === 2) {
|
||||
let dimensions = this.getBoundingBox();
|
||||
return pattern(dimensions, fillOpacity);
|
||||
} else {
|
||||
return pattern(fillOpacity);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
return rgba(props.fill, fillOpacity).rgbaString();
|
||||
} else if (fill) {
|
||||
return patterns(fill, +props.fillOpacity, dimensions, props.svgId);
|
||||
} else if (props.fill === undefined) {
|
||||
let fillOpacity = +props.fillOpacity;
|
||||
if (isNaN(fillOpacity)) {
|
||||
@@ -67,20 +23,14 @@ function fillFilter(props) {
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default function(props) {
|
||||
let fill = fillFilter.call(this, props);
|
||||
export default function(props, dimensions) {
|
||||
let fill = extractBrush(fillFilter(props, dimensions), props);
|
||||
let fillRule = fillRules[props.fillRule] === 0 ? 0 : 1;
|
||||
|
||||
return {
|
||||
fill: extractBrush(fill, props),
|
||||
fill,
|
||||
fillRule
|
||||
};
|
||||
}
|
||||
|
||||
export {
|
||||
set,
|
||||
remove
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user