@@ -207,6 +207,8 @@ public abstract static class BottomSheetCallback {
207207
208208 private boolean isShapeExpanded ;
209209
210+ private SettleRunnable settleRunnable = null ;
211+
210212 @ Nullable private ValueAnimator interpolatorAnimator ;
211213
212214 private static final int DEF_STYLE_RES = R .style .Widget_Design_BottomSheet_Modal ;
@@ -1181,7 +1183,19 @@ void startSettlingAnimation(View child, int state, int top, boolean settleFromVi
11811183 setStateInternal (STATE_SETTLING );
11821184 // STATE_SETTLING won't animate the material shape, so do that here with the target state.
11831185 updateDrawableForTargetState (state );
1184- ViewCompat .postOnAnimation (child , new SettleRunnable (child , state ));
1186+ if (settleRunnable == null ) {
1187+ // If the singleton SettleRunnable instance has not been instantiated, create it.
1188+ settleRunnable = new SettleRunnable (child , state );
1189+ }
1190+ // If the SettleRunnable has not been posted, post it with the correct state.
1191+ if (settleRunnable .isPosted == false ) {
1192+ settleRunnable .targetState = state ;
1193+ ViewCompat .postOnAnimation (child , settleRunnable );
1194+ settleRunnable .isPosted = true ;
1195+ } else {
1196+ // Otherwise, if it has been posted, just update the target state.
1197+ settleRunnable .targetState = state ;
1198+ }
11851199 } else {
11861200 setStateInternal (state );
11871201 }
@@ -1356,7 +1370,9 @@ private class SettleRunnable implements Runnable {
13561370
13571371 private final View view ;
13581372
1359- @ State private final int targetState ;
1373+ private boolean isPosted ;
1374+
1375+ @ State int targetState ;
13601376
13611377 SettleRunnable (View view , @ State int targetState ) {
13621378 this .view = view ;
@@ -1368,10 +1384,9 @@ public void run() {
13681384 if (viewDragHelper != null && viewDragHelper .continueSettling (true )) {
13691385 ViewCompat .postOnAnimation (view , this );
13701386 } else {
1371- if (state == STATE_SETTLING ) {
1372- setStateInternal (targetState );
1373- }
1387+ setStateInternal (targetState );
13741388 }
1389+ this .isPosted = false ;
13751390 }
13761391 }
13771392
0 commit comments