Use animation to hide/show fab (#6385)

This commit is contained in:
Ivan Iskandar 2021-12-26 23:38:35 +07:00 committed by GitHub
parent 733cf99bb4
commit 4c8f5e1f7a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 10 deletions

View file

@ -159,13 +159,12 @@ open class BrowseSourceController(bundle: Bundle) :
) )
filterSheet?.setFilters(presenter.filterItems) filterSheet?.setFilters(presenter.filterItems)
// TODO: [ExtendedFloatingActionButton] hide/show methods don't work properly filterSheet?.setOnShowListener { actionFab?.hide() }
filterSheet?.setOnShowListener { actionFab?.isVisible = false } filterSheet?.setOnDismissListener { actionFab?.show() }
filterSheet?.setOnDismissListener { actionFab?.isVisible = true }
actionFab?.setOnClickListener { filterSheet?.show() } actionFab?.setOnClickListener { filterSheet?.show() }
actionFab?.isVisible = true actionFab?.show()
} }
override fun configureFab(fab: ExtendedFloatingActionButton) { override fun configureFab(fab: ExtendedFloatingActionButton) {
@ -175,7 +174,7 @@ open class BrowseSourceController(bundle: Bundle) :
fab.setIconResource(R.drawable.ic_filter_list_24dp) fab.setIconResource(R.drawable.ic_filter_list_24dp)
// Controlled by initFilterSheet() // Controlled by initFilterSheet()
fab.isVisible = false fab.hide()
initFilterSheet() initFilterSheet()
} }

View file

@ -562,12 +562,13 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
binding.tabs.isVisible = to is TabbedController binding.tabs.isVisible = to is TabbedController
if (from is FabController) { if (from is FabController) {
binding.fabLayout.rootFab.isVisible = false
from.cleanupFab(binding.fabLayout.rootFab) from.cleanupFab(binding.fabLayout.rootFab)
} }
if (to is FabController) { if (to is FabController) {
binding.fabLayout.rootFab.isVisible = true binding.fabLayout.rootFab.show()
to.configureFab(binding.fabLayout.rootFab) to.configureFab(binding.fabLayout.rootFab)
} else {
binding.fabLayout.rootFab.hide()
} }
if (!isTablet()) { if (!isTablet()) {

View file

@ -303,7 +303,7 @@ class MangaController :
actionFabScrollListener = actionFab?.shrinkOnScroll(chapterRecycler) actionFabScrollListener = actionFab?.shrinkOnScroll(chapterRecycler)
// Initially set FAB invisible; will become visible if unread chapters are present // Initially set FAB invisible; will become visible if unread chapters are present
actionFab?.isVisible = false actionFab?.hide()
binding.swipeRefresh.refreshes() binding.swipeRefresh.refreshes()
.onEach { .onEach {

View file

@ -125,7 +125,7 @@ class ClearDatabaseController :
override fun configureFab(fab: ExtendedFloatingActionButton) { override fun configureFab(fab: ExtendedFloatingActionButton) {
fab.setIconResource(R.drawable.ic_delete_24dp) fab.setIconResource(R.drawable.ic_delete_24dp)
fab.setText(R.string.action_delete) fab.setText(R.string.action_delete)
fab.isVisible = false fab.hide()
fab.setOnClickListener { fab.setOnClickListener {
val ctrl = ClearDatabaseSourcesDialog() val ctrl = ClearDatabaseSourcesDialog()
ctrl.targetController = this ctrl.targetController = this
@ -136,7 +136,11 @@ class ClearDatabaseController :
private fun updateFab() { private fun updateFab() {
val adapter = adapter ?: return val adapter = adapter ?: return
actionFab?.isVisible = adapter.selectedItemCount > 0 if (adapter.selectedItemCount > 0) {
actionFab?.show()
} else {
actionFab?.hide()
}
} }
override fun cleanupFab(fab: ExtendedFloatingActionButton) { override fun cleanupFab(fab: ExtendedFloatingActionButton) {