From 406a67827c35ef53c9d1004e1d754f0d14d76b6f Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Fri, 29 Jul 2022 15:48:21 +0200 Subject: [PATCH] Adds scroll behaviour to FABs --- .../room/list/home/HomeRoomListFragment.kt | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListFragment.kt index cc211a31fa..e7882ff36f 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListFragment.kt @@ -20,10 +20,10 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.core.view.isVisible import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.ConcatAdapter import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView import com.airbnb.epoxy.EpoxyControllerAdapter import com.airbnb.epoxy.OnModelBuildFinishedListener import com.airbnb.mvrx.fragmentViewModel @@ -72,7 +72,7 @@ class HomeRoomListFragment @Inject constructor( override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - sharedActionViewModel = activityViewModelProvider.get(RoomListQuickActionsSharedActionViewModel::class.java) + sharedActionViewModel = activityViewModelProvider[RoomListQuickActionsSharedActionViewModel::class.java] sharedActionViewModel .stream() .onEach { handleQuickActions(it) } @@ -111,8 +111,7 @@ class HomeRoomListFragment @Inject constructor( } private fun setupFabs() { - views.newLayoutCreateChatButton.isVisible = true - views.newLayoutOpenSpacesButton.isVisible = true + showFABs() views.newLayoutCreateChatButton.setOnClickListener { // Click action for create chat modal goes here @@ -121,6 +120,29 @@ class HomeRoomListFragment @Inject constructor( views.newLayoutOpenSpacesButton.setOnClickListener { // Click action for open spaces modal goes here } + + // Hide FABs when list is scrolling + views.roomListView.addOnScrollListener(object : RecyclerView.OnScrollListener() { + override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { + views.createChatFabMenu.handler.removeCallbacksAndMessages(null) + + when (newState) { + RecyclerView.SCROLL_STATE_IDLE -> views.createChatFabMenu.postDelayed(::showFABs, 250) + RecyclerView.SCROLL_STATE_DRAGGING, + RecyclerView.SCROLL_STATE_SETTLING -> hideFABs() + } + } + }) + } + + private fun showFABs() { + views.newLayoutCreateChatButton.show() + views.newLayoutOpenSpacesButton.show() + } + + private fun hideFABs() { + views.newLayoutCreateChatButton.hide() + views.newLayoutOpenSpacesButton.hide() } override fun invalidate() = withState(roomListViewModel) { state ->