Skip to content

Commit

Permalink
Fix always jumps to the bottom of the timeline #8090
Browse files Browse the repository at this point in the history
  • Loading branch information
ganfra committed Feb 21, 2023
1 parent 6bd150d commit 382abdc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.d/8090.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix timeline always jumps to the bottom when screen goes back to foreground.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.transition.TransitionManager
import com.airbnb.epoxy.EpoxyModel
import com.airbnb.epoxy.EpoxyVisibilityTracker
import com.airbnb.epoxy.OnModelBuildFinishedListener
import com.airbnb.epoxy.addGlidePreloader
import com.airbnb.epoxy.glidePreloader
Expand Down Expand Up @@ -265,6 +266,7 @@ class TimelineFragment :
private val timelineViewModel: TimelineViewModel by fragmentViewModel()
private val messageComposerViewModel: MessageComposerViewModel by fragmentViewModel()
private val debouncer = Debouncer(createUIHandler())
private val itemVisibilityTracker = EpoxyVisibilityTracker()

private lateinit var scrollOnNewMessageCallback: ScrollOnNewMessageCallback
private lateinit var scrollOnHighlightedEventCallback: ScrollOnHighlightedEventCallback
Expand Down Expand Up @@ -972,11 +974,11 @@ class TimelineFragment :

override fun onResume() {
super.onResume()
itemVisibilityTracker.attach(views.timelineRecyclerView)
notificationDrawerManager.setCurrentRoom(timelineArgs.roomId)
notificationDrawerManager.setCurrentThread(timelineArgs.threadTimelineArgs?.rootThreadEventId)
roomDetailPendingActionStore.data?.let { handlePendingAction(it) }
roomDetailPendingActionStore.data = null
views.timelineRecyclerView.adapter = timelineEventController.adapter
}

private fun handlePendingAction(roomDetailPendingAction: RoomDetailPendingAction) {
Expand All @@ -993,9 +995,9 @@ class TimelineFragment :

override fun onPause() {
super.onPause()
itemVisibilityTracker.detach(views.timelineRecyclerView)
notificationDrawerManager.setCurrentRoom(null)
notificationDrawerManager.setCurrentThread(null)
views.timelineRecyclerView.adapter = null
}

private val emojiActivityResultLauncher = registerStartForActivityResult { activityResult ->
Expand Down Expand Up @@ -1038,7 +1040,6 @@ class TimelineFragment :
timelineEventController.callback = this
timelineEventController.timeline = timelineViewModel.timeline

views.timelineRecyclerView.trackItemsVisibilityChange()
layoutManager = object : LinearLayoutManager(requireContext(), RecyclerView.VERTICAL, true) {
override fun onLayoutCompleted(state: RecyclerView.State) {
super.onLayoutCompleted(state)
Expand All @@ -1061,6 +1062,7 @@ class TimelineFragment :
it.dispatchTo(scrollOnHighlightedEventCallback)
}
timelineEventController.addModelBuildListener(modelBuildListener)
views.timelineRecyclerView.adapter = timelineEventController.adapter

if (vectorPreferences.swipeToReplyIsEnabled()) {
val quickReplyHandler = object : RoomMessageTouchHelperCallback.QuickReplayHandler {
Expand Down

0 comments on commit 382abdc

Please sign in to comment.