Skip to content
Permalink
Browse files

Make perspective transformation look exactly same on iOS and Android (#…

…18302)

Summary:
There is a variation in iOS and Android output while performing perspective transformation. The variation exists even when used in Android devices with different screen density.
Pull Request resolved: #18302

Differential Revision: D13877483

Pulled By: cpojer

fbshipit-source-id: e48be047a8047c7562722923a67666cb098243d8
  • Loading branch information...
syaau authored and facebook-github-bot committed Jan 30, 2019
1 parent 7bb7f01 commit 4c10f9321c9d01dbcac4808e7e6674cba12f3aa5
Showing with 7 additions and 3 deletions.
  1. +7 −3 ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java
@@ -44,7 +44,7 @@
private static final String PROP_TRANSLATE_Y = "translateY";

private static final int PERSPECTIVE_ARRAY_INVERTED_CAMERA_DISTANCE_INDEX = 2;
private static final float CAMERA_DISTANCE_NORMALIZATION_MULTIPLIER = 5;
private static final float CAMERA_DISTANCE_NORMALIZATION_MULTIPLIER = (float)Math.sqrt(5);

/**
* Used to locate views in end-to-end (UI) tests.
@@ -234,8 +234,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);

}

0 comments on commit 4c10f93

Please sign in to comment.
You can’t perform that action at this time.