Timeline : rename isTimelineEmpty to hasAnyEvent

This commit is contained in:
ganfra 2024-04-25 15:13:19 +02:00
parent 7b07adc5ab
commit b46f8a5c27
2 changed files with 5 additions and 7 deletions

View file

@ -33,7 +33,7 @@ data class TimelineState(
val focusRequestState: FocusRequestState, val focusRequestState: FocusRequestState,
val eventSink: (TimelineEvents) -> Unit, val eventSink: (TimelineEvents) -> Unit,
){ ){
val isTimelineEmpty = timelineItems.none { it is TimelineItem.Event } val hasAnyEvent = timelineItems.any { it is TimelineItem.Event }
} }
sealed interface FocusRequestState { sealed interface FocusRequestState {

View file

@ -19,7 +19,6 @@
package io.element.android.features.messages.impl.timeline package io.element.android.features.messages.impl.timeline
import android.view.accessibility.AccessibilityManager import android.view.accessibility.AccessibilityManager
import androidx.activity.compose.BackHandler
import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.ExperimentalAnimationApi import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.animation.core.tween import androidx.compose.animation.core.tween
@ -75,7 +74,6 @@ import io.element.android.libraries.matrix.api.core.EventId
import io.element.android.libraries.matrix.api.core.UserId import io.element.android.libraries.matrix.api.core.UserId
import io.element.android.libraries.ui.strings.CommonStrings import io.element.android.libraries.ui.strings.CommonStrings
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import timber.log.Timber
import kotlin.math.abs import kotlin.math.abs
@Composable @Composable
@ -166,7 +164,7 @@ fun TimelineView(
) )
TimelineScrollHelper( TimelineScrollHelper(
isTimelineEmpty = state.isTimelineEmpty, hasAnyEvent = state.hasAnyEvent,
lazyListState = lazyListState, lazyListState = lazyListState,
forceJumpToBottomVisibility = forceJumpToBottomVisibility, forceJumpToBottomVisibility = forceJumpToBottomVisibility,
newEventState = state.newEventState, newEventState = state.newEventState,
@ -203,7 +201,7 @@ private fun FocusRequestStateView(
@Composable @Composable
private fun BoxScope.TimelineScrollHelper( private fun BoxScope.TimelineScrollHelper(
isTimelineEmpty: Boolean, hasAnyEvent: Boolean,
lazyListState: LazyListState, lazyListState: LazyListState,
newEventState: NewEventState, newEventState: NewEventState,
isLive: Boolean, isLive: Boolean,
@ -258,8 +256,8 @@ private fun BoxScope.TimelineScrollHelper(
} }
val latestOnScrollFinishedAt by rememberUpdatedState(onScrollFinishedAt) val latestOnScrollFinishedAt by rememberUpdatedState(onScrollFinishedAt)
LaunchedEffect(isScrollFinished, isTimelineEmpty) { LaunchedEffect(isScrollFinished, hasAnyEvent) {
if (isScrollFinished && !isTimelineEmpty) { if (isScrollFinished && hasAnyEvent) {
// Notify the parent composable about the first visible item index when scrolling finishes // Notify the parent composable about the first visible item index when scrolling finishes
latestOnScrollFinishedAt(lazyListState.firstVisibleItemIndex) latestOnScrollFinishedAt(lazyListState.firstVisibleItemIndex)
} }