@@ -309,6 +309,8 @@ public void onAnimationEnd(Animator animation) {
309309 if (searchBar != null ) {
310310 searchBar .getTextView ().setAlpha (1 );
311311 }
312+ // Reset clip bounds so it can react to the screen or layout changes.
313+ editText .setClipBounds (null );
312314
313315 // After expanding or collapsing, we should reset the clip bounds so it can react to the
314316 // screen or layout changes. Otherwise it will result in wrong clipping on the layout.
@@ -580,12 +582,32 @@ private Animator getEditTextAnimator(boolean show) {
580582 private AnimatorSet getTextAnimator (boolean show ) {
581583 AnimatorSet animatorSet = new AnimatorSet ();
582584 addTextFadeAnimatorIfNeeded (animatorSet );
585+ addEditTextClipAnimator (animatorSet );
583586 animatorSet .setDuration (show ? SHOW_DURATION_MS : HIDE_DURATION_MS );
584587 animatorSet .setInterpolator (
585588 ReversableAnimatedValueInterpolator .of (show , AnimationUtils .LINEAR_INTERPOLATOR ));
586589 return animatorSet ;
587590 }
588591
592+ private void addEditTextClipAnimator (AnimatorSet animatorSet ) {
593+ // We only want to add a clip animation if the edittext and searchbar text is the same, which
594+ // means it is translating instead of fading.
595+ if (searchBar == null || !TextUtils .equals (editText .getText (), searchBar .getText ())) {
596+ return ;
597+ }
598+ Rect editTextClipBounds =
599+ new Rect (0 , 0 , editText .getWidth (), editText .getHeight ());
600+ ValueAnimator animator =
601+ ValueAnimator .ofInt (
602+ searchBar .getTextView ().getWidth (), editText .getWidth ());
603+ animator .addUpdateListener (
604+ animation -> {
605+ editTextClipBounds .right = (int ) animation .getAnimatedValue ();
606+ editText .setClipBounds (editTextClipBounds );
607+ });
608+ animatorSet .playTogether (animator );
609+ }
610+
589611 private void addTextFadeAnimatorIfNeeded (AnimatorSet animatorSet ) {
590612 if (searchBar == null || TextUtils .equals (editText .getText (), searchBar .getText ())) {
591613 return ;
@@ -721,10 +743,10 @@ private int getFromTranslationXEnd(View view) {
721743 }
722744
723745 private int getFromTranslationY () {
724- int toolbarMiddleY = toolbarContainer .getTop () + toolbarContainer .getMeasuredHeight () / 2 ;
746+ int toolbarMiddleY = toolbarContainer .getTop () + toolbarContainer .getHeight () / 2 ;
725747 int searchBarMiddleY =
726748 getViewTopFromSearchViewParent (searchBar )
727- + searchBar .getMeasuredHeight () / 2 ;
749+ + searchBar .getHeight () / 2 ;
728750 return searchBarMiddleY - toolbarMiddleY ;
729751 }
730752
0 commit comments