mirror of
https://github.com/zoriya/react-native-svg.git
synced 2025-12-20 05:55:10 +00:00
Support G inherit props. Refactor text render. Text glyphs will perfectly draw along the path
62 lines
1.8 KiB
JavaScript
62 lines
1.8 KiB
JavaScript
import extractFill from './extractFill';
|
|
import extractStroke from './extractStroke';
|
|
import extractTransform from './extractTransform';
|
|
import extractClipping from './extractClipping';
|
|
import extractResponder from './extractResponder';
|
|
import extractOpacity from './extractOpacity';
|
|
import {RenderableOnlyAttributes} from '../attributes';
|
|
import _ from 'lodash';
|
|
|
|
export default function(props, options = {stroke: true, transform: true, fill: true, responder: true}) {
|
|
let propList = [];
|
|
Object.keys(RenderableOnlyAttributes).forEach(name => {
|
|
if (!_.isNil(props[name])) {
|
|
// clipPath prop may provide `clipPathRef` as native prop
|
|
if (name === 'clipPath') {
|
|
if (extractedProps[name]) {
|
|
propList.push(name);
|
|
} else if (extractedProps.clipPathRef) {
|
|
propList.push('clipPathRef');
|
|
}
|
|
} else {
|
|
propList.push(name);
|
|
}
|
|
}
|
|
});
|
|
|
|
let extractedProps = {
|
|
opacity: extractOpacity(props.opacity),
|
|
propList
|
|
};
|
|
|
|
if (props.id) {
|
|
extractedProps.name = props.id;
|
|
}
|
|
|
|
if (props.clipPath) {
|
|
_.assign(extractedProps, extractClipping(props));
|
|
}
|
|
|
|
if (options.stroke) {
|
|
_.assign(extractedProps, extractStroke(props));
|
|
}
|
|
|
|
if (options.fill) {
|
|
_.assign(extractedProps, extractFill(props));
|
|
}
|
|
|
|
if (options.transform) {
|
|
extractedProps.transform = extractTransform(props);
|
|
} else if (props.transform) {
|
|
// todo: add support for transform prop like this:
|
|
// {scale: 1.5, translate: '10 10'}
|
|
extractedProps.transform = props.transform;
|
|
}
|
|
|
|
if (options.responder) {
|
|
_.assign(extractedProps, extractResponder(props));
|
|
}
|
|
|
|
return extractedProps;
|
|
}
|