Semantic fixes: clearer naming conventions, when statements

This commit is contained in:
Jenna Vassar
2026-05-01 09:01:32 -07:00
parent 78aa500d23
commit 7148f2f28f
3 changed files with 22 additions and 21 deletions
@@ -278,9 +278,10 @@ class TimelinePresenter(
computeNewItemState(timelineItems, prevMostRecentItemId, newEventState) computeNewItemState(timelineItems, prevMostRecentItemId, newEventState)
} }
// Read marker position + unread count, scanned off the main thread. The UI gates display via // Keyed on the full [timelineItems] reference (not just .size) so we re-scan when the
// [displayJumpToUnread]; the values are always computed so the state stays up to date if the // read marker advances in place — the SDK swaps the marker virtual item to a new position
// feature flag flips at runtime. // without changing the list length, e.g. when [markRoomAsFullyRead] is sent while at the
// bottom of the room.
val readMarkerIndex = remember { mutableIntStateOf(-1) } val readMarkerIndex = remember { mutableIntStateOf(-1) }
val unreadMessagesCount = remember { mutableIntStateOf(0) } val unreadMessagesCount = remember { mutableIntStateOf(0) }
LaunchedEffect(timelineItems) { LaunchedEffect(timelineItems) {
@@ -322,15 +322,15 @@ private fun BoxScope.TimelineScrollHelper(
lazyListState.firstVisibleItemIndex < 3 && isLive lazyListState.firstVisibleItemIndex < 3 && isLive
} }
} }
val isReadMarkerOffTop by remember { val isJumpToUnreadVisible by remember {
derivedStateOf { derivedStateOf {
if (!displayJumpToUnread || readMarkerIndex < 0) { when {
false forceJumpToReadMarkerVisibility -> true
} else if (forceJumpToReadMarkerVisibility) { !displayJumpToUnread || readMarkerIndex < 0 -> false
true else -> {
} else { val lastVisibleIndex = lazyListState.layoutInfo.visibleItemsInfo.lastOrNull()?.index ?: return@derivedStateOf false
val lastVisibleIndex = lazyListState.layoutInfo.visibleItemsInfo.lastOrNull()?.index ?: return@derivedStateOf false readMarkerIndex > lastVisibleIndex
readMarkerIndex > lastVisibleIndex }
} }
} }
} }
@@ -402,7 +402,7 @@ private fun BoxScope.TimelineScrollHelper(
} }
} }
TimelineFab( JumpToPositionButton(
icon = CompoundIcons.ChevronDown(), icon = CompoundIcons.ChevronDown(),
contentDescription = stringResource(id = CommonStrings.a11y_jump_to_bottom), contentDescription = stringResource(id = CommonStrings.a11y_jump_to_bottom),
isVisible = isJumpToBottomVisible, isVisible = isJumpToBottomVisible,
@@ -418,10 +418,10 @@ private fun BoxScope.TimelineScrollHelper(
} else { } else {
stringResource(id = CommonStrings.a11y_jump_to_unread_messages) stringResource(id = CommonStrings.a11y_jump_to_unread_messages)
} }
TimelineFab( JumpToPositionButton(
icon = CompoundIcons.ChevronUp(), icon = CompoundIcons.ChevronUp(),
contentDescription = jumpToUnreadDescription, contentDescription = jumpToUnreadDescription,
isVisible = isReadMarkerOffTop, isVisible = isJumpToUnreadVisible,
count = unreadMessagesCount, count = unreadMessagesCount,
// Top padding includes [topInset] so the FAB sits below any pinned-events banner. // Top padding includes [topInset] so the FAB sits below any pinned-events banner.
modifier = Modifier modifier = Modifier
@@ -432,7 +432,7 @@ private fun BoxScope.TimelineScrollHelper(
} }
@Composable @Composable
private fun TimelineFab( private fun JumpToPositionButton(
icon: ImageVector, icon: ImageVector,
contentDescription: String, contentDescription: String,
isVisible: Boolean, isVisible: Boolean,
@@ -480,9 +480,9 @@ private fun TimelineCountBadge(
count: Int, count: Int,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
) { ) {
if (count <= 0) return when {
if (count <= 9) { count <= 0 -> return
Box( count <= 9 -> Box(
modifier = modifier modifier = modifier
.defaultMinSize(minWidth = 16.dp, minHeight = 16.dp) .defaultMinSize(minWidth = 16.dp, minHeight = 16.dp)
.background(color = ElementTheme.colors.bgActionPrimaryRest, shape = CircleShape) .background(color = ElementTheme.colors.bgActionPrimaryRest, shape = CircleShape)
@@ -497,8 +497,7 @@ private fun TimelineCountBadge(
textAlign = TextAlign.Center, textAlign = TextAlign.Center,
) )
} }
} else { else -> Box(
Box(
modifier = modifier modifier = modifier
.size(12.dp) .size(12.dp)
.background(color = ElementTheme.colors.bgActionPrimaryRest, shape = CircleShape) .background(color = ElementTheme.colors.bgActionPrimaryRest, shape = CircleShape)
@@ -592,7 +591,7 @@ internal fun TimelineViewWithReadMarkerNoBadgesPreview() = ElementPreview {
@PreviewsDayNight @PreviewsDayNight
@Composable @Composable
internal fun TimelineViewWithReadMarkerPreview() = ElementPreview { internal fun TimelineViewWithReadMarkerNumericBadgePreview() = ElementPreview {
TimelineViewWithReadMarker(unreadMessagesCount = 3, newMessagesCount = 0) TimelineViewWithReadMarker(unreadMessagesCount = 3, newMessagesCount = 0)
} }
@@ -163,6 +163,7 @@ class KonsistPreviewTest {
"TimelineViewWithReadMarkerBothCountsPreview", "TimelineViewWithReadMarkerBothCountsPreview",
"TimelineViewWithReadMarkerDotBadgesPreview", "TimelineViewWithReadMarkerDotBadgesPreview",
"TimelineViewWithReadMarkerNoBadgesPreview", "TimelineViewWithReadMarkerNoBadgesPreview",
"TimelineViewWithReadMarkerNumericBadgePreview",
"UserAvatarColorsPreview", "UserAvatarColorsPreview",
"UserProfileHeaderSectionWithVerificationViolationPreview", "UserProfileHeaderSectionWithVerificationViolationPreview",
"VoiceItemViewPlayPreview", "VoiceItemViewPlayPreview",