Skip to content

Commit

Permalink
Support native animation of fill and stroke
Browse files Browse the repository at this point in the history
  • Loading branch information
msand committed Aug 17, 2018
1 parent 0eb501d commit 3879c90
Show file tree
Hide file tree
Showing 4 changed files with 258 additions and 206 deletions.
39 changes: 35 additions & 4 deletions android/src/main/java/com/horcrux/svg/RenderableShadowNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@
import android.graphics.Region;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Dynamic;
import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
import com.facebook.react.bridge.JavaOnlyArray;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.ReadableType;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.uimanager.annotations.ReactProp;

Expand Down Expand Up @@ -70,9 +74,24 @@ abstract public class RenderableShadowNode extends VirtualNode {
protected @Nullable ReadableArray mPropList;
protected @Nullable WritableArray mAttributeList;

static final Pattern regex = Pattern.compile("[0-9.-]+");

@ReactProp(name = "fill")
public void setFill(@Nullable ReadableArray fill) {
mFill = fill;
public void setFill(@Nullable Dynamic fill) {
ReadableType type = fill.getType();
if (type.equals(ReadableType.Array)) {
mFill = fill.asArray();
} else {
JavaOnlyArray arr = new JavaOnlyArray();
arr.pushInt(0);
Matcher m = regex.matcher(fill.asString());
int i = 0;
while (m.find()) {
Double parsed = Double.parseDouble(m.group());
arr.pushDouble(i++ < 3 ? parsed / 255 : parsed);
}
mFill = arr;
}
markUpdated();
}

Expand All @@ -99,8 +118,20 @@ public void setFillRule(int fillRule) {
}

@ReactProp(name = "stroke")
public void setStroke(@Nullable ReadableArray strokeColors) {
mStroke = strokeColors;
public void setStroke(@Nullable Dynamic strokeColors) {
ReadableType type = strokeColors.getType();
if (type.equals(ReadableType.Array)) {
mStroke = strokeColors.asArray();
} else {
JavaOnlyArray arr = new JavaOnlyArray();
arr.pushInt(0);
Matcher m = regex.matcher(strokeColors.asString());
while (m.find()) {
Double parsed = Double.parseDouble(m.group());
arr.pushDouble(parsed);
}
mStroke = arr;
}
markUpdated();
}

Expand Down
8 changes: 4 additions & 4 deletions android/src/main/java/com/horcrux/svg/RenderableView.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@

import com.facebook.react.bridge.ReactContext;

public class RenderableView extends ViewGroup {
VirtualNode shadowNode;
public class RenderableView<T extends VirtualNode> extends ViewGroup {
public T shadowNode;

public RenderableView(ReactContext reactContext) {
super(reactContext);
}

VirtualNode getShadowNode() {
T getShadowNode() {
return shadowNode;
}

@Override
public void setId(int id) {
super.setId(id);
shadowNode = RenderableViewManager.getShadowNodeByTag(id);
shadowNode = (T) RenderableViewManager.getShadowNodeByTag(id);
}

void dropView() {
Expand Down
Loading

0 comments on commit 3879c90

Please sign in to comment.