For #1072: Adds grabber handle bounce animation
parent
4acd939289
commit
d2af87f8f8
|
@ -53,6 +53,7 @@ import org.mozilla.fenix.ext.requireComponents
|
|||
import org.mozilla.fenix.ext.share
|
||||
import org.mozilla.fenix.mvi.ActionBusFactory
|
||||
import org.mozilla.fenix.mvi.getAutoDisposeObservable
|
||||
import org.mozilla.fenix.quickactionsheet.QuickActionSheet
|
||||
|
||||
class BrowserFragment : Fragment(), BackHandler {
|
||||
private lateinit var toolbarComponent: ToolbarComponent
|
||||
|
@ -208,6 +209,9 @@ class BrowserFragment : Fragment(), BackHandler {
|
|||
view = view
|
||||
)
|
||||
|
||||
val actionSheet = view.findViewById<QuickActionSheet>(R.id.quick_action_sheet)
|
||||
actionSheet.afterInflate()
|
||||
|
||||
val actionEmitter = ActionBusFactory.get(this).getManagedEmitter(SearchAction::class.java)
|
||||
sessionId?.let { id ->
|
||||
customTabsIntegration.set(
|
||||
|
|
|
@ -2,7 +2,6 @@ package org.mozilla.fenix.quickactionsheet
|
|||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.LinearLayout
|
||||
import androidx.appcompat.widget.AppCompatImageButton
|
||||
|
@ -11,6 +10,9 @@ import androidx.core.widget.NestedScrollView
|
|||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
import mozilla.components.browser.toolbar.BrowserToolbar
|
||||
import org.mozilla.fenix.R
|
||||
import android.animation.ValueAnimator
|
||||
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
|
||||
import org.mozilla.fenix.ext.increaseTapArea
|
||||
|
||||
class QuickActionSheet @JvmOverloads constructor(
|
||||
context: Context,
|
||||
|
@ -21,24 +23,39 @@ class QuickActionSheet @JvmOverloads constructor(
|
|||
|
||||
init {
|
||||
inflate(getContext(), R.layout.component_quickactionsheet, this)
|
||||
//setupHandle()
|
||||
}
|
||||
|
||||
fun afterInflate() {
|
||||
setupHandle()
|
||||
}
|
||||
|
||||
private fun setupHandle() {
|
||||
val handle = findViewById<AppCompatImageButton>(R.id.quick_action_sheet_handle)
|
||||
val linearLayout = findViewById<LinearLayout>(R.id.quick_action_sheet)
|
||||
val quickActionSheetBehavior = BottomSheetBehavior.from(linearLayout) as QuickActionSheetBehavior
|
||||
val quickActionSheetBehavior = BottomSheetBehavior.from(linearLayout.parent as View) as QuickActionSheetBehavior
|
||||
handle.increaseTapArea(100)
|
||||
handle.setOnClickListener {
|
||||
bounceSheet(quickActionSheetBehavior)
|
||||
}
|
||||
|
||||
bounceSheet(quickActionSheetBehavior, 600L)
|
||||
}
|
||||
|
||||
private fun bounceSheet(quickActionSheetBehavior: QuickActionSheetBehavior) {
|
||||
quickActionSheetBehavior.state = BottomSheetBehavior.STATE_HIDDEN
|
||||
quickActionSheetBehavior.peekHeight = height
|
||||
quickActionSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED
|
||||
}
|
||||
private fun bounceSheet(quickActionSheetBehavior: QuickActionSheetBehavior, duration: Long = 400L) {
|
||||
val normalPeekHeight = quickActionSheetBehavior.peekHeight
|
||||
val valueAnimator = ValueAnimator.ofFloat(normalPeekHeight.toFloat(), normalPeekHeight*6f)
|
||||
|
||||
valueAnimator.addUpdateListener {
|
||||
quickActionSheetBehavior.peekHeight = (it.animatedValue as Float).toInt()
|
||||
}
|
||||
|
||||
valueAnimator.repeatMode = ValueAnimator.REVERSE
|
||||
valueAnimator.repeatCount = 1
|
||||
// Fast out slow in looks best so far
|
||||
valueAnimator.interpolator = FastOutSlowInInterpolator()
|
||||
valueAnimator.duration = duration
|
||||
valueAnimator.start()
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("unused") // Referenced from XML
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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/. -->
|
||||
<shape
|
||||
android:shape="rectangle"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<corners android:radius="2dp"/>
|
||||
<size android:height="2dp" android:width="24dp" />
|
||||
<solid android:color="#2915141A" />
|
||||
</shape>
|
|
@ -9,21 +9,22 @@
|
|||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="80dp"
|
||||
android:background="@color/photonRed50">
|
||||
android:background="@color/off_white">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageButton
|
||||
android:id="@+id/quick_action_sheet_handle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="10dp"
|
||||
android:layout_marginTop="7dp"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="2dp"
|
||||
android:layout_gravity="center"
|
||||
android:src="@drawable/ic_close"/>
|
||||
android:background="@drawable/ic_drawer_pull_tab"/>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_gravity="bottom"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="70dp"
|
||||
android:background="@color/photonBlue50">
|
||||
android:layout_height="78dp"
|
||||
android:background="@color/off_white">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageButton
|
||||
android:layout_weight="1"
|
||||
|
|
|
@ -23,9 +23,10 @@
|
|||
android:background="@color/off_white"
|
||||
android:clipToPadding="true"
|
||||
app:behavior_hideable="true"
|
||||
app:behavior_peekHeight="20dp"
|
||||
app:behavior_peekHeight="10dp"
|
||||
app:layout_behavior="org.mozilla.fenix.quickactionsheet.QuickActionSheetBehavior">
|
||||
<org.mozilla.fenix.quickactionsheet.QuickActionSheet
|
||||
android:id="@+id/quick_action_sheet"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom"/>
|
||||
|
|
Loading…
Reference in New Issue