mirror of
https://github.com/zoriya/react-native-svg.git
synced 2025-12-19 21:45:10 +00:00
refactor all components and isolated from ART dependency
This commit is contained in:
90
lib/attributes.js
Normal file
90
lib/attributes.js
Normal file
@@ -0,0 +1,90 @@
|
||||
|
||||
function arrayDiffer(a, b) {
|
||||
if (a == null) {
|
||||
return true;
|
||||
}
|
||||
if (a.length !== b.length) {
|
||||
return true;
|
||||
}
|
||||
for (var i = 0; i < a.length; i++) {
|
||||
if (a[i] !== b[i]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function fontAndLinesDiffer(a, b) {
|
||||
if (a === b) {
|
||||
return false;
|
||||
}
|
||||
if (a.font !== b.font) {
|
||||
if (a.font === null) {
|
||||
return true;
|
||||
}
|
||||
if (b.font === null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (
|
||||
a.font.fontFamily !== b.font.fontFamily ||
|
||||
a.font.fontSize !== b.font.fontSize ||
|
||||
a.font.fontWeight !== b.font.fontWeight ||
|
||||
a.font.fontStyle !== b.font.fontStyle
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return arrayDiffer(a.lines, b.lines);
|
||||
}
|
||||
|
||||
var NodeAttributes = {
|
||||
transform: {
|
||||
diff: arrayDiffer
|
||||
},
|
||||
opacity: true
|
||||
};
|
||||
|
||||
var GroupAttributes = Object.assign({
|
||||
clipping: {
|
||||
diff: arrayDiffer
|
||||
}
|
||||
}, NodeAttributes);
|
||||
|
||||
var RenderableAttributes = Object.assign({
|
||||
fill: {
|
||||
diff: arrayDiffer
|
||||
},
|
||||
stroke: {
|
||||
diff: arrayDiffer
|
||||
},
|
||||
strokeWidth: true,
|
||||
strokeCap: true,
|
||||
strokeJoin: true,
|
||||
strokeDash: {
|
||||
diff: arrayDiffer
|
||||
}
|
||||
}, NodeAttributes);
|
||||
|
||||
var PathAttributes = Object.assign({
|
||||
d: {
|
||||
diff: arrayDiffer
|
||||
}
|
||||
}, RenderableAttributes);
|
||||
|
||||
var TextAttributes = Object.assign({
|
||||
alignment: true,
|
||||
frame: {
|
||||
diff: fontAndLinesDiffer
|
||||
},
|
||||
path: {
|
||||
diff: arrayDiffer
|
||||
}
|
||||
}, RenderableAttributes);
|
||||
|
||||
export {
|
||||
GroupAttributes,
|
||||
PathAttributes,
|
||||
TextAttributes
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user