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

Fix updating a view z-index on Android #15203

Closed

Conversation

janicduplessis
Copy link
Contributor

If the z-index was updated after the initial mount, changes would not be reflected because we did not recalculate the z-index mapped child views and redraw the view. This adds code to do that and call it whenever we update z-index.

Test plan
Tested by reproducing the bug with 2 overlapping views that change z-index every second. Made sure it now works properly and z-index changes are reflected.

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

pull-bot commented Jul 25, 2017

This PR has been submitted by a core contributor.

Generated by 🚫 dangerJS

@Noitidart
Copy link

Thank you sir! I will test this tonight! :)

@Noitidart
Copy link

Noitidart commented Jul 26, 2017

I never tested something like this, but I tried my hand. I saw the 4 files you changed, and made those files changes in my node_modules folder. Then I re-ran react-native run-android, however no change :(

It's a very simple repo, may you please try with this commit - https://github.com/Noitidart/Qaida-Board/tree/3ec2502c3682073fc43c8738a7849d09e867674f/App

I am using react native 0.46.1 + the edits I saw in your commit here.

@janicduplessis
Copy link
Contributor Author

Testing on Android is a bit more complex because you need to build the project from source, see http://facebook.github.io/react-native/docs/android-building-from-source.html.

@janicduplessis
Copy link
Contributor Author

I can test with the project you linked tomorrow if you don't get it working, I know building from source can be a pain :)

@Noitidart
Copy link

Oh thanks, I'll try this now and let you know how it goes. :)

@paranoidjk
Copy link

+1 for this

@Noitidart
Copy link

My sincerest apologies sir, @janicduplessis - I was not able to figure this testing process out. I'm feeling like a fool right now, it seems the instructions are very good, I just am screwing up somewhere. :(

@Noitidart
Copy link

Noitidart commented Jul 27, 2017

I did take a screencast of it being bad vs good though the other day. On Android it works like this for me:

https://youtu.be/2MNBLw382-0

But it should work like this:

Recording of iOS - https://youtu.be/3cwRMAnB45A
Recording of this on Windows (UWP) - https://youtu.be/0x-DUFVk5LA

* Redraw the view based on updated z-index. This should be called after updating one of it's child
* z-index.
*/
void updateZIndex();

Choose a reason for hiding this comment

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

I think that name of this method is a bit too short. Maybe updateViewParentZIndex() would be better as I suppose this method belongs to parent not child.

Copy link
Contributor Author

@janicduplessis janicduplessis Jul 27, 2017

Choose a reason for hiding this comment

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

Yea I had a hard time figuring out a name. updateViewParentZIndex would not work in this case because it doesn't update the parent, it redraws the view based on the updated z-index of its children.

@@ -12,4 +12,10 @@
* @return The child view index considering z-index
*/
int getZIndexMappedChildIndex(int index);

/**
* Redraw the view based on updated z-index. This should be called after updating one of it's child
Copy link
Contributor

Choose a reason for hiding this comment

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

"it's child z-index" -> "its child z-indexes"

@hramos
Copy link
Contributor

hramos commented Aug 3, 2017

Passing on to Andrew Chen for review.

@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 4, 2017
@facebook-github-bot
Copy link
Contributor

@achen1 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@Noitidart
Copy link

@janicduplessis were you able to test with the demo commit I gave? I am very eager to hear if that fixed it please sir. I don't think there is an error on my side because it worked as expected on iOS and even Windows (UWP).

@facebook-github-bot
Copy link
Contributor

@achen1 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@rtman
Copy link

rtman commented Aug 18, 2017

@janicduplessis curious how this is going? Doesn't seem resolved yet?

@hramos
Copy link
Contributor

hramos commented Aug 18, 2017

@rtman this PR has been merged and the fix should be on master. Please confirm that you're not seeing this resolved on master.

ide pushed a commit that referenced this pull request Aug 18, 2017
Summary:
If the z-index was updated after the initial mount, changes would not be reflected because we did not recalculate the z-index mapped child views and redraw the view. This adds code to do that and call it whenever we update z-index.

**Test plan**
Tested by reproducing the bug with 2 overlapping views that change z-index every second. Made sure it now works properly and z-index changes are reflected.
Closes #15203

Differential Revision: D5564832

Pulled By: achen1

fbshipit-source-id: 5b6c20147211ce0b7e8954d60f8614eafe128fb4
@Noitidart
Copy link

Thanks @hramos is there some steps for novices to follow? I followed the previous guide and failed miserably.

@ide
Copy link
Contributor

ide commented Aug 18, 2017

I cherry picked this into 0.48 as well. It should be easier to test that way. When 0.48-rc.2 gets published (no ETA though) it will include this change.

@rtman
Copy link

rtman commented Aug 19, 2017

@hramos Sorry what version of react-native is this included in?

Sent from my Google Nexus 5 using FastHub

@rtman
Copy link

rtman commented Aug 22, 2017

@hramos Oh i understand now, this is in the current master right? I will try this sometime soon and see if it works.

@ide 0.48-rc.2 is the earliest version that contains this fix?

@ide
Copy link
Contributor

ide commented Aug 22, 2017

@rtman, this is not in 0.48-rc.1 but if rc.2 is published it will be there.

@rtman
Copy link

rtman commented Aug 24, 2017

@ide ok thanks!

@Noitidart
Copy link

Noitidart commented Oct 17, 2017

Just tested out0.49 with my zIndex example above and it works, yahoo! Thanks!

I had an animated view, the animation was janky but this might be because it was not a production build and I had console.log's.

@rtman
Copy link

rtman commented Oct 17, 2017

Yea it works for me on 0.49.3!

Sent from my Google Nexus 5 using FastHub

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Import Started This pull request has been imported. This does not imply the PR has been approved.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants