question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Snackbar] `isAnchorViewLayoutListenerEnabled` causes infinite layout loop

See original GitHub issue

Description: 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 requestLayouts 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:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
aleksandra-krzemiencommented, Nov 2, 2022

@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, first onGlobalLayout() may be called before Snackbar view is added to parent. Then in updateMargins(), as view.getParent() == null we get a hint Wait for addView() is done to update layout params, but if I understand correctly and the comment refers to addToTargetParent (which calls addView) then it is recalculateAndUpdateMargins() 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.

0reactions
drchencommented, Nov 7, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Auto Layout causes infinite layoutSubviews loop - ios
I'm really puzzled by this, when I use auto layout on a subview the layoutSubview method loops infinitely. ... And this causes an...
Read more >
[Snackbar] Infinite loop when presenting a snackbar #3194
Overview When presenting a snackbar on a non-MDCOverlayWindow, with a presentedViewController, the application is entering an infinite loop.
Read more >
iOS 10: infinite loop of UICollect… | Apple Developer Forums
I have a collection view with cell called "MyCell". Each MyCell contains a MyView, and MyView contains a MyLabel. 2 seconds after the...
Read more >
Snackbar - Android Developers
Having a CoordinatorLayout in your view hierarchy allows Snackbar to enable certain features, such as swipe-to-dismiss and automatically moving ...
Read more >
A layout feedback loop caused by safe area insets - Medium
It seems to be a UI issue in auto layout, where an infinite loop generated and UI got frozen. If you leave the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found