Timeline permalink : scroll to fetched event when known
This commit is contained in:
parent
b46f8a5c27
commit
82d833b434
4 changed files with 15 additions and 9 deletions
|
|
@ -146,7 +146,7 @@ class TimelinePresenter @AssistedInject constructor(
|
||||||
timelineController.focusOnEvent(event.eventId)
|
timelineController.focusOnEvent(event.eventId)
|
||||||
.fold(
|
.fold(
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
focusRequestState.value = FocusRequestState.None
|
focusRequestState.value = FocusRequestState.Fetched
|
||||||
},
|
},
|
||||||
onFailure = {
|
onFailure = {
|
||||||
focusRequestState.value = FocusRequestState.Failure(it)
|
focusRequestState.value = FocusRequestState.Failure(it)
|
||||||
|
|
@ -165,15 +165,20 @@ class TimelinePresenter @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Makes sure to get back to live when there is nothing more to load forwards
|
|
||||||
LaunchedEffect(isLive) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
LaunchedEffect(timelineItems.size) {
|
LaunchedEffect(timelineItems.size) {
|
||||||
computeNewItemState(timelineItems, prevMostRecentItemId, newEventState)
|
computeNewItemState(timelineItems, prevMostRecentItemId, newEventState)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LaunchedEffect(timelineItems.size, focusRequestState.value, focusedEventId.value) {
|
||||||
|
val currentFocusedEventId = focusedEventId.value
|
||||||
|
if (focusRequestState.value is FocusRequestState.Fetched && currentFocusedEventId != null) {
|
||||||
|
if (timelineItemIndexer.isKnown(currentFocusedEventId)) {
|
||||||
|
val index = timelineItemIndexer.indexOf(currentFocusedEventId)
|
||||||
|
focusRequestState.value = FocusRequestState.Cached(index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
combine(timelineController.timelineItems(), room.membersStateFlow) { items, membersState ->
|
combine(timelineController.timelineItems(), room.membersStateFlow) { items, membersState ->
|
||||||
timelineItemsFactory.replaceWith(
|
timelineItemsFactory.replaceWith(
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ sealed interface FocusRequestState {
|
||||||
data object None : FocusRequestState
|
data object None : FocusRequestState
|
||||||
data class Cached(val index: Int): FocusRequestState
|
data class Cached(val index: Int): FocusRequestState
|
||||||
data object Fetching : FocusRequestState
|
data object Fetching : FocusRequestState
|
||||||
|
data object Fetched: FocusRequestState
|
||||||
data class Failure(val throwable: Throwable) : FocusRequestState
|
data class Failure(val throwable: Throwable) : FocusRequestState
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -195,7 +195,7 @@ private fun FocusRequestStateView(
|
||||||
FocusRequestState.Fetching -> {
|
FocusRequestState.Fetching -> {
|
||||||
ProgressDialog(modifier = modifier, onDismissRequest = onClearFocusRequestState)
|
ProgressDialog(modifier = modifier, onDismissRequest = onClearFocusRequestState)
|
||||||
}
|
}
|
||||||
is FocusRequestState.Cached, FocusRequestState.None -> Unit
|
else -> Unit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -237,7 +237,7 @@ private fun BoxScope.TimelineScrollHelper(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LaunchedEffect(key1 = focusRequestState) {
|
LaunchedEffect(focusRequestState) {
|
||||||
if (focusRequestState is FocusRequestState.Cached) {
|
if (focusRequestState is FocusRequestState.Cached) {
|
||||||
if (abs(lazyListState.firstVisibleItemIndex - focusRequestState.index) < 10) {
|
if (abs(lazyListState.firstVisibleItemIndex - focusRequestState.index) < 10) {
|
||||||
lazyListState.animateScrollToItem(focusRequestState.index)
|
lazyListState.animateScrollToItem(focusRequestState.index)
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ fun TimelineItemVirtualRow(
|
||||||
TimelineItemRoomBeginningModel -> TimelineItemRoomBeginningView(roomName = timelineRoomInfo.name)
|
TimelineItemRoomBeginningModel -> TimelineItemRoomBeginningView(roomName = timelineRoomInfo.name)
|
||||||
is TimelineItemLoadingIndicatorModel -> {
|
is TimelineItemLoadingIndicatorModel -> {
|
||||||
TimelineLoadingMoreIndicator()
|
TimelineLoadingMoreIndicator()
|
||||||
LaunchedEffect(key1 = virtual.model.timestamp) {
|
LaunchedEffect(virtual.model.timestamp) {
|
||||||
eventSink(TimelineEvents.LoadMore(virtual.model.direction))
|
eventSink(TimelineEvents.LoadMore(virtual.model.direction))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue