[fenix] For https://github.com/mozilla-mobile/fenix/issues/619 - Keep toolbar expanded while page is loading

pull/600/head
Emily Kager 6 years ago committed by Emily Kager
parent 62a755f0d3
commit 8982e69f43

@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- #176 - Added a swipe to delete gesture on home screen
- #1539 - Added bookmarks multi-select related features
- #1603 - Remove deprecated success path for Firefox Accounts login
- #619 - Sets toolbar behavior based on accessibility and if session is loading
### Changed
- #1429 - Updated site permissions ui for MVP

@ -82,6 +82,7 @@ import kotlin.coroutines.CoroutineContext
class BrowserFragment : Fragment(), BackHandler, CoroutineScope {
private lateinit var toolbarComponent: ToolbarComponent
private var sessionObserver: Session.Observer? = null
private val sessionFeature = ViewBoundFeatureWrapper<SessionFeature>()
private val contextMenuFeature = ViewBoundFeatureWrapper<ContextMenuFeature>()
private val downloadsFeature = ViewBoundFeatureWrapper<DownloadsFeature>()
@ -130,14 +131,6 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope {
)
(layoutParams as CoordinatorLayout.LayoutParams).apply {
// Stop toolbar from collapsing if TalkBack is enabled
val accessibilityManager = context
?.getSystemService(Context.ACCESSIBILITY_SERVICE) as AccessibilityManager
if (!accessibilityManager.isTouchExplorationEnabled) {
behavior = BrowserToolbarBottomBehavior(view.context, null)
}
gravity = Gravity.BOTTOM
height = (resources.displayMetrics.density * TOOLBAR_HEIGHT).toInt()
}
@ -289,6 +282,7 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope {
@Suppress("ComplexMethod")
override fun onStart() {
super.onStart()
sessionObserver = subscribeToSession()
getAutoDisposeObservable<SearchAction>()
.subscribe {
when (it) {
@ -370,6 +364,13 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope {
assignSitePermissionsRules()
}
override fun onStop() {
super.onStop()
sessionObserver?.let {
requireComponents.core.sessionManager.selectedSession?.unregister(it)
}
}
override fun onBackPressed(): Boolean {
return when {
findInPageIntegration.onBackPressed() -> true
@ -520,6 +521,34 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope {
clipBoard.primaryClip = ClipData.newRawUri("Uri", uri)
}
private fun subscribeToSession(): Session.Observer {
val observer = object : Session.Observer {
override fun onLoadingStateChanged(session: Session, loading: Boolean) {
super.onLoadingStateChanged(session, loading)
setToolbarBehavior(loading)
}
}
requireComponents.core.sessionManager.selectedSession?.register(observer)
return observer
}
private fun setToolbarBehavior(loading: Boolean) {
val toolbarView = toolbarComponent.uiView.view
(toolbarView.layoutParams as CoordinatorLayout.LayoutParams).apply {
// Stop toolbar from collapsing if TalkBack is enabled or page is loading
val accessibilityManager = context
?.getSystemService(Context.ACCESSIBILITY_SERVICE) as AccessibilityManager
if (!accessibilityManager.isTouchExplorationEnabled) {
if (!loading) {
behavior = BrowserToolbarBottomBehavior(context, null)
} else {
(behavior as? BrowserToolbarBottomBehavior)?.forceExpand(toolbarView)
behavior = null
}
}
}
}
companion object {
private const val REQUEST_CODE_DOWNLOAD_PERMISSIONS = 1
private const val REQUEST_CODE_PROMPT_PERMISSIONS = 2

@ -44,6 +44,10 @@ class BrowserToolbarBottomBehavior(
duration = SNAP_ANIMATION_DURATION
}
fun forceExpand(view: View) {
animateSnap(view, SnapDirection.UP)
}
override fun onStartNestedScroll(
coordinatorLayout: CoordinatorLayout,
child: BrowserToolbar,

Loading…
Cancel
Save