Skip to content

Commit

Permalink
[SnackBar] Fix NPE on Android 8 & 9
Browse files Browse the repository at this point in the history
It seems like on Android 8 & 9 framework's View implementation has a bug that under certain scenarios if we set a view's visibility when view.getParent() is null, it can cause NPE crash.

Fixes this by switching the order of addView and setVisibility() call.

Resolves #917

PiperOrigin-RevId: 413978332
  • Loading branch information
drchen authored and josefigueroa168 committed Dec 6, 2021
1 parent fcc68a2 commit 35d9da8
Showing 1 changed file with 2 additions and 1 deletion.
Expand Up @@ -765,10 +765,11 @@ public void run() {

recalculateAndUpdateMargins();

targetParent.addView(this.view);

// Set view to INVISIBLE so it doesn't flash on the screen before the inset adjustment is
// handled and the enter animation is started
view.setVisibility(View.INVISIBLE);
targetParent.addView(this.view);
}

if (ViewCompat.isLaidOut(this.view)) {
Expand Down

0 comments on commit 35d9da8

Please sign in to comment.