diff --git a/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testViewExample_1-iOS10@2x.png b/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testViewExample_1-iOS10@2x.png index 1904eb149..ec70fd4d4 100644 Binary files a/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testViewExample_1-iOS10@2x.png and b/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testViewExample_1-iOS10@2x.png differ diff --git a/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testViewExample_1-iOS11@2x.png b/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testViewExample_1-iOS11@2x.png index 20a2e6193..0144c9611 100644 Binary files a/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testViewExample_1-iOS11@2x.png and b/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testViewExample_1-iOS11@2x.png differ diff --git a/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testViewExample_1@2x.png b/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testViewExample_1@2x.png index fcaf5fb30..0d4521449 100644 Binary files a/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testViewExample_1@2x.png and b/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testViewExample_1@2x.png differ diff --git a/RNTester/js/ViewExample.js b/RNTester/js/ViewExample.js index 89419b22a..af115bec8 100644 --- a/RNTester/js/ViewExample.js +++ b/RNTester/js/ViewExample.js @@ -311,4 +311,72 @@ exports.examples = [ return ; }, }, + { + title: 'BackfaceVisibility', + render: function() { + return ( + <> + + View #1, front is visible, back is hidden. + + + + Front + + + Back (You should not see this) + + + + View #2, front is hidden, back is visible. + + + + Front (You should not see this) + + + Back + + + + ); + }, + }, ]; diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.java b/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.java index ce2fa9528..5b357f8ef 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.java @@ -110,6 +110,8 @@ public class ReactViewGroup extends ViewGroup implements private final ViewGroupDrawingOrderHelper mDrawingOrderHelper; private @Nullable Path mPath; private int mLayoutDirection; + private float mBackfaceOpacity = 1.f; + private String mBackfaceVisibility = "visible"; public ReactViewGroup(Context context) { super(context); @@ -836,4 +838,36 @@ public class ReactViewGroup extends ViewGroup implements } } } + + public void setOpacityIfPossible(float opacity) { + mBackfaceOpacity = opacity; + setBackfaceVisibilityDependantOpacity(); + } + + public void setBackfaceVisibility(String backfaceVisibility) { + mBackfaceVisibility = backfaceVisibility; + setBackfaceVisibilityDependantOpacity(); + } + + public void setBackfaceVisibilityDependantOpacity() { + boolean isBackfaceVisible = mBackfaceVisibility.equals("visible"); + + if (isBackfaceVisible) { + setAlpha(mBackfaceOpacity); + return; + } + + float rotationX = getRotationX(); + float rotationY = getRotationY(); + + boolean isFrontfaceVisible = (rotationX >= -90.f && rotationX < 90.f) && + (rotationY >= -90.f && rotationY < 90.f); + + if (isFrontfaceVisible) { + setAlpha(mBackfaceOpacity); + return; + } + + setAlpha(0); + } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewManager.java index b4eb58704..289539c15 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewManager.java @@ -203,6 +203,22 @@ public class ReactViewManager extends ViewGroupManager { view.setOverflow(overflow); } + @ReactProp(name = "backfaceVisibility") + public void setBackfaceVisibility(ReactViewGroup view, String backfaceVisibility) { + view.setBackfaceVisibility(backfaceVisibility); + } + + @Override + public void setOpacity(ReactViewGroup view, float opacity) { + view.setOpacityIfPossible(opacity); + } + + @Override + public void setTransform(ReactViewGroup view, ReadableArray matrix) { + super.setTransform(view, matrix); + view.setBackfaceVisibilityDependantOpacity(); + } + @Override public String getName() { return REACT_CLASS;