show/hide fab on scroll
This commit is contained in:
parent
ff4bbf0a8a
commit
2dbe2b5f30
|
@ -26,6 +26,7 @@ import android.view.ViewGroup
|
|||
import androidx.core.text.toSpannable
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.airbnb.epoxy.EpoxyVisibilityTracker
|
||||
import com.airbnb.mvrx.activityViewModel
|
||||
import com.airbnb.mvrx.withState
|
||||
|
@ -83,16 +84,16 @@ class SpaceDirectoryFragment @Inject constructor(
|
|||
bundle.getString(SpaceAddRoomSpaceChooserBottomSheet.BUNDLE_KEY_ACTION)?.let { action ->
|
||||
val spaceId = withState(viewModel) { it.spaceId }
|
||||
when (action) {
|
||||
SpaceAddRoomSpaceChooserBottomSheet.ACTION_ADD_ROOMS -> {
|
||||
SpaceAddRoomSpaceChooserBottomSheet.ACTION_ADD_ROOMS -> {
|
||||
addExistingRoomActivityResult.launch(SpaceManageActivity.newIntent(requireContext(), spaceId, ManageType.AddRooms))
|
||||
}
|
||||
SpaceAddRoomSpaceChooserBottomSheet.ACTION_ADD_SPACES -> {
|
||||
SpaceAddRoomSpaceChooserBottomSheet.ACTION_ADD_SPACES -> {
|
||||
addExistingRoomActivityResult.launch(SpaceManageActivity.newIntent(requireContext(), spaceId, ManageType.AddRoomsOnlySpaces))
|
||||
}
|
||||
SpaceAddRoomSpaceChooserBottomSheet.ACTION_CREATE_ROOM -> {
|
||||
viewModel.handle(SpaceDirectoryViewAction.CreateNewRoom)
|
||||
}
|
||||
else -> {
|
||||
else -> {
|
||||
// nop
|
||||
}
|
||||
}
|
||||
|
@ -125,6 +126,24 @@ class SpaceDirectoryFragment @Inject constructor(
|
|||
|
||||
views.spaceCard.matrixToCardMainButton.isVisible = false
|
||||
views.spaceCard.matrixToCardSecondaryButton.isVisible = false
|
||||
|
||||
// Hide FAB when list is scrolling
|
||||
views.spaceDirectoryList.addOnScrollListener(
|
||||
object : RecyclerView.OnScrollListener() {
|
||||
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
|
||||
views.addOrCreateChatRoomButton.removeCallbacks(showFabRunnable)
|
||||
|
||||
when (newState) {
|
||||
RecyclerView.SCROLL_STATE_IDLE -> {
|
||||
views.addOrCreateChatRoomButton.postDelayed(showFabRunnable, 250)
|
||||
}
|
||||
RecyclerView.SCROLL_STATE_DRAGGING,
|
||||
RecyclerView.SCROLL_STATE_SETTLING -> {
|
||||
views.addOrCreateChatRoomButton.hide()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
|
@ -134,6 +153,12 @@ class SpaceDirectoryFragment @Inject constructor(
|
|||
super.onDestroyView()
|
||||
}
|
||||
|
||||
private val showFabRunnable = Runnable {
|
||||
if (isAdded) {
|
||||
views.addOrCreateChatRoomButton.show()
|
||||
}
|
||||
}
|
||||
|
||||
override fun invalidate() = withState(viewModel) { state ->
|
||||
epoxyController.setData(state)
|
||||
|
||||
|
|
Loading…
Reference in New Issue