Skip to content

Commit 35d9da8

Browse files
drchenjosefigueroa168
authored andcommitted
[SnackBar] Fix NPE on Android 8 & 9
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
1 parent fcc68a2 commit 35d9da8

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/java/com/google/android/material/snackbar/BaseTransientBottomBar.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,10 +765,11 @@ public void run() {
765765

766766
recalculateAndUpdateMargins();
767767

768+
targetParent.addView(this.view);
769+
768770
// Set view to INVISIBLE so it doesn't flash on the screen before the inset adjustment is
769771
// handled and the enter animation is started
770772
view.setVisibility(View.INVISIBLE);
771-
targetParent.addView(this.view);
772773
}
773774

774775
if (ViewCompat.isLaidOut(this.view)) {

0 commit comments

Comments
 (0)