From 2a43579404b35db6b6b9613c05076170e02203e3 Mon Sep 17 00:00:00 2001 From: Mikael Sand Date: Thu, 11 Oct 2018 03:31:47 +0300 Subject: [PATCH] Implement support for animation of transform and some text properties --- .../com/horcrux/svg/RenderableShadowNode.java | 3 ++ elements/G.js | 9 +++-- elements/TSpan.js | 33 +++++++------------ elements/Text.js | 33 +++++++------------ 4 files changed, 34 insertions(+), 44 deletions(-) diff --git a/android/src/main/java/com/horcrux/svg/RenderableShadowNode.java b/android/src/main/java/com/horcrux/svg/RenderableShadowNode.java index 7ac1f225..eaa7103d 100644 --- a/android/src/main/java/com/horcrux/svg/RenderableShadowNode.java +++ b/android/src/main/java/com/horcrux/svg/RenderableShadowNode.java @@ -426,6 +426,9 @@ abstract public class RenderableShadowNode extends VirtualNode { if (mRegion == null && mFillPath != null) { mRegion = getRegion(mFillPath); } + if (mRegion == null && mPath != null) { + mRegion = getRegion(mPath); + } if (mStrokeRegion == null && mStrokePath != null) { mStrokeRegion = getRegion(mStrokePath); } diff --git a/elements/G.js b/elements/G.js index 798929a8..b39a744f 100644 --- a/elements/G.js +++ b/elements/G.js @@ -5,6 +5,7 @@ import { pathProps, fontProps } from "../lib/props"; import { GroupAttributes } from "../lib/attributes"; import extractProps from "../lib/extract/extractProps"; import { extractFont } from "../lib/extract/extractText"; +import extractTransform from "../lib/extract/extractTransform"; export default class extends Shape { static displayName = "G"; @@ -14,8 +15,12 @@ export default class extends Shape { ...fontProps }; - setNativeProps = (...args) => { - this.root.setNativeProps(...args); + setNativeProps = (props) => { + const matrix = !props.matrix && extractTransform(props); + if (matrix) { + props.matrix = matrix; + } + this.root.setNativeProps(props); }; render() { diff --git a/elements/TSpan.js b/elements/TSpan.js index cf54ddbb..840622eb 100644 --- a/elements/TSpan.js +++ b/elements/TSpan.js @@ -1,10 +1,12 @@ import React from "react"; +import _ from "lodash"; import PropTypes from "prop-types"; import { requireNativeComponent } from "react-native"; import extractText from "../lib/extract/extractText"; import { textProps } from "../lib/props"; import { TSpanAttibutes } from "../lib/attributes"; import extractProps from "../lib/extract/extractProps"; +import extractTransform from "../lib/extract/extractTransform"; import Shape from "./Shape"; // TSpan elements are shadow components @@ -13,27 +15,16 @@ export default class extends Shape { static propTypes = textProps; - //noinspection JSUnusedGlobalSymbols - static childContextTypes = { - isInAParentText: PropTypes.bool - }; - - //noinspection JSUnusedGlobalSymbols - getChildContext() { - return { - isInAParentText: true - }; - } - - //noinspection JSUnusedGlobalSymbols - getContextTypes() { - return { - isInAParentText: PropTypes.bool - }; - } - - setNativeProps = (...args) => { - this.root.setNativeProps(...args); + setNativeProps = (props) => { + const matrix = !props.matrix && extractTransform(props); + if (matrix) { + props.matrix = matrix; + } + const textProps = _.pickBy(extractText(props, true), p => !_.isNil(p)); + this.root.setNativeProps({ + ...props, + ...textProps + }); }; render() { diff --git a/elements/Text.js b/elements/Text.js index ffe21c20..a5682a81 100644 --- a/elements/Text.js +++ b/elements/Text.js @@ -1,10 +1,12 @@ import React from "react"; +import _ from "lodash"; import PropTypes from "prop-types"; import { requireNativeComponent } from "react-native"; import extractText from "../lib/extract/extractText"; import { textProps } from "../lib/props"; import { TextAttributes } from "../lib/attributes"; import extractProps from "../lib/extract/extractProps"; +import extractTransform from "../lib/extract/extractTransform"; import Shape from "./Shape"; export default class extends Shape { @@ -12,27 +14,16 @@ export default class extends Shape { static propTypes = textProps; - //noinspection JSUnusedGlobalSymbols - static childContextTypes = { - isInAParentText: PropTypes.bool - }; - - //noinspection JSUnusedGlobalSymbols - getChildContext() { - return { - isInAParentText: true - }; - } - - //noinspection JSUnusedGlobalSymbols - getContextTypes() { - return { - isInAParentText: PropTypes.bool - }; - } - - setNativeProps = (...args) => { - this.root.setNativeProps(...args); + setNativeProps = (props) => { + const matrix = !props.matrix && extractTransform(props); + if (matrix) { + props.matrix = matrix; + } + const textProps = _.pickBy(extractText(props, true), p => !_.isNil(p)); + this.root.setNativeProps({ + ...props, + ...textProps + }); }; render() {