2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-19 09:25:34 +00:00

[fenix] For https://github.com/mozilla-mobile/fenix/issues/2206: Quick Action Bar fixes, do not hide, add shadow, peek initially (https://github.com/mozilla-mobile/fenix/pull/2238)

This commit is contained in:
Colin Lee 2019-05-02 15:08:49 -05:00 committed by GitHub
parent 6919cf294e
commit 9281be3341
3 changed files with 63 additions and 34 deletions

View File

@ -48,6 +48,8 @@ class ToolbarUIView(
?: sessionManager.selectedSession
view.apply {
elevation = resources.pxToDp(TOOLBAR_ELEVATION).toFloat()
setOnUrlCommitListener {
actionEmitter.onNext(SearchAction.UrlCommitted(it, sessionId, state?.engine))
false
@ -61,8 +63,12 @@ class ToolbarUIView(
val isCustomTabSession = (session?.isCustomTabSession() == true)
urlBoxView = if (isCustomTabSession) { null } else urlBackground
progressBarGravity = if (isCustomTabSession) { PROGRESS_BOTTOM } else PROGRESS_TOP
urlBoxView = if (isCustomTabSession) {
null
} else urlBackground
progressBarGravity = if (isCustomTabSession) {
PROGRESS_BOTTOM
} else PROGRESS_TOP
textColor = ContextCompat.getColor(context, R.color.photonGrey30)
@ -73,6 +79,7 @@ class ToolbarUIView(
actionEmitter.onNext(SearchAction.EditingCanceled)
return false
}
override fun onTextChanged(text: String) {
url = text
actionEmitter.onNext(SearchAction.TextChanged(text))
@ -186,6 +193,7 @@ class ToolbarUIView(
}
companion object {
private const val TOOLBAR_ELEVATION = 16
private const val PROGRESS_BOTTOM = 0
private const val PROGRESS_TOP = 1
const val browserActionMarginDp = 8

View File

@ -4,21 +4,21 @@
package org.mozilla.fenix.quickactionsheet
import android.animation.ValueAnimator
import android.content.Context
import android.os.Bundle
import android.util.AttributeSet
import android.view.View
import android.widget.LinearLayout
import androidx.coordinatorlayout.widget.CoordinatorLayout
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 android.os.Bundle
import android.view.accessibility.AccessibilityEvent
import android.view.accessibility.AccessibilityNodeInfo
import android.widget.ImageButton
import android.widget.LinearLayout
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.widget.NestedScrollView
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
import com.google.android.material.bottomsheet.BottomSheetBehavior
import mozilla.components.browser.toolbar.BrowserToolbar
import org.mozilla.fenix.R
import org.mozilla.fenix.utils.Settings
const val POSITION_SNAP_BUFFER = 1f
@ -69,8 +69,10 @@ class QuickActionSheet @JvmOverloads constructor(
val peakHeightMultiplier = if (duration == demoBounceAnimationLength)
demoBounceAnimationPeekHeightMultiplier else bounceAnimationPeekHeightMultiplier
ValueAnimator.ofFloat(normalPeekHeight.toFloat(),
normalPeekHeight * peakHeightMultiplier)?.let {
ValueAnimator.ofFloat(
normalPeekHeight.toFloat(),
normalPeekHeight * peakHeightMultiplier
)?.let {
it.addUpdateListener {
quickActionSheetBehavior.peekHeight = (it.animatedValue as Float).toInt()
@ -123,11 +125,13 @@ class QuickActionSheet @JvmOverloads constructor(
override fun onInitializeAccessibilityNodeInfo(host: View?, info: AccessibilityNodeInfo?) {
super.onInitializeAccessibilityNodeInfo(host, info)
info?.addAction(when (finalState) {
info?.addAction(
when (finalState) {
BottomSheetBehavior.STATE_COLLAPSED,
BottomSheetBehavior.STATE_HIDDEN -> AccessibilityNodeInfo.AccessibilityAction.ACTION_EXPAND
else -> AccessibilityNodeInfo.AccessibilityAction.ACTION_COLLAPSE
})
}
)
}
}
@ -167,9 +171,12 @@ class QuickActionSheetBehavior(
}
private fun repositionQuickActionSheet(quickActionSheetContainer: NestedScrollView, toolbar: BrowserToolbar) {
val handleHeight = quickActionSheetContainer.findViewById<ImageButton>(R.id.quick_action_sheet_handle).height
if (toolbar.translationY >= toolbar.height.toFloat() - POSITION_SNAP_BUFFER) {
state = STATE_HIDDEN
peekHeight = handleHeight
state = STATE_COLLAPSED
} else if (state == STATE_HIDDEN || state == STATE_SETTLING) {
peekHeight = handleHeight
state = STATE_COLLAPSED
}

View File

@ -7,6 +7,7 @@ package org.mozilla.fenix.quickactionsheet
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageButton
import android.widget.LinearLayout
import androidx.core.widget.NestedScrollView
import com.google.android.material.bottomsheet.BottomSheetBehavior
@ -16,6 +17,7 @@ import io.reactivex.functions.Consumer
import kotlinx.android.synthetic.main.fragment_browser.*
import kotlinx.android.synthetic.main.layout_quick_action_sheet.*
import kotlinx.android.synthetic.main.layout_quick_action_sheet.view.*
import mozilla.components.support.ktx.android.content.res.pxToDp
import org.mozilla.fenix.R
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.components
@ -35,6 +37,11 @@ class QuickActionUIView(
val quickActionSheetBehavior =
BottomSheetBehavior.from(nestedScrollQuickAction as View) as QuickActionSheetBehavior
// set initial state
animateOverlay(initialOverlayAlpha)
quickActionSheetBehavior.isHideable = false
quickActionSheetBehavior.peekHeight = view.resources.pxToDp(initialPeekHeightInDps)
quickActionSheetBehavior.setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
override fun onStateChanged(v: View, state: Int) {
updateImportantForAccessibility(state)
@ -47,6 +54,8 @@ class QuickActionUIView(
}
override fun onSlide(bottomSheet: View, slideOffset: Float) {
quickActionSheetBehavior.peekHeight =
bottomSheet.findViewById<ImageButton>(R.id.quick_action_sheet_handle).height
animateOverlay(slideOffset)
}
})
@ -99,4 +108,9 @@ class QuickActionUIView(
view.quick_action_read.visibility = if (it.readable) View.VISIBLE else View.GONE
view.quick_action_bookmark.isSelected = it.bookmarked
}
companion object {
const val initialOverlayAlpha = 0.5f
const val initialPeekHeightInDps = 30
}
}