Skip to content

Commit a41414f

Browse files
fix(compose): scale online indicator dynamically for large avatars
The 96dp avatar in channel info screens used ExtraLarge indicator dimensions (designed for 64dp), making the dot proportionally small. - Convert OnlineIndicatorDimensions from enum to data class - Scale indicator size proportionally for avatars > 64dp - 96dp avatar now gets 24dp indicator (1.5x scale) instead of 16dp
1 parent 09748a2 commit a41414f

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/components/avatar/OnlineIndicator.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ internal fun OnlineIndicator(
5050
)
5151
}
5252

53-
internal enum class OnlineIndicatorDimensions(val indicatorSize: Dp, val borderWidth: Dp, val offset: Dp) {
54-
Small(indicatorSize = 8.dp, borderWidth = 1.dp, offset = 1.dp),
55-
Medium(indicatorSize = 12.dp, borderWidth = 2.dp, offset = 2.dp),
56-
Large(indicatorSize = 14.dp, borderWidth = 2.dp, offset = 2.dp),
57-
ExtraLarge(indicatorSize = 16.dp, borderWidth = 2.dp, offset = 0.dp),
53+
internal data class OnlineIndicatorDimensions(val indicatorSize: Dp, val borderWidth: Dp, val offset: Dp) {
54+
companion object {
55+
val Small = OnlineIndicatorDimensions(indicatorSize = 8.dp, borderWidth = 1.dp, offset = 1.dp)
56+
val Medium = OnlineIndicatorDimensions(indicatorSize = 12.dp, borderWidth = 2.dp, offset = 2.dp)
57+
val Large = OnlineIndicatorDimensions(indicatorSize = 14.dp, borderWidth = 2.dp, offset = 2.dp)
58+
val ExtraLarge = OnlineIndicatorDimensions(indicatorSize = 16.dp, borderWidth = 2.dp, offset = 0.dp)
59+
}
5860
}

stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/components/avatar/UserAvatar.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ public fun UserAvatar(
8585
}
8686

8787
internal fun BoxWithConstraintsScope.resolveIndicatorDimensions(): OnlineIndicatorDimensions = when {
88+
maxWidth > AvatarSize.ExtraExtraLarge -> {
89+
val scale = maxWidth / AvatarSize.ExtraExtraLarge
90+
val base = OnlineIndicatorDimensions.ExtraLarge
91+
OnlineIndicatorDimensions(
92+
indicatorSize = base.indicatorSize * scale,
93+
borderWidth = base.borderWidth,
94+
offset = base.offset,
95+
)
96+
}
8897
maxWidth >= AvatarSize.ExtraExtraLarge -> OnlineIndicatorDimensions.ExtraLarge
8998
maxWidth >= AvatarSize.ExtraLarge -> OnlineIndicatorDimensions.ExtraLarge
9099
maxWidth >= AvatarSize.Large -> OnlineIndicatorDimensions.Large

0 commit comments

Comments
 (0)