Skip to content

Commit

Permalink
Issue mozilla-mobile#1664 - Add navigation overlay toolbar-push behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
liuche committed Feb 23, 2019
1 parent 235d197 commit 86985a4
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* 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.tv.firefox.navigationoverlay

import android.content.Context
import android.support.design.widget.CoordinatorLayout
import android.support.v4.widget.NestedScrollView
import android.util.AttributeSet
import android.view.View
import android.widget.LinearLayout
import org.mozilla.tv.firefox.R

class NavigationOverlayBehavior(context: Context, attrs: AttributeSet) : CoordinatorLayout.Behavior<LinearLayout>(context, attrs) {
var toolbarHeight = 0

override fun onLayoutChild(parent: CoordinatorLayout, child: LinearLayout, layoutDirection: Int): Boolean {
toolbarHeight = child.measuredHeight
return super.onLayoutChild(parent, child, layoutDirection)
}

override fun onStartNestedScroll(
coordinatorLayout: CoordinatorLayout,
child: LinearLayout,
directTargetChild: View,
target: View,
axes: Int,
type: Int
): Boolean {
return true
}

override fun onNestedScroll(
coordinatorLayout: CoordinatorLayout,
child: LinearLayout,
target: View,
dxConsumed: Int,
dyConsumed: Int,
dxUnconsumed: Int,
dyUnconsumed: Int,
type: Int
) {
if (target is NestedScrollView) {
val overlayBottomContainer = (target.findViewById<LinearLayout>(R.id.overlayBottomHalf))
val containerPosArray = intArrayOf(0, 0)
overlayBottomContainer.getLocationOnScreen(containerPosArray)

val containerTop = containerPosArray[1]
if (containerTop < toolbarHeight) {
child.y = 1.0f * (containerTop - toolbarHeight)
} else {
child.y = 0f
}
}
super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, type)
}
}
3 changes: 3 additions & 0 deletions app/src/main/res/layout/fragment_navigation_overlay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/overlayScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand All @@ -26,6 +27,7 @@
android:layout_height="412dp"/>

<LinearLayout
android:id="@+id/overlayBottomHalf"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
Expand Down Expand Up @@ -60,6 +62,7 @@
android:layout_height="wrap_content"
android:paddingTop="27dp"
android:background="@color/browser_overlay_background"
app:layout_behavior="org.mozilla.tv.firefox.navigationoverlay.NavigationOverlayBehavior"
android:orientation="vertical">

<LinearLayout
Expand Down

0 comments on commit 86985a4

Please sign in to comment.