Skip to content

Commit

Permalink
[CollapsingToolbarLayout] Fix issue where expanded text gets ellipsiz…
Browse files Browse the repository at this point in the history
…ed too aggressively when using title fade mode and the toolbar has menu items

PiperOrigin-RevId: 569287167
  • Loading branch information
dsn5ft committed Oct 2, 2023
1 parent a01a68d commit 094e3e2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
Expand Up @@ -22,6 +22,8 @@
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.LayoutRes;
Expand All @@ -32,6 +34,13 @@
/** A base fragment that displays a collapsing Top App Bar demo for the Catalog app. */
public abstract class BaseTopAppBarCollapsingDemoFragment extends DemoFragment {

@Override
public void onCreate(@Nullable Bundle bundle) {
super.onCreate(bundle);

setHasOptionsMenu(true);
}

@NonNull
@Override
public View onCreateDemoView(
Expand All @@ -47,6 +56,13 @@ public View onCreateDemoView(
return view;
}

@Override
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater menuInflater) {
super.onCreateOptionsMenu(menu, menuInflater);

menuInflater.inflate(R.menu.cat_topappbar_menu, menu);
}

@Override
public boolean shouldShowDefaultDemoActionBar() {
return false;
Expand Down
Expand Up @@ -41,7 +41,7 @@
android:layout_height="?attr/actionBarSize"
android:elevation="0dp"
app:layout_collapseMode="pin"
app:title="@string/cat_topappbar_collapsing_demo_toolbar_title"/>
app:title="@string/cat_topappbar_collapsing_demo_toolbar_large_title"/>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>

Expand Down
Expand Up @@ -41,7 +41,7 @@
android:layout_height="?attr/actionBarSize"
android:elevation="0dp"
app:layout_collapseMode="pin"
app:title="@string/cat_topappbar_collapsing_demo_toolbar_title"/>
app:title="@string/cat_topappbar_collapsing_demo_toolbar_medium_title"/>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>

Expand Down
Expand Up @@ -41,8 +41,10 @@
<string name="cat_topappbar_main_demo_toolbar_title">Regular Title</string>
<!-- Title for the scrolling toolbar demo [CHAR_LIMIT=NONE] -->
<string name="cat_topappbar_scrolling_demo_toolbar_title">Scrolling Title</string>
<!-- Title for the collpasing toolbar demo [CHAR_LIMIT=NONE] -->
<string name="cat_topappbar_collapsing_demo_toolbar_title">Collapsing Title</string>
<!-- Title for the medium collpasing toolbar demo [CHAR_LIMIT=NONE] -->
<string name="cat_topappbar_collapsing_demo_toolbar_medium_title">Collapsing Title Medium Size</string>

This comment has been minimized.

Copy link
@0MuTTanT0

0MuTTanT0 Jan 8, 2024

`
SAVE_20230109_162324

`

<!-- Title for the large collpasing toolbar demo [CHAR_LIMIT=NONE] -->
<string name="cat_topappbar_collapsing_demo_toolbar_large_title">Collapsing Title Large Size</string>
<!-- Label for a button in the menu [CHAR_LIMIT=NONE] -->
<string name="cat_topappbar_edit_menu_item_title">Edit</string>
<!-- Label for a button in the menu [CHAR_LIMIT=NONE] -->
Expand Down
Expand Up @@ -1026,9 +1026,11 @@ private void calculateUsingTextSize(final float fraction, boolean forceRecalcula
// collapsed text size
float scaledDownWidth = expandedWidth * textSizeRatio;

if (forceRecalculate) {
if (forceRecalculate || fadeModeEnabled) {
// If we're forcing a recalculate during a measure pass, use the expanded width since the
// collapsed width might not be ready yet
// Or if the fade mode is enabled, we can also just use the expanded width because when
// fading out/in there is not a continuous scale transition between expanded/collapsed text
availableWidth = expandedWidth;
} else {
// If the scaled down size is larger than the actual collapsed width, we need to
Expand Down

0 comments on commit 094e3e2

Please sign in to comment.