Skip to content

Commit 1e20c6f

Browse files
authored
Align typography and ripple with Figma design tokens (#6347)
* Update typography * Update and simplify ripple configuration
1 parent d2cd803 commit 1e20c6f

10 files changed

Lines changed: 258 additions & 330 deletions

stream-chat-android-compose/api/stream-chat-android-compose.api

Lines changed: 216 additions & 226 deletions
Large diffs are not rendered by default.

stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/theme/ChatTheme.kt

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ package io.getstream.chat.android.compose.ui.theme
2121
import androidx.compose.foundation.isSystemInDarkTheme
2222
import androidx.compose.foundation.layout.Box
2323
import androidx.compose.material3.ExperimentalMaterial3Api
24-
import androidx.compose.material3.LocalContentColor
2524
import androidx.compose.material3.LocalRippleConfiguration
2625
import androidx.compose.runtime.Composable
2726
import androidx.compose.runtime.CompositionLocalProvider
@@ -142,7 +141,6 @@ private val LocalStreamMediaRecorder = compositionLocalOf<StreamMediaRecorder> {
142141
* @param config Central behavioral configuration for the Chat SDK. See [ChatUiConfig].
143142
* @param colors The set of colors we provide, wrapped in [StreamDesign.Colors].
144143
* @param typography The set of typography styles we provide, wrapped in [StreamDesign.Typography].
145-
* @param rippleConfiguration Defines the appearance for ripples.
146144
* @param componentFactory Provide to customize the stateless components that are used throughout the UI.
147145
* @param attachmentPreviewHandlers Attachment preview handlers we provide.
148146
* @param reactionResolver Provides available reactions and resolves reaction types to emoji codes.
@@ -173,13 +171,12 @@ private val LocalStreamMediaRecorder = compositionLocalOf<StreamMediaRecorder> {
173171
public fun ChatTheme(
174172
isInDarkMode: Boolean = isSystemInDarkTheme(),
175173
config: ChatUiConfig = ChatUiConfig(),
176-
colors: StreamDesign.Colors =
177-
if (isInDarkMode) StreamDesign.Colors.defaultDark() else StreamDesign.Colors.default(),
174+
colors: StreamDesign.Colors = if (isInDarkMode) {
175+
StreamDesign.Colors.defaultDark()
176+
} else {
177+
StreamDesign.Colors.default()
178+
},
178179
typography: StreamDesign.Typography = StreamDesign.Typography.default(),
179-
rippleConfiguration: StreamRippleConfiguration = StreamRippleConfiguration.defaultRippleConfiguration(
180-
contentColor = LocalContentColor.current,
181-
lightTheme = !isInDarkMode,
182-
),
183180
componentFactory: ChatComponentFactory = DefaultChatComponentFactory(),
184181
attachmentPreviewHandlers: List<AttachmentPreviewHandler> =
185182
AttachmentPreviewHandler.defaultAttachmentHandlers(LocalContext.current),
@@ -228,12 +225,11 @@ public fun ChatTheme(
228225
}
229226
}
230227

231-
@Suppress("DEPRECATION")
232228
CompositionLocalProvider(
233229
LocalChatUiConfig provides config,
234230
LocalColors provides colors,
235231
LocalTypography provides typography,
236-
LocalRippleConfiguration provides rippleConfiguration.toRippleConfiguration(),
232+
LocalRippleConfiguration provides streamRippleConfiguration(colors, lightTheme = !isInDarkMode),
237233
LocalShimmerTheme provides StreamShimmerTheme,
238234
LocalComponentFactory provides componentFactory,
239235
LocalAttachmentPreviewHandlers provides attachmentPreviewHandlers,

stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/theme/StreamDesign.kt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,7 @@ public object StreamDesign {
865865
* @param headingLarge Style for large, prominent headings.
866866
* @param metadataDefault Style for metadata and secondary information.
867867
* @param metadataEmphasis Style for emphasized metadata in secondary content areas.
868+
* @param numericSmall Style for micro numeric indicators.
868869
* @param numericMedium Style for medium-sized numeric indicators, like the unread count.
869870
* @param numericLarge Style for large numeric indicators.
870871
* @param numericExtraLarge Style for extra-large numeric indicators.
@@ -881,6 +882,7 @@ public object StreamDesign {
881882
public val headingLarge: TextStyle,
882883
public val metadataDefault: TextStyle,
883884
public val metadataEmphasis: TextStyle,
885+
public val numericSmall: TextStyle,
884886
public val numericMedium: TextStyle,
885887
public val numericLarge: TextStyle,
886888
public val numericExtraLarge: TextStyle,
@@ -911,17 +913,17 @@ public object StreamDesign {
911913
fontFamily = fontFamily,
912914
fontWeight = StreamTokens.fontWeightRegular,
913915
fontSize = StreamTokens.fontSizeSm,
914-
lineHeight = StreamTokens.lineHeightTight,
916+
lineHeight = StreamTokens.lineHeightNormal,
915917
),
916918
captionEmphasis = TextStyle(
917919
fontFamily = fontFamily,
918920
fontWeight = StreamTokens.fontWeightSemiBold,
919921
fontSize = StreamTokens.fontSizeSm,
920-
lineHeight = StreamTokens.lineHeightTight,
922+
lineHeight = StreamTokens.lineHeightNormal,
921923
),
922924
headingExtraSmall = TextStyle(
923925
fontFamily = fontFamily,
924-
fontWeight = StreamTokens.fontWeightMedium,
926+
fontWeight = StreamTokens.fontWeightSemiBold,
925927
fontSize = StreamTokens.fontSizeSm,
926928
lineHeight = StreamTokens.lineHeightNormal,
927929
),
@@ -955,22 +957,29 @@ public object StreamDesign {
955957
fontSize = StreamTokens.fontSizeXs,
956958
lineHeight = StreamTokens.lineHeightTight,
957959
),
960+
numericSmall = TextStyle(
961+
fontFamily = fontFamily,
962+
fontWeight = StreamTokens.fontWeightBold,
963+
fontSize = StreamTokens.fontSizeMicro,
964+
lineHeight = StreamTokens.fontSizeMicro,
965+
),
958966
numericMedium = TextStyle(
959967
fontFamily = fontFamily,
960968
fontWeight = StreamTokens.fontWeightBold,
961969
fontSize = StreamTokens.fontSize2xs,
962-
lineHeight = StreamTokens.lineHeightTighter,
970+
lineHeight = StreamTokens.fontSize2xs,
963971
),
964972
numericLarge = TextStyle(
965973
fontFamily = fontFamily,
966974
fontWeight = StreamTokens.fontWeightBold,
967975
fontSize = StreamTokens.fontSizeXs,
976+
lineHeight = StreamTokens.fontSizeXs,
968977
),
969978
numericExtraLarge = TextStyle(
970979
fontFamily = fontFamily,
971980
fontWeight = StreamTokens.fontWeightBold,
972981
fontSize = StreamTokens.fontSizeSm,
973-
lineHeight = StreamTokens.lineHeightTighter,
982+
lineHeight = StreamTokens.fontSizeSm,
974983
),
975984
)
976985
}

stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/theme/StreamRippleConfiguration.kt

Lines changed: 21 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -19,92 +19,26 @@ package io.getstream.chat.android.compose.ui.theme
1919
import androidx.compose.material.ripple.RippleAlpha
2020
import androidx.compose.material3.ExperimentalMaterial3Api
2121
import androidx.compose.material3.RippleConfiguration
22-
import androidx.compose.runtime.Composable
23-
import androidx.compose.ui.graphics.Color
24-
import androidx.compose.ui.graphics.luminance
2522

26-
/**
27-
* Configuration for customizing the ripple effect on the composable components.
28-
*
29-
* @param color The color of the ripple effect.
30-
* @param rippleAlpha The alpha of the ripple effect.
31-
*/
32-
public class StreamRippleConfiguration(
33-
public val color: Color,
34-
public val rippleAlpha: RippleAlpha,
35-
) {
36-
37-
public companion object {
38-
39-
private const val LUMINANCE_THRESHOLD = 0.5
40-
41-
// Note: Values taken from material:RippleDefaults to keep it backwards compatible
42-
private val LightThemeHighContrastRippleAlpha = RippleAlpha(
43-
pressedAlpha = 0.24f,
44-
focusedAlpha = 0.24f,
45-
draggedAlpha = 0.16f,
46-
hoveredAlpha = 0.08f,
47-
)
48-
49-
// Note: Values taken from material:RippleDefaults to keep it backwards compatible
50-
private val LightThemeLowContrastRippleAlpha = RippleAlpha(
51-
pressedAlpha = 0.12f,
52-
focusedAlpha = 0.12f,
53-
draggedAlpha = 0.08f,
54-
hoveredAlpha = 0.04f,
55-
)
56-
57-
// Note: Values taken from material:RippleDefaults to keep it backwards compatible
58-
private val DarkThemeRippleAlpha = RippleAlpha(
59-
pressedAlpha = 0.10f,
60-
focusedAlpha = 0.12f,
61-
draggedAlpha = 0.08f,
62-
hoveredAlpha = 0.04f,
63-
)
64-
65-
/**
66-
* Creates the default [StreamRippleConfiguration].
67-
*
68-
* @param contentColor The current content color.
69-
* @param lightTheme Indicator if the system is in light theme.
70-
*/
71-
@Composable
72-
public fun defaultRippleConfiguration(contentColor: Color, lightTheme: Boolean): StreamRippleConfiguration =
73-
StreamRippleConfiguration(
74-
color = rippleColor(contentColor, lightTheme),
75-
rippleAlpha = rippleAlpha(contentColor, lightTheme),
76-
)
77-
78-
private fun rippleColor(contentColor: Color, lightTheme: Boolean): Color {
79-
val contentLuminance = contentColor.luminance()
80-
return if (!lightTheme && contentLuminance < LUMINANCE_THRESHOLD) {
81-
Color.White
82-
} else {
83-
contentColor
84-
}
85-
}
86-
87-
private fun rippleAlpha(contentColor: Color, lightTheme: Boolean): RippleAlpha {
88-
return when {
89-
lightTheme -> {
90-
if (contentColor.luminance() > LUMINANCE_THRESHOLD) {
91-
LightThemeHighContrastRippleAlpha
92-
} else {
93-
LightThemeLowContrastRippleAlpha
94-
}
95-
}
96-
else -> {
97-
DarkThemeRippleAlpha
98-
}
99-
}
100-
}
101-
}
102-
}
103-
104-
/**
105-
* Maps a [StreamRippleConfiguration] to the android [RippleConfiguration].
106-
* Used to hide the internal implementation of the ripple configuration, and not expose it outside of [ChatTheme].
107-
*/
10823
@OptIn(ExperimentalMaterial3Api::class)
109-
internal fun StreamRippleConfiguration.toRippleConfiguration(): RippleConfiguration =
110-
RippleConfiguration(color = color, rippleAlpha = rippleAlpha)
24+
internal fun streamRippleConfiguration(
25+
colors: StreamDesign.Colors,
26+
lightTheme: Boolean,
27+
): RippleConfiguration = RippleConfiguration(
28+
color = if (lightTheme) colors.chrome.s900 else colors.chrome.s1000,
29+
rippleAlpha = if (lightTheme) LightRippleAlpha else DarkRippleAlpha,
30+
)
31+
32+
private val LightRippleAlpha = RippleAlpha(
33+
pressedAlpha = 0.15f,
34+
focusedAlpha = 0.15f,
35+
draggedAlpha = 0.10f,
36+
hoveredAlpha = 0.10f,
37+
)
38+
39+
private val DarkRippleAlpha = RippleAlpha(
40+
pressedAlpha = 0.20f,
41+
focusedAlpha = 0.20f,
42+
draggedAlpha = 0.15f,
43+
hoveredAlpha = 0.15f,
44+
)

stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/theme/StreamTokens.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,13 @@ internal object StreamTokens {
5151
val fontWeightSemiBold = FontWeight.SemiBold
5252
val fontWeightMedium = FontWeight.Medium
5353
val fontWeightRegular = FontWeight.Normal
54+
val fontSizeMicro = 8.sp
5455
val fontSize2xs = 10.sp
5556
val fontSizeXs = 12.sp
5657
val fontSizeSm = 14.sp
5758
val fontSizeMd = 16.sp
5859
val fontSizeLg = 18.sp
5960
val fontSizeXl = 20.sp
60-
val lineHeightTightest = 10.sp
61-
val lineHeightTighter = 14.sp
6261
val lineHeightTight = 16.sp
6362
val lineHeightNormal = 20.sp
6463
val lineHeightRelaxed = 24.sp
Loading
Loading
Loading
Loading
285 Bytes
Loading

0 commit comments

Comments
 (0)