Skip to content

Commit

Permalink
Implement support for animation of transform and some text properties
Browse files Browse the repository at this point in the history
  • Loading branch information
msand committed Oct 11, 2018
1 parent b568a63 commit 2a43579
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,9 @@ public int hitTest(final float[] src) {
if (mRegion == null && mFillPath != null) {
mRegion = getRegion(mFillPath);
}
if (mRegion == null && mPath != null) {
mRegion = getRegion(mPath);
}
if (mStrokeRegion == null && mStrokePath != null) {
mStrokeRegion = getRegion(mStrokePath);
}
Expand Down
9 changes: 7 additions & 2 deletions elements/G.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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() {
Expand Down
33 changes: 12 additions & 21 deletions elements/TSpan.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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() {
Expand Down
33 changes: 12 additions & 21 deletions elements/Text.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,29 @@
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 {
static displayName = "Text";

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() {
Expand Down

0 comments on commit 2a43579

Please sign in to comment.