Skip to content

Commit

Permalink
[Fix] Fix crash during activity recreation.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanghai committed Nov 24, 2020
1 parent 73fb777 commit e3f3eec
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ fun AppBarLayout.updateLiftOnScrollOnPreDraw() {
val consumed = IntArray(2)
viewTreeObserver.addOnPreDrawListener {
// Call AppBarLayout.Behavior.onNestedPreScroll() with dy == 0 to update lifted state.
val behavior = (layoutParams as CoordinatorLayout.LayoutParams).behavior!!
val behavior = (layoutParams as CoordinatorLayout.LayoutParams).behavior
// onPreDraw() somehow may be called before onMeasure() (where
// AppBarLayout.getBehavior() is called) during activity recreation.
?: return@addOnPreDrawListener true
val coordinatorLayout = parent as CoordinatorLayout
behavior.onNestedPreScroll(coordinatorLayout, this, coordinatorLayout, 0, 0, consumed, 0)
true
Expand Down

0 comments on commit e3f3eec

Please sign in to comment.