Skip to content

Commit

Permalink
Ignore non-array transforms, align transform handling with react-native
Browse files Browse the repository at this point in the history
  • Loading branch information
msand committed Feb 27, 2019
1 parent 0b1f536 commit 0a282f1
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions android/src/main/java/com/horcrux/svg/RenderableViewManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.facebook.react.bridge.JavaOnlyMap;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.ReadableType;
import com.facebook.react.uimanager.DisplayMetricsHolder;
import com.facebook.react.uimanager.LayoutShadowNode;
import com.facebook.react.uimanager.MatrixMathHelper;
Expand Down Expand Up @@ -315,8 +316,12 @@ private static void setTransformProperty(View view, ReadableArray transforms) {
float scale = DisplayMetricsHolder.getScreenDisplayMetrics().density;

// The following converts the matrix's perspective to a camera distance
// such that the camera perspective looks the same on Android and iOS
float normalizedCameraDistance = scale * cameraDistance * CAMERA_DISTANCE_NORMALIZATION_MULTIPLIER;
// such that the camera perspective looks the same on Android and iOS.
// The native Android implementation removed the screen density from the
// calculation, so squaring and a normalization value of
// sqrt(5) produces an exact replica with iOS.
// For more information, see https://github.com/facebook/react-native/pull/18302
float normalizedCameraDistance = scale * scale * cameraDistance * CAMERA_DISTANCE_NORMALIZATION_MULTIPLIER;
view.setCameraDistance(normalizedCameraDistance);

}
Expand Down Expand Up @@ -1014,11 +1019,15 @@ public void setMatrix(VirtualView node, Dynamic matrixArray) {
}

@ReactProp(name = "transform")
public void setTransform(VirtualView node, ReadableArray matrix) {
if (matrix == null) {
public void setTransform(VirtualView node, Dynamic matrix) {
if (matrix.getType() != ReadableType.Array) {
return;
}
ReadableArray ma = matrix.asArray();
if (ma == null) {
resetTransformProperty(node);
} else {
setTransformProperty(node, matrix);
setTransformProperty(node, ma);
}
Matrix m = node.getMatrix();
node.mTransform = m;
Expand Down

0 comments on commit 0a282f1

Please sign in to comment.