From 96391bedfb764cbea36411c76f4df08f3bfd6fe7 Mon Sep 17 00:00:00 2001 From: ekager Date: Fri, 19 Apr 2019 12:01:32 -0700 Subject: [PATCH] [fenix] Closes https://github.com/mozilla-mobile/fenix/issues/1798, Closes https://github.com/mozilla-mobile/fenix/issues/1581 Corrects divider views and padding for toolbar and action sheet --- .../browser/BrowserToolbarDividerBehavior.kt | 42 +++++++++++++++++++ app/src/main/res/layout/fragment_browser.xml | 14 +++++-- .../res/layout/layout_quick_action_sheet.xml | 8 ++++ 3 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/org/mozilla/fenix/browser/BrowserToolbarDividerBehavior.kt diff --git a/app/src/main/java/org/mozilla/fenix/browser/BrowserToolbarDividerBehavior.kt b/app/src/main/java/org/mozilla/fenix/browser/BrowserToolbarDividerBehavior.kt new file mode 100644 index 0000000000..dbb6e22963 --- /dev/null +++ b/app/src/main/java/org/mozilla/fenix/browser/BrowserToolbarDividerBehavior.kt @@ -0,0 +1,42 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package org.mozilla.fenix.browser + +import android.content.Context +import android.util.AttributeSet +import android.view.View +import androidx.coordinatorlayout.widget.CoordinatorLayout +import mozilla.components.browser.toolbar.BrowserToolbar + +/** + * [CoordinatorLayout.Behavior] that will always position the [View] above the [BrowserToolbar] (including + * when the browser toolbar is scrolling or performing a snap animation). + */ +@Suppress("unused") // Referenced from XML +class BrowserToolbarDividerBehavior( + context: Context, + attrs: AttributeSet +) : CoordinatorLayout.Behavior(context, attrs) { + override fun layoutDependsOn(parent: CoordinatorLayout, child: View, dependency: View): Boolean { + if (dependency is BrowserToolbar) { + return true + } + + return super.layoutDependsOn(parent, child, dependency) + } + + override fun onDependentViewChanged(parent: CoordinatorLayout, child: View, dependency: View): Boolean { + return if (dependency is BrowserToolbar) { + repositionView(child, dependency) + true + } else { + false + } + } + + private fun repositionView(view: View, toolbar: BrowserToolbar) { + view.translationY = (toolbar.translationY + toolbar.height * -1.0).toFloat() + } +} diff --git a/app/src/main/res/layout/fragment_browser.xml b/app/src/main/res/layout/fragment_browser.xml index 8466b77324..229c0785f2 100644 --- a/app/src/main/res/layout/fragment_browser.xml +++ b/app/src/main/res/layout/fragment_browser.xml @@ -16,17 +16,25 @@ android:layout_width="match_parent" android:layout_height="match_parent"/> - + + + +