diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/pinned/banner/PinnedMessagesBannerStateProvider.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/pinned/banner/PinnedMessagesBannerStateProvider.kt index e9d0a27c16..358872ca7f 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/pinned/banner/PinnedMessagesBannerStateProvider.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/pinned/banner/PinnedMessagesBannerStateProvider.kt @@ -26,14 +26,15 @@ internal class PinnedMessagesBannerStateProvider : PreviewParameterProvider 11 } } - val lazyListState = rememberLazyListState() - LaunchedEffect(pinIndex) { - val viewportSize = lazyListState.layoutInfo.viewportSize - lazyListState.animateScrollToItem( - pinIndex, - indicatorHeight / 2 - viewportSize.height / 2 - ) + val activeIndex = remember(pinIndex) { + pinIndex % 3 } - LazyColumn( + val shownIndicators = remember(pinsCount, pinIndex) { + if (pinsCount <= 3) { + pinsCount + } else { + val isLastPage = pinIndex >= pinsCount - pinsCount % 3 + if (isLastPage) { + pinsCount % 3 + } else { + 3 + } + } + } + val indicatorsCount = pinsCount.coerceAtMost(3) + + Column( modifier = modifier, - state = lazyListState, - verticalArrangement = spacedBy(2.dp), - userScrollEnabled = false, + verticalArrangement = spacedBy(2.dp) ) { - items(pinsCount) { index -> + for (index in 0 until indicatorsCount) { Box( modifier = Modifier - .width(2.dp) - .height(indicatorHeight.dp) - .background( - color = if (index == pinIndex) { - ElementTheme.colors.iconAccentPrimary - } else { - ElementTheme.colors.pinnedMessageBannerIndicator - } - ) + .width(2.dp) + .height(indicatorHeight.dp) + .background( + color = if (index == activeIndex) { + ElementTheme.colors.iconAccentPrimary + } else if (index < shownIndicators) { + ElementTheme.colors.pinnedMessageBannerIndicator + } else { + Color.Transparent + } + ), ) } }