Skip to content
This repository has been archived by the owner on Jan 12, 2023. It is now read-only.

Commit

Permalink
BrowserFragment: Revert toolbar alpha state when app bar is collapsed…
Browse files Browse the repository at this point in the history
… or expanded. (#1126)
  • Loading branch information
pocmo committed Aug 11, 2017
1 parent 28039cd commit 6a9b5a4
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions app/src/main/java/org/mozilla/focus/fragment/BrowserFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,21 @@ public View inflateLayout(LayoutInflater inflater, @Nullable ViewGroup container
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
// When scrolling the toolbar away we want to fade out the content on the toolbar
// with an alpha animation. This will avoid that the text
// with an alpha animation. This will avoid that the text clashes with the status bar.

final int totalScrollRange = appBarLayout.getTotalScrollRange();
if (verticalOffset == 0 || Math.abs(verticalOffset) == totalScrollRange) {
// If the app bar is completely expanded or collapsed we want full opacity. We
// even want full opacity for a collapsed app bar because while loading a website
// the toolbar sometimes pops out when the URL changes. Without setting it to
// opaque the toolbar content might be invisible in this case (See issue #1126)
toolbarContent.setAlpha(1f);
return;
}

// The toolbar content should have 100% alpha when the AppBarLayout is expanded and
// should have 0 alpha when the toolbar is collapsed 50% or more.
float alpha = -1 * (((100f / (appBarLayout.getTotalScrollRange() * 0.5f)) * verticalOffset) / 100);
float alpha = -1 * (((100f / (totalScrollRange * 0.5f)) * verticalOffset) / 100);

// We never want to go lower than 0 or higher than 1.
alpha = Math.max(0, alpha);
Expand Down

0 comments on commit 6a9b5a4

Please sign in to comment.