Skip to content

Commit

Permalink
Merge pull request #3772 from Bnyro/master
Browse files Browse the repository at this point in the history
Fix crash in CommentsMainFragment
  • Loading branch information
Bnyro committed May 15, 2023
2 parents 04c9b94 + 5b6b1a3 commit d95b5e9
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ class CommentsMainFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

val binding = _binding ?: return
val layoutManager = LinearLayoutManager(requireContext())
binding.commentsRV.layoutManager = layoutManager
binding.commentsRV.setItemViewCacheSize(20)

binding.commentsRV.viewTreeObserver.addOnScrollChangedListener {
val binding = _binding ?: return@addOnScrollChangedListener
val viewBinding = _binding ?: return@addOnScrollChangedListener
// save the last scroll position to become used next time when the sheet is opened
viewModel.currentCommentsPosition = layoutManager.findFirstVisibleItemPosition()

Expand All @@ -48,11 +49,11 @@ class CommentsMainFragment : Fragment() {
commentsSheetBinding?.btnScrollToTop?.isVisible = viewModel.currentCommentsPosition != 0
commentsSheetBinding?.btnScrollToTop?.setOnClickListener {
// scroll back to the top / first comment
binding.commentsRV.smoothScrollToPosition(0)
viewBinding.commentsRV.smoothScrollToPosition(0)
viewModel.currentCommentsPosition = 0
}

if (!binding.commentsRV.canScrollVertically(1)) {
if (!viewBinding.commentsRV.canScrollVertically(1)) {
viewModel.fetchNextComments()
}
}
Expand Down

0 comments on commit d95b5e9

Please sign in to comment.