@@ -309,6 +309,8 @@ public void onAnimationEnd(Animator animation) {
309
309
if (searchBar != null ) {
310
310
searchBar .getTextView ().setAlpha (1 );
311
311
}
312
+ // Reset clip bounds so it can react to the screen or layout changes.
313
+ editText .setClipBounds (null );
312
314
313
315
// After expanding or collapsing, we should reset the clip bounds so it can react to the
314
316
// screen or layout changes. Otherwise it will result in wrong clipping on the layout.
@@ -580,12 +582,32 @@ private Animator getEditTextAnimator(boolean show) {
580
582
private AnimatorSet getTextAnimator (boolean show ) {
581
583
AnimatorSet animatorSet = new AnimatorSet ();
582
584
addTextFadeAnimatorIfNeeded (animatorSet );
585
+ addEditTextClipAnimator (animatorSet );
583
586
animatorSet .setDuration (show ? SHOW_DURATION_MS : HIDE_DURATION_MS );
584
587
animatorSet .setInterpolator (
585
588
ReversableAnimatedValueInterpolator .of (show , AnimationUtils .LINEAR_INTERPOLATOR ));
586
589
return animatorSet ;
587
590
}
588
591
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
+
589
611
private void addTextFadeAnimatorIfNeeded (AnimatorSet animatorSet ) {
590
612
if (searchBar == null || TextUtils .equals (editText .getText (), searchBar .getText ())) {
591
613
return ;
@@ -721,10 +743,10 @@ private int getFromTranslationXEnd(View view) {
721
743
}
722
744
723
745
private int getFromTranslationY () {
724
- int toolbarMiddleY = toolbarContainer .getTop () + toolbarContainer .getMeasuredHeight () / 2 ;
746
+ int toolbarMiddleY = toolbarContainer .getTop () + toolbarContainer .getHeight () / 2 ;
725
747
int searchBarMiddleY =
726
748
getViewTopFromSearchViewParent (searchBar )
727
- + searchBar .getMeasuredHeight () / 2 ;
749
+ + searchBar .getHeight () / 2 ;
728
750
return searchBarMiddleY - toolbarMiddleY ;
729
751
}
730
752
0 commit comments