Skip to content

Commit 251f906

Browse files
Material Design Teamhunterstich
authored andcommitted
[Search] sync SearchBar text and placeholder for contained animations
Previously, the SearchBar placeholder text could be updated independently of the main TextView to handle transitions where SearchView.EditText differed from SearchBar.TextView. However, for contained animations, having these texts out of sync complicates the translation logic and causes incorrect offset calculations. Since the contained style uses cross-fading, keeping the TextView and placeholder in sync provides a smoother transition without the positioning bugs. PiperOrigin-RevId: 881635003
1 parent bb0f842 commit 251f906

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

lib/java/com/google/android/material/search/SearchView.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ public class SearchView extends FrameLayout
174174
private boolean useWindowInsetsController;
175175
private boolean statusBarSpacerEnabledOverride;
176176
private final boolean dividerVisible;
177+
private final boolean containedAnimationEnabled;
177178
@NonNull private TransitionState currentTransitionState = TransitionState.HIDDEN;
178179
private Map<View, Integer> childImportantForAccessibilityMap;
179180
private final OnTouchModeChangeListener touchModeChangeListener =
@@ -224,7 +225,7 @@ public SearchView(@NonNull Context context, @Nullable AttributeSet attrs, int de
224225
autoShowKeyboard = a.getBoolean(R.styleable.SearchView_autoShowKeyboard, true);
225226
backHandlingEnabled = a.getBoolean(R.styleable.SearchView_backHandlingEnabled, true);
226227
dividerVisible = a.getBoolean(R.styleable.SearchView_dividerVisible, true);
227-
boolean containedAnimationEnabled =
228+
containedAnimationEnabled =
228229
a.getBoolean(R.styleable.SearchView_containedAnimationEnabled, false);
229230

230231
a.recycle();
@@ -326,7 +327,7 @@ public void startBackProgress(@NonNull BackEventCompat backEvent) {
326327
if (isHiddenOrHiding() || searchBar == null) {
327328
return;
328329
}
329-
if (searchBar != null) {
330+
if (!containedAnimationEnabled) {
330331
searchBar.setPlaceholderText(editText.getText().toString());
331332
}
332333
searchViewAnimationHelper.startBackProgress(backEvent);
@@ -964,7 +965,9 @@ public void hide() {
964965
return;
965966
}
966967
if (searchBar != null && searchBar.isAttachedToWindow()) {
967-
searchBar.setPlaceholderText(editText.getText().toString());
968+
if (!containedAnimationEnabled) {
969+
searchBar.setPlaceholderText(editText.getText().toString());
970+
}
968971
searchBar.post(searchViewAnimationHelper::hide);
969972
} else {
970973
searchViewAnimationHelper.hide();

0 commit comments

Comments
 (0)