From 3e760f48c5a28b592cb60c4060ca28a1574f6274 Mon Sep 17 00:00:00 2001 From: Kevin Stumpf Date: Tue, 15 Mar 2016 11:51:31 -0700 Subject: [PATCH] Android support for perspective transform Summary:- Motivation: ["Perspective" Transform](https://facebook.github.io/react-native/docs/transforms.html#proptypes) was so far supported only on iOS - Closes #2915 - Test Plan: I built a [react-native-flip-view](https://github.com/DispatcherInc/react-native-flip-view) and ensured that the same perspective transform results in the same camera perspective on both iOS and Android: ![image](https://cloud.githubusercontent.com/assets/7293984/13342624/6556cfe0-dbf8-11e5-8fb2-05554a5081b7.png) ![image](https://cloud.githubusercontent.com/assets/7293984/13342677/daf90560-dbf8-11e5-9941-2ae0f9f9d99b.png) Closes https://github.com/facebook/react-native/pull/6159 Differential Revision: D3053532 Pulled By: mkonicek fb-gh-sync-id: a39a9fbafe0fc7c648fdafc2eb69f651fe58d9fb shipit-source-id: a39a9fbafe0fc7c648fdafc2eb69f651fe58d9fb --- .../react/uimanager/BaseViewManager.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java index 9a697ce3a..12fbae977 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java @@ -6,8 +6,10 @@ import android.graphics.Color; import android.os.Build; import android.view.View; +import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableMap; import com.facebook.react.uimanager.annotations.ReactProp; +import com.facebook.react.uimanager.DisplayMetricsHolder; /** * Base class that should be suitable for the majority of subclasses of {@link ViewManager}. @@ -25,6 +27,7 @@ public abstract class BaseViewManager PERSPECTIVE_ARRAY_INVERTED_CAMERA_DISTANCE_INDEX) { + float cameraDistance = (float)(-1 / perspectiveArray.getDouble(PERSPECTIVE_ARRAY_INVERTED_CAMERA_DISTANCE_INDEX)); + 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; + + view.setCameraDistance(normalizedCameraDistance); + } + } } private static void resetTransformMatrix(View view) { @@ -175,4 +194,4 @@ public abstract class BaseViewManager