Pinned messages banner : adjust indicator to match design.
This commit is contained in:
parent
9bce1156f2
commit
790f694dcc
2 changed files with 63 additions and 57 deletions
|
|
@ -26,14 +26,15 @@ internal class PinnedMessagesBannerStateProvider : PreviewParameterProvider<Pinn
|
||||||
get() = sequenceOf(
|
get() = sequenceOf(
|
||||||
aHiddenPinnedMessagesBannerState(),
|
aHiddenPinnedMessagesBannerState(),
|
||||||
aLoadingPinnedMessagesBannerState(knownPinnedMessagesCount = 1),
|
aLoadingPinnedMessagesBannerState(knownPinnedMessagesCount = 1),
|
||||||
aLoadingPinnedMessagesBannerState(knownPinnedMessagesCount = 4),
|
aLoadingPinnedMessagesBannerState(knownPinnedMessagesCount = 5),
|
||||||
aLoadedPinnedMessagesBannerState(knownPinnedMessagesCount = 1, currentPinnedMessageIndex = 0),
|
aLoadedPinnedMessagesBannerState(knownPinnedMessagesCount = 1, currentPinnedMessageIndex = 0),
|
||||||
aLoadedPinnedMessagesBannerState(knownPinnedMessagesCount = 2, currentPinnedMessageIndex = 0),
|
aLoadedPinnedMessagesBannerState(knownPinnedMessagesCount = 2, currentPinnedMessageIndex = 0),
|
||||||
aLoadedPinnedMessagesBannerState(knownPinnedMessagesCount = 3, currentPinnedMessageIndex = 0),
|
aLoadedPinnedMessagesBannerState(knownPinnedMessagesCount = 3, currentPinnedMessageIndex = 0),
|
||||||
aLoadedPinnedMessagesBannerState(knownPinnedMessagesCount = 4, currentPinnedMessageIndex = 0),
|
aLoadedPinnedMessagesBannerState(knownPinnedMessagesCount = 5, currentPinnedMessageIndex = 0),
|
||||||
aLoadedPinnedMessagesBannerState(knownPinnedMessagesCount = 4, currentPinnedMessageIndex = 1),
|
aLoadedPinnedMessagesBannerState(knownPinnedMessagesCount = 5, currentPinnedMessageIndex = 1),
|
||||||
aLoadedPinnedMessagesBannerState(knownPinnedMessagesCount = 4, currentPinnedMessageIndex = 2),
|
aLoadedPinnedMessagesBannerState(knownPinnedMessagesCount = 5, currentPinnedMessageIndex = 2),
|
||||||
aLoadedPinnedMessagesBannerState(knownPinnedMessagesCount = 4, currentPinnedMessageIndex = 3),
|
aLoadedPinnedMessagesBannerState(knownPinnedMessagesCount = 5, currentPinnedMessageIndex = 3),
|
||||||
|
aLoadedPinnedMessagesBannerState(knownPinnedMessagesCount = 5, currentPinnedMessageIndex = 4),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,10 +29,7 @@ import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.heightIn
|
import androidx.compose.foundation.layout.heightIn
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.layout.width
|
import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
|
||||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
|
||||||
import androidx.compose.runtime.Stable
|
import androidx.compose.runtime.Stable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
|
@ -111,7 +108,6 @@ private fun PinnedMessagesBannerRow(
|
||||||
PinIndicators(
|
PinIndicators(
|
||||||
pinIndex = state.currentPinnedMessageIndex(),
|
pinIndex = state.currentPinnedMessageIndex(),
|
||||||
pinsCount = state.pinnedMessagesCount(),
|
pinsCount = state.pinnedMessagesCount(),
|
||||||
modifier = Modifier.heightIn(max = 40.dp)
|
|
||||||
)
|
)
|
||||||
Icon(
|
Icon(
|
||||||
imageVector = CompoundIcons.PinSolid(),
|
imageVector = CompoundIcons.PinSolid(),
|
||||||
|
|
@ -183,32 +179,41 @@ private fun PinIndicators(
|
||||||
else -> 11
|
else -> 11
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val lazyListState = rememberLazyListState()
|
val activeIndex = remember(pinIndex) {
|
||||||
LaunchedEffect(pinIndex) {
|
pinIndex % 3
|
||||||
val viewportSize = lazyListState.layoutInfo.viewportSize
|
|
||||||
lazyListState.animateScrollToItem(
|
|
||||||
pinIndex,
|
|
||||||
indicatorHeight / 2 - viewportSize.height / 2
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
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,
|
modifier = modifier,
|
||||||
state = lazyListState,
|
verticalArrangement = spacedBy(2.dp)
|
||||||
verticalArrangement = spacedBy(2.dp),
|
|
||||||
userScrollEnabled = false,
|
|
||||||
) {
|
) {
|
||||||
items(pinsCount) { index ->
|
for (index in 0 until indicatorsCount) {
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.width(2.dp)
|
.width(2.dp)
|
||||||
.height(indicatorHeight.dp)
|
.height(indicatorHeight.dp)
|
||||||
.background(
|
.background(
|
||||||
color = if (index == pinIndex) {
|
color = if (index == activeIndex) {
|
||||||
ElementTheme.colors.iconAccentPrimary
|
ElementTheme.colors.iconAccentPrimary
|
||||||
} else {
|
} else if (index < shownIndicators) {
|
||||||
ElementTheme.colors.pinnedMessageBannerIndicator
|
ElementTheme.colors.pinnedMessageBannerIndicator
|
||||||
|
} else {
|
||||||
|
Color.Transparent
|
||||||
}
|
}
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue