Skip to content

[Android] Call handleUpdateLayout even if the content didn't change#11222

Closed
Kerumen wants to merge 1 commit into
react:masterfrom
Kerumen:master
Closed

[Android] Call handleUpdateLayout even if the content didn't change#11222
Kerumen wants to merge 1 commit into
react:masterfrom
Kerumen:master

Conversation

@Kerumen

@Kerumen Kerumen commented Nov 30, 2016

Copy link
Copy Markdown
Contributor

This PR fixes #11096.

I don't know enough the ReactAndroid's source code so I don't know if this is correct but I hope it is.

In a recent commit (d4b8ae7), the dispatchUpdates method now returns a boolean to dispatch or not the onLayout event. This works well but if the content is unchanged, the line nativeViewHierarchyOptimizer.handleUpdateLayout(this); is never called. I don't know if it was intended but it was this which introduces my issue. I called this again even if the content didn't change. This was the behaviour before 0.38 so I guess I didn't break anything.

Test plan (required)

I tested my pretty big app with this fix and every screen is ok.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

By analyzing the blame information on this pull request, we identified @astreet and @emilsjolander to be potential reviewers.

@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 Nov 30, 2016
@astreet

astreet commented Nov 30, 2016

Copy link
Copy Markdown
Contributor

Why do we need to dispatch handleUpdateLayout when the layout hasn't changed? As in, what did it break for you? I have a feeling there's a better fix we can do.

@Kerumen

Kerumen commented Nov 30, 2016

Copy link
Copy Markdown
Contributor Author

I invite you to have a look at the issue I linked (#11096). I explain what worked before and broke (basically a height change that moves my button). And I created a GitHub repo with my bug.

I don't doubt there is a better fix, I'm not an expert in the React Native's java source code.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the repro: I just looked through the code here and this check is just not correct. It should all be handled by hasNewLayout above. As such, the correct fix is to just combine lines 301-304 into lines 289-292 and delete this entire if-block.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Noted! I updated the PR :)

@astreet

astreet commented Nov 30, 2016

Copy link
Copy Markdown
Contributor

Awesome, thanks!

@facebook-github-bot

Copy link
Copy Markdown
Contributor

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

@fred2028

fred2028 commented Dec 1, 2016

Copy link
Copy Markdown
Contributor

Thanks! This fixes something I was investigating

grabbou pushed a commit that referenced this pull request Dec 2, 2016
Summary:
This PR fixes #11096.

I don't know enough the ReactAndroid's source code so I don't know if this is correct but I hope it is.

In a recent commit (d4b8ae7), the `dispatchUpdates` method now returns a boolean to dispatch or not the `onLayout` event. This works well but if the content is unchanged, the line `nativeViewHierarchyOptimizer.handleUpdateLayout(this);` is never called. I don't know if it was intended but it was this which introduces my issue. I called this again even if the content didn't change. This was the behaviour before 0.38 so I guess I didn't break anything.

**Test plan (required)**

I tested my pretty big app with this fix and every screen is ok.
Closes #11222

Differential Revision: D4252101

Pulled By: astreet

fbshipit-source-id: 551559234631ac37245a854d81ba568f0ddb02dd
mkonicek referenced this pull request Dec 5, 2016
Summary:
Fixes [#7202 Android Redundant onLayout event](#7202)
Closes #7250

Differential Revision: D4104066

Pulled By: mkonicek

fbshipit-source-id: 383efdb4b4881aa7d7e508d61c9c01165bcf7bb6
@mkonicek

mkonicek commented Dec 5, 2016

Copy link
Copy Markdown
Contributor

Thanks for the fix! The bug affected RN versions 0.38 and 0.39.

Your fix fb23000 will be part of the 0.40 release, and was cherry picked into 0.39, and I just now cherry-picked it into 0.38 too for people who are choosing to use 0.38 over 0.39.

mkonicek pushed a commit that referenced this pull request Dec 5, 2016
Summary:
This PR fixes #11096.

I don't know enough the ReactAndroid's source code so I don't know if this is correct but I hope it is.

In a recent commit (d4b8ae7), the `dispatchUpdates` method now returns a boolean to dispatch or not the `onLayout` event. This works well but if the content is unchanged, the line `nativeViewHierarchyOptimizer.handleUpdateLayout(this);` is never called. I don't know if it was intended but it was this which introduces my issue. I called this again even if the content didn't change. This was the behaviour before 0.38 so I guess I didn't break anything.

**Test plan (required)**

I tested my pretty big app with this fix and every screen is ok.
Closes #11222

Differential Revision: D4252101

Pulled By: astreet

fbshipit-source-id: 551559234631ac37245a854d81ba568f0ddb02dd
@mschipperheyn

Copy link
Copy Markdown

I'm having a number of issues that seem to be related to this commit. Please reference the discussion here: #11441

@ramilushev

ramilushev commented Jan 12, 2017

Copy link
Copy Markdown

I am also having an issue. See here: #11809

@astreet

astreet commented Jan 24, 2017

Copy link
Copy Markdown
Contributor

I'm having a number of issues that seem to be related to this commit. Please reference the discussion here: #11441

That problem seems to have been on iOS, this is an Android-only change.

@sahrens

sahrens commented Jan 24, 2017

Copy link
Copy Markdown
Contributor

Did you experiment with calling nativeViewHierarchyOptimizer.handleUpdateLayout(this); just as often, but returning false if the layout coordinates didn't change? I think that could provide the onLayout optimization we want, but hopefully without breaking anything like the original diff did.

@sahrens

sahrens commented Jan 24, 2017

Copy link
Copy Markdown
Contributor

I'm putting up a diff internally that filters out redundant onLayout calls without affecting handleUpdateLayout so hopefully that will get us some solid perf wins without breaking anything :)

@ramilushev

Copy link
Copy Markdown

@sahrens Did that internal diff make it to production?

@mkonicek

mkonicek commented Feb 22, 2017

Copy link
Copy Markdown
Contributor

@ramilushev Not yet but @astreet picked up the work and the diff should be in master soon.

facebook-github-bot pushed a commit that referenced this pull request Feb 22, 2017
Summary:
Developers are complaining about horrible lag (#11809) caused by PR #11222.

The issue was that hasNewLayout in yoga is actually a dirty bit and indicates that either you OR one of your children has a new layout. We still need to manually check whether the component's layout actually is different from before.

Reviewed By: sahrens

Differential Revision: D4597545

fbshipit-source-id: 27d4605afd00badfdcdacae740ee2e477adee929
ming436534 pushed a commit to ming436534/react-native that referenced this pull request Feb 23, 2017
Summary:
Developers are complaining about horrible lag (react#11809) caused by PR react#11222.

The issue was that hasNewLayout in yoga is actually a dirty bit and indicates that either you OR one of your children has a new layout. We still need to manually check whether the component's layout actually is different from before.

Reviewed By: sahrens

Differential Revision: D4597545

fbshipit-source-id: 27d4605afd00badfdcdacae740ee2e477adee929
lelandrichardson pushed a commit to airbnb/react-native that referenced this pull request Mar 24, 2017
Summary:
Developers are complaining about horrible lag (react#11809) caused by PR react#11222.

The issue was that hasNewLayout in yoga is actually a dirty bit and indicates that either you OR one of your children has a new layout. We still need to manually check whether the component's layout actually is different from before.

Reviewed By: sahrens

Differential Revision: D4597545

fbshipit-source-id: 27d4605afd00badfdcdacae740ee2e477adee929
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android] [0.38] Position bug when the content change

8 participants