material-components-android icon indicating copy to clipboard operation
material-components-android copied to clipboard

[CollapsingToolbarLayout] Calculate texts positions only in onLayout()

Open pubiqq opened this issue 2 years ago • 4 comments

The PR removes the call to the updateTextBounds() method from onMeasure(). Also, the PR removes all hacks (meaning the forceRecalculate flag and passing fake view position parameters to updateTextBounds()) that were required only for updateTextBounds() to work in onMeasure(). As a nice side effect, it saves onMeasure() from expensive, pointless, and unnecessary calculations that the CollapsingTextHelper#recalculate() method does.

pubiqq avatar Aug 15 '22 08:08 pubiqq

Hi can you provide more information like why we need this change and what it is aiming to solve?

drchen avatar Aug 30 '22 15:08 drchen

In short, you can't "update text bounds" in the onMeasure() method, because you don't know the view position yet. Well, and trying to update text bounds in the onMeasure() method is logically incorrect, of course.

P.S. Added a little description to the PR.

pubiqq avatar Aug 30 '22 17:08 pubiqq

Hunter, can you help take a look?

drchen avatar Oct 17 '22 18:10 drchen

any news?

pubiqq avatar Nov 01 '22 17:11 pubiqq

Bump.

In addition to the above description, this PR also unlocks the ability to create other PRs that fix some cases of incorrect behavior of CollapsingToolbarLayout.

pubiqq avatar Mar 12 '24 19:03 pubiqq