Shows or hides shadows based on scroll state

This commit is contained in:
ericdecanini 2022-05-11 11:05:26 +02:00
parent a6564b6466
commit 94e6e1b0d8
2 changed files with 36 additions and 4 deletions

View File

@ -58,6 +58,7 @@ class SpaceListModalFragment : VectorBaseFragment<FragmentSpaceListModalBinding>
super.onViewCreated(view, savedInstanceState)
sharedActionViewModel = activityViewModelProvider.get(HomeSharedActionViewModel::class.java)
setupRecyclerView()
setupTopBar()
setupAddSpace()
setupInvites()
observeSpaceChange()
@ -73,6 +74,18 @@ class SpaceListModalFragment : VectorBaseFragment<FragmentSpaceListModalBinding>
}
}
private fun setupTopBar() {
if (!binding.roomList.canScrollVertically(-1)) {
binding.headerBottomShadow.isVisible = false
binding.addSpaceTopShadow.isVisible = false
binding.addSpaceTopDivider.isVisible = true
} else {
binding.headerBottomShadow.isVisible = true
binding.addSpaceTopShadow.isVisible = true
binding.addSpaceTopDivider.isVisible = false
}
}
private fun setupAddSpace() {
binding.addSpaceLayout.setOnClickListener {
val currentSpace = sharedActionViewModel.space.value
@ -106,12 +119,13 @@ class SpaceListModalFragment : VectorBaseFragment<FragmentSpaceListModalBinding>
override fun invalidate() {
withState(viewModel) { state ->
state.rootSpacesOrdered?.let {
(binding.roomList.adapter as SpaceListAdapter).replaceList(it)
(binding.roomList.adapter as SpaceListAdapter).replaceList(it + it + it)
binding.noSpacesYetGroup.isVisible = it.isEmpty()
}
binding.invitesGroup.isVisible = state.inviteCount > 0
binding.counterBadge.render(UnreadCounterBadgeView.State(state.inviteCount, true))
setupTopBar()
}
}
}

View File

@ -12,7 +12,6 @@
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
android:background="@color/modal_background_color"
android:elevation="4dp"
android:paddingBottom="8dp">
<TextView
@ -76,8 +75,18 @@
app:layout_constraintTop_toBottomOf="@id/header_text_layout"
app:layout_constraintBottom_toTopOf="@id/add_space_layout"
tools:itemCount="3"
tools:visibility="visible"
tools:listitem="@layout/item_modal_space" />
tools:layout_editor_absoluteX="-99dp"
tools:listitem="@layout/item_modal_space"
tools:visibility="visible" />
<View
android:id="@+id/header_bottom_shadow"
android:layout_width="match_parent"
android:layout_height="4dp"
android:background="@drawable/top_shadow"
android:visibility="gone"
android:rotation="180"
app:layout_constraintTop_toBottomOf="@id/header_text_layout" />
<androidx.constraintlayout.widget.Group
android:id="@+id/no_spaces_yet_group"
@ -113,9 +122,18 @@
app:layout_constraintEnd_toEndOf="parent" />
<View
android:id="@+id/add_space_top_shadow"
android:layout_width="match_parent"
android:layout_height="4dp"
android:background="@drawable/top_shadow"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@id/add_space_layout" />
<View
android:id="@+id/add_space_top_divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/vctr_content_quinary"
app:layout_constraintBottom_toTopOf="@id/add_space_layout" />
<androidx.constraintlayout.widget.ConstraintLayout