Skip to content

Commit

Permalink
[Search] Exclude icons from search bar handwriting bounds
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 617405112
(cherry picked from commit fb441e6)
  • Loading branch information
Material Design Team authored and hunterstich committed Mar 21, 2024
1 parent a3af20a commit 387f59b
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/java/com/google/android/material/search/SearchBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,8 @@ private void setNavigationIconDecorative(boolean decorative) {
// that, and restore the original background when the icon becomes clickable.
navigationIconButton.setBackgroundDrawable(
decorative ? null : originalNavigationIconBackground);

setHandwritingBoundsInsets();
}

@Override
Expand Down Expand Up @@ -448,6 +450,7 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
super.onLayout(changed, left, top, right, bottom);

layoutCenterView();
setHandwritingBoundsInsets();
}

@Override
Expand Down Expand Up @@ -559,6 +562,32 @@ private void layoutChild(View child, int left, int top, int right, int bottom) {
}
}

private void setHandwritingBoundsInsets() {
if (VERSION.SDK_INT < VERSION_CODES.UPSIDE_DOWN_CAKE) {
return;
}

boolean isRtl = getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;

// If the navigation icon is non-decorative, exclude it from the handwriting bounds.
int startInset = 0;
View navigationIconButton = ToolbarUtils.getNavigationIconButton(this);
if (navigationIconButton != null && navigationIconButton.isClickable()) {
startInset =
isRtl ? (getWidth() - navigationIconButton.getLeft()) : navigationIconButton.getRight();
}

// Exclude the menu items from the handwriting bounds.
int endInset = 0;
View actionMenuView = ToolbarUtils.getActionMenuView(this);
if (actionMenuView != null) {
endInset = isRtl ? actionMenuView.getRight() : (getWidth() - actionMenuView.getLeft());
}

setHandwritingBoundsOffsets(
-(isRtl ? endInset : startInset), 0, -(isRtl ? startInset : endInset), 0);
}

/** Returns the optional centered child view of this {@link SearchBar} */
@Nullable
public View getCenterView() {
Expand Down

0 comments on commit 387f59b

Please sign in to comment.