Skip to content

Commit

Permalink
[TopAppBar] Fixed compress effect when toolbar is set as a support ac…
Browse files Browse the repository at this point in the history
…tion bar and hiddin/shown.

getSupportActionBar.show/hide uses visibility to show/hide the toolbar which conflicted with the compress effect's use of Visibility to remove the toolbar when completely masked. This updates the compress effect to use alpha instead of visibility.

PiperOrigin-RevId: 619253990
  • Loading branch information
hunterstich authored and paulfthomas committed Mar 26, 2024
1 parent a2d9bac commit 17855c1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ public View onCreateDemoView(
showHideTabsButton.setOnCheckedChangeListener(
(buttonView, isChecked) -> updateTabVisibility(tabs, isChecked));

ToggleButton showHideToolbarButton = view.findViewById(R.id.show_hide_toolbar_button);
showHideToolbarButton.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (isChecked) {
activity.getSupportActionBar().show();
} else {
activity.getSupportActionBar().hide();
}
});

return view;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@
android:textOn="@string/cat_topappbar_compress_hide_tabs_toggle_label"
android:textOff="@string/cat_topappbar_compress_show_tabs_toggle_label" />

<ToggleButton
android:id="@+id/show_hide_toolbar_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="8dp"
android:checked="true"
android:textOn="@string/cat_topappbar_compress_hide_toolbar_toggle_label"
android:textOff="@string/cat_topappbar_compress_show_toolbar_toggle_label" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@
<string name="cat_topappbar_compress_toolbar_title">Compress Title</string>
<string name="cat_topappbar_compress_show_tabs_toggle_label">Show tabs</string>
<string name="cat_topappbar_compress_hide_tabs_toggle_label">Hide tabs</string>
<string name="cat_topappbar_compress_show_toolbar_toggle_label">Show toolbar</string>
<string name="cat_topappbar_compress_hide_toolbar_toggle_label">Hide toolbar</string>

<string name="cat_topappbar_tabs_label_all">All</string>
<string name="cat_topappbar_tabs_label_shopping">Shopping</string>
Expand Down
6 changes: 3 additions & 3 deletions lib/java/com/google/android/material/appbar/AppBarLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -2579,16 +2579,16 @@ public void onOffsetChanged(
// invisible. Otherwise, on API <= 24 a ghost rect that is outside of the drawing rect will
// be ignored and the child would be drawn with no clipping.
if (offsetY >= ghostRect.height()) {
child.setVisibility(INVISIBLE);
child.setAlpha(0f);
} else {
child.setVisibility(VISIBLE);
child.setAlpha(1f);
}
ViewCompat.setClipBounds(child, ghostRect);
} else {
// Reset both the clip bounds and translationY of this view
ViewCompat.setClipBounds(child, null);
child.setTranslationY(0);
child.setVisibility(VISIBLE);
child.setAlpha(1f);
}
}
}
Expand Down

0 comments on commit 17855c1

Please sign in to comment.