Skip to content

Commit

Permalink
change package names
Browse files Browse the repository at this point in the history
  • Loading branch information
magicismight committed Apr 20, 2016
1 parent 7c288b0 commit 677bbbe
Show file tree
Hide file tree
Showing 13 changed files with 677 additions and 88 deletions.
9 changes: 7 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ android {
}

repositories {
mavenCentral()
mavenLocal()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$projectDir/../../node_modules/react-native/android"
}
}

dependencies {
compile 'com.facebook.react:react-native:0.24.+'
compile 'com.facebook.react:react-native:+'
}
22 changes: 0 additions & 22 deletions android/src/main/java/com/horcrux/svg/BUCK

This file was deleted.

55 changes: 27 additions & 28 deletions android/src/main/java/com/horcrux/svg/PropHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,42 @@
import javax.annotation.Nullable;

import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.uimanager.ReactStylesDiffMap;

/**
* Contains static helper methods for accessing props.
*/
/* package */ class PropHelper {

/**
* Converts {@link ReadableArray} to an array of {@code float}. Returns newly created array.
*
* @return a {@code float[]} if converted successfully, or {@code null} if {@param value} was
* {@code null}.
*/
/**
* Converts {@link ReadableArray} to an array of {@code float}. Returns newly created array.
*
* @return a {@code float[]} if converted successfully, or {@code null} if {@param value} was
* {@code null}.
*/
/*package*/ static @Nullable float[] toFloatArray(@Nullable ReadableArray value) {
if (value != null) {
float[] result = new float[value.size()];
toFloatArray(value, result);
return result;
if (value != null) {
float[] result = new float[value.size()];
toFloatArray(value, result);
return result;
}
return null;
}
return null;
}

/**
* Converts given {@link ReadableArray} to an array of {@code float}. Writes result to the array
* passed in {@param into}. This method will write to the output array up to the number of items
* from the input array. If the input array is longer than output the remaining part of the input
* will not be converted.
*
* @param value input array
* @param into output array
* @return number of items copied from input to the output array
*/
/**
* Converts given {@link ReadableArray} to an array of {@code float}. Writes result to the array
* passed in {@param into}. This method will write to the output array up to the number of items
* from the input array. If the input array is longer than output the remaining part of the input
* will not be converted.
*
* @param value input array
* @param into output array
* @return number of items copied from input to the output array
*/
/*package*/ static int toFloatArray(ReadableArray value, float[] into) {
int length = value.size() > into.length ? into.length : value.size();
for (int i = 0; i < length; i++) {
into[i] = (float) value.getDouble(i);
int length = value.size() > into.length ? into.length : value.size();
for (int i = 0; i < length; i++) {
into[i] = (float) value.getDouble(i);
}
return value.size();
}
return value.size();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import com.facebook.react.uimanager.annotations.ReactProp;

/**
* Shadow node for virtual RNSVGShape view
* Shadow node for virtual RNSVGPath view
*/
public class RNSVGShapeShadowNode extends RNSVGVirtualNode {
public class RNSVGPathShadowNode extends RNSVGVirtualNode {

private static final int CAP_BUTT = 0;
private static final int CAP_ROUND = 1;
Expand All @@ -50,7 +50,7 @@ public class RNSVGShapeShadowNode extends RNSVGVirtualNode {
private int mStrokeJoin = JOIN_ROUND;

@ReactProp(name = "d")
public void setShapePath(@Nullable ReadableArray shapePath) {
public void setPath(@Nullable ReadableArray shapePath) {
float[] pathData = PropHelper.toFloatArray(shapePath);
mPath = createPath(pathData);
markUpdated();
Expand Down Expand Up @@ -99,7 +99,7 @@ public void draw(Canvas canvas, Paint paint, float opacity) {
saveAndSetupCanvas(canvas);
if (mPath == null) {
throw new JSApplicationIllegalArgumentException(
"Shapes should have a valid path (d) prop");
"Paths should have a valid path (d) prop");
}
if (setupStrokePaint(paint, opacity)) {
canvas.drawPath(mPath, paint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@

import android.view.View;

import com.facebook.react.uimanager.ReactStylesDiffMap;
//import com.facebook.react.uimanager.ReactStylesDiffMap;
import com.facebook.react.uimanager.ReactShadowNode;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.ViewManager;

/**
* ViewManager for all shadowed RNSVG views: Group, Shape and Text. Since these never get rendered
* into native views and don't need any logic (all the logic is in {@link RNSVGSurfaceView}), this
* ViewManager for all shadowed RNSVG views: Group, Path and Text. Since these never get rendered
* into native views and don't need any logic (all the logic is in {@link RNSVGSvgView}), this
* "stubbed" ViewManager is used for all of them.
*/
public class RNSVGRenderableViewManager extends ViewManager<View, ReactShadowNode> {

/* package */ static final String CLASS_GROUP = "RNSVGGroup";
/* package */ static final String CLASS_SHAPE = "RNSVGShape";
/* package */ static final String CLASS_SVG = "RNSVGPath";
/* package */ static final String CLASS_TEXT = "RNSVGText";

private final String mClassName;
Expand All @@ -33,8 +33,8 @@ public static RNSVGRenderableViewManager createRNSVGGroupViewManager() {
return new RNSVGRenderableViewManager(CLASS_GROUP);
}

public static RNSVGRenderableViewManager createRNSVGShapeViewManager() {
return new RNSVGRenderableViewManager(CLASS_SHAPE);
public static RNSVGRenderableViewManager createRNSVGPathViewManager() {
return new RNSVGRenderableViewManager(CLASS_SVG);
}

public static RNSVGRenderableViewManager createRNSVGTextViewManager() {
Expand All @@ -54,8 +54,8 @@ public String getName() {
public ReactShadowNode createShadowNodeInstance() {
if (mClassName == CLASS_GROUP) {
return new RNSVGGroupShadowNode();
} else if (mClassName == CLASS_SHAPE) {
return new RNSVGShapeShadowNode();
} else if (mClassName == CLASS_SVG) {
return new RNSVGPathShadowNode();
} else if (mClassName == CLASS_TEXT) {
return new RNSVGTextShadowNode();
} else {
Expand All @@ -67,8 +67,8 @@ public ReactShadowNode createShadowNodeInstance() {
public Class<? extends ReactShadowNode> getShadowNodeClass() {
if (mClassName == CLASS_GROUP) {
return RNSVGGroupShadowNode.class;
} else if (mClassName == CLASS_SHAPE) {
return RNSVGShapeShadowNode.class;
} else if (mClassName == CLASS_SVG) {
return RNSVGPathShadowNode.class;
} else if (mClassName == CLASS_TEXT) {
return RNSVGTextShadowNode.class;
} else {
Expand All @@ -78,11 +78,11 @@ public Class<? extends ReactShadowNode> getShadowNodeClass() {

@Override
protected View createViewInstance(ThemedReactContext reactContext) {
throw new IllegalStateException("RNSVGShape does not map into a native view");
throw new IllegalStateException("RNSVGPath does not map into a native view");
}

@Override
public void updateExtraData(View root, Object extraData) {
throw new IllegalStateException("RNSVGShape does not map into a native view");
throw new IllegalStateException("RNSVGPath does not map into a native view");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
import android.view.View;

/**
* Custom {@link View} implementation that draws an RNSVGSurface React view and its children.
* Custom {@link View} implementation that draws an RNSVGSvg React view and its children.
*/
public class RNSVGSurfaceView extends View {
public class RNSVGSvgView extends View {

private @Nullable Bitmap mBitmap;

public RNSVGSurfaceView(Context context) {
public RNSVGSvgView(Context context) {
super(context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
import com.facebook.react.uimanager.ThemedReactContext;

/**
* ViewManager for RNSVGSurfaceView React views. Renders as a {@link RNSVGSurfaceView} and handles
* ViewManager for RNSVGSvgView React views. Renders as a {@link RNSVGSvgView} and handles
* invalidating the native view on shadow view updates happening in the underlying tree.
*/
public class RNSVGSurfaceViewManager extends
BaseViewManager<RNSVGSurfaceView, RNSVGSurfaceViewShadowNode> {
public class RNSVGSvgViewManager extends
BaseViewManager<RNSVGSvgView, RNSVGSvgViewShadowNode> {

private static final String REACT_CLASS = "RNSVGSurfaceView";
private static final String REACT_CLASS = "RNSVGSvgView";

private static final CSSNode.MeasureFunction MEASURE_FUNCTION = new CSSNode.MeasureFunction() {
@Override
public void measure(CSSNode node, float width, float height, MeasureOutput measureOutput) {
throw new IllegalStateException("SurfaceView should have explicit width and height set");
throw new IllegalStateException("SvgView should have explicit width and height set");
}
};

Expand All @@ -38,24 +38,24 @@ public String getName() {
}

@Override
public RNSVGSurfaceViewShadowNode createShadowNodeInstance() {
RNSVGSurfaceViewShadowNode node = new RNSVGSurfaceViewShadowNode();
public RNSVGSvgViewShadowNode createShadowNodeInstance() {
RNSVGSvgViewShadowNode node = new RNSVGSvgViewShadowNode();
node.setMeasureFunction(MEASURE_FUNCTION);
return node;
}

@Override
public Class<RNSVGSurfaceViewShadowNode> getShadowNodeClass() {
return RNSVGSurfaceViewShadowNode.class;
public Class<RNSVGSvgViewShadowNode> getShadowNodeClass() {
return RNSVGSvgViewShadowNode.class;
}

@Override
protected RNSVGSurfaceView createViewInstance(ThemedReactContext reactContext) {
return new RNSVGSurfaceView(reactContext);
protected RNSVGSvgView createViewInstance(ThemedReactContext reactContext) {
return new RNSVGSvgView(reactContext);
}

@Override
public void updateExtraData(RNSVGSurfaceView root, Object extraData) {
public void updateExtraData(RNSVGSvgView root, Object extraData) {
root.setBitmap((Bitmap) extraData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import com.facebook.react.uimanager.UIViewOperationQueue;

/**
* Shadow node for RNSVG virtual tree root - RNSVGSurfaceView
* Shadow node for RNSVG virtual tree root - RNSVGSvgView
*/
public class RNSVGSurfaceViewShadowNode extends LayoutShadowNode {
public class RNSVGSvgViewShadowNode extends LayoutShadowNode {

@Override
public boolean isVirtual() {
Expand All @@ -38,7 +38,7 @@ public void onCollectExtraUpdates(UIViewOperationQueue uiUpdater) {
}

private Object drawOutput() {
// TODO(7255985): Use TextureView and pass Surface from the view to draw on it asynchronously
// TODO(7255985): Use TextureView and pass Svg from the view to draw on it asynchronously
// instead of passing the bitmap (which is inefficient especially in terms of memory usage)
Bitmap bitmap = Bitmap.createBitmap(
(int) getLayoutWidth(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* Shadow node for virtual RNSVGText view
*/
public class RNSVGTextShadowNode extends RNSVGShapeShadowNode {
public class RNSVGTextShadowNode extends RNSVGPathShadowNode {

private static final String PROP_LINES = "lines";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.facebook.react.uimanager.ReactShadowNode;

/**
* Base class for RNSVGView virtual nodes: {@link RNSVGGroupShadowNode}, {@link RNSVGShapeShadowNode} and
* Base class for RNSVGView virtual nodes: {@link RNSVGGroupShadowNode}, {@link RNSVGPathShadowNode} and
* indirectly for {@link RNSVGTextShadowNode}.
*/
public abstract class RNSVGVirtualNode extends ReactShadowNode {
Expand Down
38 changes: 38 additions & 0 deletions android/src/main/java/com/horcrux/svg/RNSvgPackage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.horcrux.svg;

import android.app.Activity;

import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;


public class RNSvgPackage implements ReactPackage {

@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Arrays.<ViewManager>asList(
RNSVGRenderableViewManager.createRNSVGGroupViewManager(),
RNSVGRenderableViewManager.createRNSVGPathViewManager(),
RNSVGRenderableViewManager.createRNSVGTextViewManager(),
new RNSVGSvgViewManager());
}

@Override
public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
}

@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
return Collections.emptyList();
}


}
Loading

0 comments on commit 677bbbe

Please sign in to comment.