[Snackbar] `isAnchorViewLayoutListenerEnabled` causes infinite layout loop
See original GitHub issueDescription: Setting isAnchorViewLayoutListenerEnabled
and triggering layout causes the global layout listener to update margins and request layout, triggering itself in an infinite loop
Expected behavior: There’s no infinite requestLayout
s happening when not needed
Source code: snackbar.isAnchorViewLayoutListenerEnabled = true
Minimal sample app repro: Please consider attaching a minimal sample app that reproduces the issue. This will help narrow down the conditions required for reproducing the issue, and it will speed up the bug fix process. You may attach a zip file of the sample app or link to a GitHub repo that contains the sample app.
Here’s the video showing infinite layout loop. This is only the case when isAnchorViewLayoutListenerEnabled
is set to true
https://user-images.githubusercontent.com/3951580/172944673-4c62a376-243e-4b0c-ac79-4fe8a9a76db4.mov
Android API version: 28
Material Library version: 1.4.0
Device: emulator
To help us triage faster, please check to make sure you are using the latest version of the library.
We also happily accept pull requests.
Issue Analytics
- State:
- Created a year ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
@drchen I don’t think that this change solves the issue. Or rather it seems to be introducing a new one.
When using
isAnchorViewLayoutListenerEnabled = true
, firstonGlobalLayout()
may be called before Snackbar view is added to parent. Then inupdateMargins()
, asview.getParent() == null
we get a hintWait for addView() is done to update layout params
, but if I understand correctly and the comment refers toaddToTargetParent
(which callsaddView
) then it isrecalculateAndUpdateMargins()
which is called next, and as the bottomMargin didn’t change,updateMargins()
will not be called any more.This way the margin will never get updated.
Hi @aleksandra-krzemien,
Thanks for the report. Can you create a new issue and link this one there? I’m currently pretty occupied by some other stuff but let’s try to find someone who may be able to take a look.