mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 05:31:21 +03:00
Adds scroll behaviour to FABs
This commit is contained in:
parent
8e7e320e40
commit
406a67827c
1 changed files with 26 additions and 4 deletions
|
@ -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 ->
|
||||
|
|
Loading…
Reference in a new issue