Permalink
Browse files

Support native animation of fill and stroke

  • Loading branch information...
msand committed Aug 17, 2018
1 parent 0eb501d commit 3879c90bd8273ba8b38713b2f39d2bdfd5265665
@@ -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;
@@ -70,9 +74,24 @@
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();
}
@@ -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();
}
@@ -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() {
Oops, something went wrong.

0 comments on commit 3879c90

Please sign in to comment.