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:
parent
6919cf294e
commit
9281be3341
@ -48,9 +48,11 @@ class ToolbarUIView(
|
|||||||
?: sessionManager.selectedSession
|
?: sessionManager.selectedSession
|
||||||
|
|
||||||
view.apply {
|
view.apply {
|
||||||
|
elevation = resources.pxToDp(TOOLBAR_ELEVATION).toFloat()
|
||||||
|
|
||||||
setOnUrlCommitListener {
|
setOnUrlCommitListener {
|
||||||
actionEmitter.onNext(SearchAction.UrlCommitted(it, sessionId, state?.engine))
|
actionEmitter.onNext(SearchAction.UrlCommitted(it, sessionId, state?.engine))
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
onUrlClicked = {
|
onUrlClicked = {
|
||||||
actionEmitter.onNext(SearchAction.ToolbarClicked)
|
actionEmitter.onNext(SearchAction.ToolbarClicked)
|
||||||
@ -61,8 +63,12 @@ class ToolbarUIView(
|
|||||||
|
|
||||||
val isCustomTabSession = (session?.isCustomTabSession() == true)
|
val isCustomTabSession = (session?.isCustomTabSession() == true)
|
||||||
|
|
||||||
urlBoxView = if (isCustomTabSession) { null } else urlBackground
|
urlBoxView = if (isCustomTabSession) {
|
||||||
progressBarGravity = if (isCustomTabSession) { PROGRESS_BOTTOM } else PROGRESS_TOP
|
null
|
||||||
|
} else urlBackground
|
||||||
|
progressBarGravity = if (isCustomTabSession) {
|
||||||
|
PROGRESS_BOTTOM
|
||||||
|
} else PROGRESS_TOP
|
||||||
|
|
||||||
textColor = ContextCompat.getColor(context, R.color.photonGrey30)
|
textColor = ContextCompat.getColor(context, R.color.photonGrey30)
|
||||||
|
|
||||||
@ -73,6 +79,7 @@ class ToolbarUIView(
|
|||||||
actionEmitter.onNext(SearchAction.EditingCanceled)
|
actionEmitter.onNext(SearchAction.EditingCanceled)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onTextChanged(text: String) {
|
override fun onTextChanged(text: String) {
|
||||||
url = text
|
url = text
|
||||||
actionEmitter.onNext(SearchAction.TextChanged(text))
|
actionEmitter.onNext(SearchAction.TextChanged(text))
|
||||||
@ -186,6 +193,7 @@ class ToolbarUIView(
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
private const val TOOLBAR_ELEVATION = 16
|
||||||
private const val PROGRESS_BOTTOM = 0
|
private const val PROGRESS_BOTTOM = 0
|
||||||
private const val PROGRESS_TOP = 1
|
private const val PROGRESS_TOP = 1
|
||||||
const val browserActionMarginDp = 8
|
const val browserActionMarginDp = 8
|
||||||
|
@ -4,21 +4,21 @@
|
|||||||
|
|
||||||
package org.mozilla.fenix.quickactionsheet
|
package org.mozilla.fenix.quickactionsheet
|
||||||
|
|
||||||
|
import android.animation.ValueAnimator
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.os.Bundle
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.View
|
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.AccessibilityEvent
|
||||||
import android.view.accessibility.AccessibilityNodeInfo
|
import android.view.accessibility.AccessibilityNodeInfo
|
||||||
import android.widget.ImageButton
|
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 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
|
import org.mozilla.fenix.utils.Settings
|
||||||
|
|
||||||
const val POSITION_SNAP_BUFFER = 1f
|
const val POSITION_SNAP_BUFFER = 1f
|
||||||
@ -69,8 +69,10 @@ class QuickActionSheet @JvmOverloads constructor(
|
|||||||
val peakHeightMultiplier = if (duration == demoBounceAnimationLength)
|
val peakHeightMultiplier = if (duration == demoBounceAnimationLength)
|
||||||
demoBounceAnimationPeekHeightMultiplier else bounceAnimationPeekHeightMultiplier
|
demoBounceAnimationPeekHeightMultiplier else bounceAnimationPeekHeightMultiplier
|
||||||
|
|
||||||
ValueAnimator.ofFloat(normalPeekHeight.toFloat(),
|
ValueAnimator.ofFloat(
|
||||||
normalPeekHeight * peakHeightMultiplier)?.let {
|
normalPeekHeight.toFloat(),
|
||||||
|
normalPeekHeight * peakHeightMultiplier
|
||||||
|
)?.let {
|
||||||
|
|
||||||
it.addUpdateListener {
|
it.addUpdateListener {
|
||||||
quickActionSheetBehavior.peekHeight = (it.animatedValue as Float).toInt()
|
quickActionSheetBehavior.peekHeight = (it.animatedValue as Float).toInt()
|
||||||
@ -88,18 +90,18 @@ class QuickActionSheet @JvmOverloads constructor(
|
|||||||
private val quickActionSheetBehavior: QuickActionSheetBehavior
|
private val quickActionSheetBehavior: QuickActionSheetBehavior
|
||||||
) : View.AccessibilityDelegate() {
|
) : View.AccessibilityDelegate() {
|
||||||
private var finalState = BottomSheetBehavior.STATE_COLLAPSED
|
private var finalState = BottomSheetBehavior.STATE_COLLAPSED
|
||||||
get() = when (quickActionSheetBehavior.state) {
|
get() = when (quickActionSheetBehavior.state) {
|
||||||
BottomSheetBehavior.STATE_EXPANDED,
|
BottomSheetBehavior.STATE_EXPANDED,
|
||||||
BottomSheetBehavior.STATE_HIDDEN,
|
BottomSheetBehavior.STATE_HIDDEN,
|
||||||
BottomSheetBehavior.STATE_COLLAPSED -> {
|
BottomSheetBehavior.STATE_COLLAPSED -> {
|
||||||
quickActionSheetBehavior.state
|
quickActionSheetBehavior.state
|
||||||
|
}
|
||||||
|
else -> field
|
||||||
|
}
|
||||||
|
set(value) {
|
||||||
|
field = value
|
||||||
|
quickActionSheetBehavior.state = value
|
||||||
}
|
}
|
||||||
else -> field
|
|
||||||
}
|
|
||||||
set(value) {
|
|
||||||
field = value
|
|
||||||
quickActionSheetBehavior.state = value
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun performAccessibilityAction(host: View?, action: Int, args: Bundle?): Boolean {
|
override fun performAccessibilityAction(host: View?, action: Int, args: Bundle?): Boolean {
|
||||||
when (action) {
|
when (action) {
|
||||||
@ -123,11 +125,13 @@ class QuickActionSheet @JvmOverloads constructor(
|
|||||||
|
|
||||||
override fun onInitializeAccessibilityNodeInfo(host: View?, info: AccessibilityNodeInfo?) {
|
override fun onInitializeAccessibilityNodeInfo(host: View?, info: AccessibilityNodeInfo?) {
|
||||||
super.onInitializeAccessibilityNodeInfo(host, info)
|
super.onInitializeAccessibilityNodeInfo(host, info)
|
||||||
info?.addAction(when (finalState) {
|
info?.addAction(
|
||||||
BottomSheetBehavior.STATE_COLLAPSED,
|
when (finalState) {
|
||||||
BottomSheetBehavior.STATE_HIDDEN -> AccessibilityNodeInfo.AccessibilityAction.ACTION_EXPAND
|
BottomSheetBehavior.STATE_COLLAPSED,
|
||||||
else -> AccessibilityNodeInfo.AccessibilityAction.ACTION_COLLAPSE
|
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) {
|
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) {
|
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) {
|
} else if (state == STATE_HIDDEN || state == STATE_SETTLING) {
|
||||||
|
peekHeight = handleHeight
|
||||||
state = STATE_COLLAPSED
|
state = STATE_COLLAPSED
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ package org.mozilla.fenix.quickactionsheet
|
|||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import android.widget.ImageButton
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import androidx.core.widget.NestedScrollView
|
import androidx.core.widget.NestedScrollView
|
||||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
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.fragment_browser.*
|
||||||
import kotlinx.android.synthetic.main.layout_quick_action_sheet.*
|
import kotlinx.android.synthetic.main.layout_quick_action_sheet.*
|
||||||
import kotlinx.android.synthetic.main.layout_quick_action_sheet.view.*
|
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.R
|
||||||
import org.mozilla.fenix.components.metrics.Event
|
import org.mozilla.fenix.components.metrics.Event
|
||||||
import org.mozilla.fenix.ext.components
|
import org.mozilla.fenix.ext.components
|
||||||
@ -35,6 +37,11 @@ class QuickActionUIView(
|
|||||||
val quickActionSheetBehavior =
|
val quickActionSheetBehavior =
|
||||||
BottomSheetBehavior.from(nestedScrollQuickAction as View) as 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() {
|
quickActionSheetBehavior.setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
|
||||||
override fun onStateChanged(v: View, state: Int) {
|
override fun onStateChanged(v: View, state: Int) {
|
||||||
updateImportantForAccessibility(state)
|
updateImportantForAccessibility(state)
|
||||||
@ -47,6 +54,8 @@ class QuickActionUIView(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onSlide(bottomSheet: View, slideOffset: Float) {
|
override fun onSlide(bottomSheet: View, slideOffset: Float) {
|
||||||
|
quickActionSheetBehavior.peekHeight =
|
||||||
|
bottomSheet.findViewById<ImageButton>(R.id.quick_action_sheet_handle).height
|
||||||
animateOverlay(slideOffset)
|
animateOverlay(slideOffset)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -80,10 +89,10 @@ class QuickActionUIView(
|
|||||||
|
|
||||||
private fun updateImportantForAccessibility(state: Int) {
|
private fun updateImportantForAccessibility(state: Int) {
|
||||||
view.findViewById<LinearLayout>(R.id.quick_action_buttons_layout).importantForAccessibility =
|
view.findViewById<LinearLayout>(R.id.quick_action_buttons_layout).importantForAccessibility =
|
||||||
if (state == BottomSheetBehavior.STATE_COLLAPSED || state == BottomSheetBehavior.STATE_HIDDEN)
|
if (state == BottomSheetBehavior.STATE_COLLAPSED || state == BottomSheetBehavior.STATE_HIDDEN)
|
||||||
View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
|
View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
|
||||||
else
|
else
|
||||||
View.IMPORTANT_FOR_ACCESSIBILITY_AUTO
|
View.IMPORTANT_FOR_ACCESSIBILITY_AUTO
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun sendTelemetryEvent(state: Int) {
|
private fun sendTelemetryEvent(state: Int) {
|
||||||
@ -99,4 +108,9 @@ class QuickActionUIView(
|
|||||||
view.quick_action_read.visibility = if (it.readable) View.VISIBLE else View.GONE
|
view.quick_action_read.visibility = if (it.readable) View.VISIBLE else View.GONE
|
||||||
view.quick_action_bookmark.isSelected = it.bookmarked
|
view.quick_action_bookmark.isSelected = it.bookmarked
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val initialOverlayAlpha = 0.5f
|
||||||
|
const val initialPeekHeightInDps = 30
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user