forked from mozilla-mobile/firefox-tv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue mozilla-mobile#1664 - Add navigation overlay toolbar-push behavior
- Loading branch information
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
app/src/main/java/org/mozilla/tv/firefox/navigationoverlay/NavigationOverlayBehavior.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters