Skip to content

Commit 4c10f93

Browse files
syaaufacebook-github-bot
authored andcommittedJan 30, 2019
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
1 parent 7bb7f01 commit 4c10f93

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed
 

‎ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public abstract class BaseViewManager<T extends View, C extends LayoutShadowNode
4444
private static final String PROP_TRANSLATE_Y = "translateY";
4545

4646
private static final int PERSPECTIVE_ARRAY_INVERTED_CAMERA_DISTANCE_INDEX = 2;
47-
private static final float CAMERA_DISTANCE_NORMALIZATION_MULTIPLIER = 5;
47+
private static final float CAMERA_DISTANCE_NORMALIZATION_MULTIPLIER = (float)Math.sqrt(5);
4848

4949
/**
5050
* Used to locate views in end-to-end (UI) tests.
@@ -234,8 +234,12 @@ private static void setTransformProperty(View view, ReadableArray transforms) {
234234
float scale = DisplayMetricsHolder.getScreenDisplayMetrics().density;
235235

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

241245
}

0 commit comments

Comments
 (0)