Skip to content

Commit 6254db4

Browse files
authored
fix(#82): ensure content is scrolled beneath toolbar (#83)
Fixes #82. By default, the appbar starts as not lifted, then it's lifted on scroll. That's why the scrollable content is not beneath the toolbar as seen in #82. Our use case doesn't require appbar lifting, so we can safely disable this feature, making the toolbar be permanently lifted above the scrollable content. This would likely be a bug in the material-components library, which doesn't properly handle the edge-to-edge enforcement since Android 15. NOTE: whereas disabling lifting feature fixes the view drawing order (aka Z order), for a better UI, we also need to disable the scrim background animation in Expressive Design (enabled by default since Android 16), otherwise we'll see for a moment the scrollable content through the AppBarLayout. Signed-off-by: iusmac <[email protected]>
1 parent 8b44fff commit 6254db4

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

res/values/integers.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<!-- Override the default AOSP's value of 50ms, which is too short and makes the scrim flicker
4+
on <60Hz displays.
5+
Note that for a better UI, we completely disable the scrim background animation in the
6+
Expressive Design, otherwise we'll see for a moment the scrollable content through the
7+
AppBarLayout. -->
8+
<integer name="collapsingtoolbar_scrim_anim_duration">250</integer>
9+
<integer name="collapsingtoolbar_scrim_anim_duration_expressive">0</integer>
10+
</resources>

src/com/github/iusmac/sevensim/ui/components/CollapsingToolbarBaseActivity.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
* the box.
3535
*/
3636
public abstract class CollapsingToolbarBaseActivity extends FragmentActivity {
37-
private static final int SCRIM_ANIMATION_DURATION = 250;
38-
3937
private CollapsingToolbarDelegate mToolbardelegate;
4038
private ToolbarDecorator mToolbarDecorator;
4139
private ViewModel mViewModel;
@@ -58,9 +56,10 @@ protected void onCreate(final @Nullable Bundle savedInstanceState) {
5856

5957
final ToolbarDecorator toolbarDecorator = getToolbarDecorator();
6058
if (toolbarDecorator.isCollapsingToolbarSupported()) {
61-
// Override the default AOSP's value of 50ms, which is too short and makes the scrim
62-
// flicker on <60Hz displays
63-
getCollapsingToolbarLayout().setScrimAnimationDuration(SCRIM_ANIMATION_DURATION);
59+
final int scrimAnimationDuration = getResources().getInteger(isExpressiveTheme ?
60+
R.integer.collapsingtoolbar_scrim_anim_duration_expressive
61+
: R.integer.collapsingtoolbar_scrim_anim_duration);
62+
getCollapsingToolbarLayout().setScrimAnimationDuration(scrimAnimationDuration);
6463
// Enforce fade in/out and translate collapse effect for the title so that it's
6564
// consistent with the subtitle that doesn't support scaling, which may be selected if
6665
// using non-AOSP sources
@@ -84,6 +83,9 @@ protected void onCreate(final @Nullable Bundle savedInstanceState) {
8483
// Hide the action button by default when expressive theme is enabled.
8584
setActionButtonEnabled(false);
8685
}
86+
// Our use case requires the CollapsingToolbar to be permanently lifted above the
87+
// scrollable content (safe to disable; less animations, better performance)
88+
getAppBarLayout().setLiftable(false);
8789
} else {
8890
// For better UX (e.g. l10n), apply the marquee effect on the title for non-collapsing
8991
// Toolbar

0 commit comments

Comments
 (0)