Add preview for focusedEvent.

This commit is contained in:
Benoit Marty 2024-04-26 14:12:17 +02:00
parent 21ddeb00fe
commit 31946a98ad
4 changed files with 15 additions and 8 deletions

View file

@ -106,6 +106,8 @@ fun aMessagesState(
voiceMessageComposerState: VoiceMessageComposerState = aVoiceMessageComposerState(), voiceMessageComposerState: VoiceMessageComposerState = aVoiceMessageComposerState(),
timelineState: TimelineState = aTimelineState( timelineState: TimelineState = aTimelineState(
timelineItems = aTimelineItemList(aTimelineItemTextContent()), timelineItems = aTimelineItemList(aTimelineItemTextContent()),
// Render a focused event for an event with sender information displayed
focusedEventIndex = 2,
), ),
retrySendMenuState: RetrySendMenuState = aRetrySendMenuState(), retrySendMenuState: RetrySendMenuState = aRetrySendMenuState(),
readReceiptBottomSheetState: ReadReceiptBottomSheetState = aReadReceiptBottomSheetState(), readReceiptBottomSheetState: ReadReceiptBottomSheetState = aReadReceiptBottomSheetState(),

View file

@ -49,6 +49,7 @@ fun aTimelineState(
timelineItems: ImmutableList<TimelineItem> = persistentListOf(), timelineItems: ImmutableList<TimelineItem> = persistentListOf(),
renderReadReceipts: Boolean = false, renderReadReceipts: Boolean = false,
timelineRoomInfo: TimelineRoomInfo = aTimelineRoomInfo(), timelineRoomInfo: TimelineRoomInfo = aTimelineRoomInfo(),
focusedEventIndex: Int = -1,
eventSink: (TimelineEvents) -> Unit = {}, eventSink: (TimelineEvents) -> Unit = {},
) = TimelineState( ) = TimelineState(
timelineItems = timelineItems, timelineItems = timelineItems,
@ -56,7 +57,7 @@ fun aTimelineState(
renderReadReceipts = renderReadReceipts, renderReadReceipts = renderReadReceipts,
newEventState = NewEventState.None, newEventState = NewEventState.None,
isLive = true, isLive = true,
focusedEventId = null, focusedEventId = timelineItems.filterIsInstance<TimelineItem.Event>().getOrNull(focusedEventIndex)?.eventId,
focusRequestState = FocusRequestState.None, focusRequestState = FocusRequestState.None,
eventSink = eventSink, eventSink = eventSink,
) )

View file

@ -265,8 +265,8 @@ private fun BoxScope.TimelineScrollHelper(
// Use inverse of canAutoScroll otherwise we might briefly see the before the scroll animation is triggered // Use inverse of canAutoScroll otherwise we might briefly see the before the scroll animation is triggered
isVisible = !canAutoScroll || forceJumpToBottomVisibility || !isLive, isVisible = !canAutoScroll || forceJumpToBottomVisibility || !isLive,
modifier = Modifier modifier = Modifier
.align(Alignment.BottomEnd) .align(Alignment.BottomEnd)
.padding(end = 24.dp, bottom = 12.dp), .padding(end = 24.dp, bottom = 12.dp),
onClick = { jumpToBottom() }, onClick = { jumpToBottom() },
) )
} }
@ -293,8 +293,8 @@ private fun JumpToBottomButton(
) { ) {
Icon( Icon(
modifier = Modifier modifier = Modifier
.size(24.dp) .size(24.dp)
.rotate(90f), .rotate(90f),
imageVector = CompoundIcons.ArrowRight(), imageVector = CompoundIcons.ArrowRight(),
contentDescription = stringResource(id = CommonStrings.a11y_jump_to_bottom) contentDescription = stringResource(id = CommonStrings.a11y_jump_to_bottom)
) )
@ -312,7 +312,10 @@ internal fun TimelineViewPreview(
LocalTimelineItemPresenterFactories provides aFakeTimelineItemPresenterFactories(), LocalTimelineItemPresenterFactories provides aFakeTimelineItemPresenterFactories(),
) { ) {
TimelineView( TimelineView(
state = aTimelineState(timelineItems), state = aTimelineState(
timelineItems = timelineItems,
focusedEventIndex = 0,
),
typingNotificationState = aTypingNotificationState(), typingNotificationState = aTypingNotificationState(),
onUserDataClicked = {}, onUserDataClicked = {},
onLinkClicked = {}, onLinkClicked = {},

View file

@ -160,12 +160,13 @@ private fun TimelineItemGroupedEventsRowContent(
@PreviewsDayNight @PreviewsDayNight
@Composable @Composable
internal fun TimelineItemGroupedEventsRowContentExpandedPreview() = ElementPreview { internal fun TimelineItemGroupedEventsRowContentExpandedPreview() = ElementPreview {
val events = aGroupedEvents(withReadReceipts = true)
TimelineItemGroupedEventsRowContent( TimelineItemGroupedEventsRowContent(
isExpanded = true, isExpanded = true,
onExpandGroupClick = {}, onExpandGroupClick = {},
timelineItem = aGroupedEvents(withReadReceipts = true), timelineItem = events,
timelineRoomInfo = aTimelineRoomInfo(), timelineRoomInfo = aTimelineRoomInfo(),
focusedEventId = null, focusedEventId = events.events.first().eventId,
renderReadReceipts = true, renderReadReceipts = true,
isLastOutgoingMessage = false, isLastOutgoingMessage = false,
onClick = {}, onClick = {},