Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add backface-visibility support on Android #15970

Closed

Conversation

charpeni
Copy link
Contributor

@charpeni charpeni commented Sep 16, 2017

backfaceVisibility was only available on iOS and 3D transformations were lacking on Android.

Backface Visibility is computed from the decomposed matrix of transform prop the view with their rotation degree values.

MatrixDecompositionContext properties have been made public so we can access to decomposed matrix values from outside (ReactViewGroup).

I'm not sure if this is the best implementation, so if it's not let's discuss it.

cc @janicduplessis @foghina

Test Plan

Tested in https://github.com/charpeni/react-native-backface-visibility.

Before Now

RNTester

iOS Android

Release Notes

[ANDROID] [FEATURE] [ReactViewGroup] - Add backface-visibility support on Android

@facebook-github-bot facebook-github-bot added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Sep 16, 2017
@pull-bot
Copy link

@facebook-github-bot label Core Team

Generated by 🚫 dangerJS

@elicwhite
Copy link
Member

I could imagine this would be a good thing to have screenshot tests for on both ios and android to ensure it doesn't break in the future.

@chirag04
Copy link
Contributor

chirag04 commented Sep 22, 2017

i think there is an example for ios in RNTester. @charpeni would be nice to get that in for android too

setBackfaceVisibilityDependantOpacity();
}

public void decomposeMatrix(ReadableArray matrix) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we just use View#getRotationX and View#getRotationY instead of keeping our own transform info here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point!

float rotationX = (float) sMatrixDecompositionContext.rotationDegrees[0];
float rotationY = (float) sMatrixDecompositionContext.rotationDegrees[1];

boolean isFrontfaceVisible = (rotationX >= -90.f && rotationX < 90.f) &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could a negative scale affect the backface visibility?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Negative degrees are handled.

flipAnimation.interpolate({
  inputRange: [0, 180],
  outputRange: ['0deg', '180deg'],
});
flipAnimation.interpolate({
  inputRange: [0, 180],
  outputRange: ['0deg', '-180deg'],
});

@janicduplessis
Copy link
Contributor

Yea screenshot test for this would amazing

@facebook-github-bot
Copy link
Contributor

@charpeni I tried to find reviewers for this pull request and wanted to ping them to take another look. However, based on the blame information for the files in this pull request I couldn't find any reviewers. This sometimes happens when the files in the pull request are new or don't exist on master anymore. Is this pull request still relevant? If yes could you please rebase? In case you know who has context on this code feel free to mention them in a comment (one person is fine). Thanks for reading and hope you will continue contributing to the project.

@stale
Copy link

stale bot commented Dec 21, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Dec 21, 2017
@charpeni
Copy link
Contributor Author

I'll do the requested changes.

@stale stale bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Dec 21, 2017
@charpeni charpeni added Android and removed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Jan 10, 2018
@sdwilsh sdwilsh removed the cla signed label Mar 1, 2018
@charpeni charpeni force-pushed the android-backface-visibility branch from 25a89c9 to 54709a4 Compare March 2, 2018 22:06
@charpeni
Copy link
Contributor Author

charpeni commented Mar 5, 2018

@chirag04 The example was already there for both platforms, I've updated the PR with RNTester screenshots.

@TheSavior @janicduplessis I can find snapshot tests, but I can't find anything related to screenshot tests, is this setup internally?

@elicwhite
Copy link
Member

I think this link might be the right thing: https://facebook.github.io/react-native/docs/testing.html#screenshot-snapshot-tests

@charpeni
Copy link
Contributor Author

charpeni commented Mar 5, 2018

Oh I see, they're the same/bundle that's why screenshots were referring to snapshots. Thanks Eli!

@bduyng
Copy link

bduyng commented Mar 14, 2018

any update on this issue?

@react-native-bot react-native-bot added Android Ran Commands One of our bots successfully processed a command. labels Mar 16, 2018
@pkozhin
Copy link

pkozhin commented Jul 30, 2018

Please, would be awesome to get backfaceVisibility working on Android.
Any updates on review of the last changes?

@elicwhite
Copy link
Member

It looks like the added screenshots include a screenshot for front, but not for back. Support for the back surface is the main thing being added in this diff, right? We should probably have a screenshot for that.

@charpeni
Copy link
Contributor Author

charpeni commented Aug 1, 2018

Actually, the initial issue with backface visibility is that the second view (back) was always drawn on the first view (front). So, the front view was showing the backface with a rotation as shown here:

So, if we can see the front view, it means the backface visibility should work or you don't have a backface.

Anyway, just to be sure have add both cases in RNTester, updated screenshots, and rebase on master.

@facebook-github-bot facebook-github-bot added the Import Started This pull request has been imported. This does not imply the PR has been approved. label Aug 20, 2018
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hramos is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@hramos
Copy link
Contributor

hramos commented Aug 23, 2018

error: undefined reference to 'folly::makeConversionError(folly::ConversionCode, folly::Range<char const*>)'

 ** Summary of failures encountered during the build **
Rule __REDACTED__ FAILED because Command failed with exit code 1.
stderr: __REDACTED__/folly/Conv.h:1515: error: undefined reference to 'folly::makeConversionError(folly::ConversionCode, folly::Range<char const*>)'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

@charpeni charpeni force-pushed the android-backface-visibility branch from 5bbb738 to 526f509 Compare August 24, 2018 19:53
@charpeni
Copy link
Contributor Author

Where did you get this error @hramos?

I'm not sure this is directly related to these changes, I've rebased on a working RNTester commit (e2f2e41) and I can't reproduce any Folly errors.

@jsoendermann
Copy link
Contributor

@hramos Any chance you can take another look at this? Much appreciated!

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hramos is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@react-native-bot
Copy link
Collaborator

@charpeni merged commit 0cce0a6 into facebook:master.


Once this commit is added to a release, you will see the corresponding version tag below the description at 0cce0a6. If the commit has a single master tag, it is not yet part of a release.

@facebook facebook locked as resolved and limited conversation to collaborators Sep 7, 2018
@react-native-bot react-native-bot added the Merged This PR has been merged. label Sep 7, 2018
gengjiawen pushed a commit to gengjiawen/react-native that referenced this pull request Sep 14, 2018
Summary:
`backfaceVisibility` was only available on iOS and 3D transformations were lacking on Android.

Backface Visibility is computed from ~the decomposed matrix of transform prop~ the view with their rotation degree values.

~`MatrixDecompositionContext` properties have been made public so we can access to decomposed matrix values from outside (`ReactViewGroup`).~

I'm not sure if this is the best implementation, so if it's not let's discuss it.

cc janicduplessis foghina

Tested in https://github.com/charpeni/react-native-backface-visibility.

| Before | Now |
| - | - |
| <img src="https://user-images.githubusercontent.com/7189823/30123717-e5361598-9300-11e7-8e2e-a87a7a8d896a.gif" width="260" /> | <img src="https://user-images.githubusercontent.com/7189823/30514997-4d203572-9aee-11e7-8542-bfde41678eb6.gif" width="244" /> |

| iOS | Android |
| - | - |
| <img src="https://user-images.githubusercontent.com/7189823/36995899-609513b4-2083-11e8-9834-ee44c1a292e1.gif" width="300" /> | <img src="https://user-images.githubusercontent.com/7189823/36995978-9ed3b158-2083-11e8-841e-b9e3357d2509.gif" width="240" /> |

[ANDROID] [FEATURE] [ReactViewGroup] - Add backface-visibility support on Android
Pull Request resolved: facebook#15970

Differential Revision: D9411130

Pulled By: hramos

fbshipit-source-id: 62f646a4de37d83922286cb98893a95b55fa889e
@charpeni charpeni deleted the android-backface-visibility branch October 5, 2018 16:52
@hramos hramos removed Import Started This pull request has been imported. This does not imply the PR has been approved. labels Feb 6, 2019
sunnylqm pushed a commit to sunnylqm/react-native that referenced this pull request Feb 17, 2019
Summary:
`backfaceVisibility` was only available on iOS and 3D transformations were lacking on Android.

Backface Visibility is computed from ~the decomposed matrix of transform prop~ the view with their rotation degree values.

~`MatrixDecompositionContext` properties have been made public so we can access to decomposed matrix values from outside (`ReactViewGroup`).~

I'm not sure if this is the best implementation, so if it's not let's discuss it.

cc janicduplessis foghina

Tested in https://github.com/charpeni/react-native-backface-visibility.

| Before | Now |
| - | - |
| <img src="https://user-images.githubusercontent.com/7189823/30123717-e5361598-9300-11e7-8e2e-a87a7a8d896a.gif" width="260" /> | <img src="https://user-images.githubusercontent.com/7189823/30514997-4d203572-9aee-11e7-8542-bfde41678eb6.gif" width="244" /> |

| iOS | Android |
| - | - |
| <img src="https://user-images.githubusercontent.com/7189823/36995899-609513b4-2083-11e8-9834-ee44c1a292e1.gif" width="300" /> | <img src="https://user-images.githubusercontent.com/7189823/36995978-9ed3b158-2083-11e8-841e-b9e3357d2509.gif" width="240" /> |

[ANDROID] [FEATURE] [ReactViewGroup] - Add backface-visibility support on Android
Pull Request resolved: facebook#15970

Differential Revision: D9411130

Pulled By: hramos

fbshipit-source-id: 62f646a4de37d83922286cb98893a95b55fa889e
rozele pushed a commit to microsoft/react-native-windows that referenced this pull request Apr 14, 2019
Summary:
`backfaceVisibility` was only available on iOS and 3D transformations were lacking on Android.

Backface Visibility is computed from ~the decomposed matrix of transform prop~ the view with their rotation degree values.

~`MatrixDecompositionContext` properties have been made public so we can access to decomposed matrix values from outside (`ReactViewGroup`).~

I'm not sure if this is the best implementation, so if it's not let's discuss it.

cc janicduplessis foghina

Tested in https://github.com/charpeni/react-native-backface-visibility.

| Before | Now |
| - | - |
| <img src="https://user-images.githubusercontent.com/7189823/30123717-e5361598-9300-11e7-8e2e-a87a7a8d896a.gif" width="260" /> | <img src="https://user-images.githubusercontent.com/7189823/30514997-4d203572-9aee-11e7-8542-bfde41678eb6.gif" width="244" /> |

| iOS | Android |
| - | - |
| <img src="https://user-images.githubusercontent.com/7189823/36995899-609513b4-2083-11e8-9834-ee44c1a292e1.gif" width="300" /> | <img src="https://user-images.githubusercontent.com/7189823/36995978-9ed3b158-2083-11e8-841e-b9e3357d2509.gif" width="240" /> |

[ANDROID] [FEATURE] [ReactViewGroup] - Add backface-visibility support on Android
Pull Request resolved: facebook/react-native#15970

Differential Revision: D9411130

Pulled By: hramos

fbshipit-source-id: 62f646a4de37d83922286cb98893a95b55fa889e
t-nanava pushed a commit to microsoft/react-native-macos that referenced this pull request Jun 17, 2019
Summary:
`backfaceVisibility` was only available on iOS and 3D transformations were lacking on Android.

Backface Visibility is computed from ~the decomposed matrix of transform prop~ the view with their rotation degree values.

~`MatrixDecompositionContext` properties have been made public so we can access to decomposed matrix values from outside (`ReactViewGroup`).~

I'm not sure if this is the best implementation, so if it's not let's discuss it.

cc janicduplessis foghina

Tested in https://github.com/charpeni/react-native-backface-visibility.

| Before | Now |
| - | - |
| <img src="https://user-images.githubusercontent.com/7189823/30123717-e5361598-9300-11e7-8e2e-a87a7a8d896a.gif" width="260" /> | <img src="https://user-images.githubusercontent.com/7189823/30514997-4d203572-9aee-11e7-8542-bfde41678eb6.gif" width="244" /> |

| iOS | Android |
| - | - |
| <img src="https://user-images.githubusercontent.com/7189823/36995899-609513b4-2083-11e8-9834-ee44c1a292e1.gif" width="300" /> | <img src="https://user-images.githubusercontent.com/7189823/36995978-9ed3b158-2083-11e8-841e-b9e3357d2509.gif" width="240" /> |

[ANDROID] [FEATURE] [ReactViewGroup] - Add backface-visibility support on Android
Pull Request resolved: facebook#15970

Differential Revision: D9411130

Pulled By: hramos

fbshipit-source-id: 62f646a4de37d83922286cb98893a95b55fa889e
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Merged This PR has been merged. Platform: Android Android applications. Ran Commands One of our bots successfully processed a command.
Projects
None yet
Development

Successfully merging this pull request may close these issues.