用途:在 Jetpack Compose 中应用与定制 CometChat 主题,涵盖颜色方案、排版、形状、深色模式,以及基于 CompositionLocal 的按组件样式覆盖。适用于将 CometChat 组件包裹在 CometChatTheme {} 中、修改主色或配色方案、实现深色模式、定制排版或形状,以及在自定义 composable 中读取主题令牌。若处理 Kotlin Views 主题,应改用 cometchat-android-v6-kotlin-theming;若定制气泡渲染,应改用 cometchat-android-v6-compose-customization。
主要能力:CometChatTheme 是可组合项,通过 CompositionLocalProvider 提供 LocalColorScheme、LocalTypography、LocalShapes。颜色方案支持 lightColorScheme()、darkColorScheme() 及按系统设置自动切换;仅覆盖 primary 时,扩展主色 50–900 会自动重新生成。CometChatColorScheme 包含主色、扩展主色、中性色、提示色(info/success/warning/error/messageRead)、背景色 1–4、描边/边框色、文本色、图标着色、按钮色与静态黑白等令牌组。排版通过 CometChatTheme.typography 访问,形状通过 CometChatTheme.shapes 访问,均可在 CometChatTheme 中传入自定义值。
使用方式:导入 com.cometchat.uikit.compose.theme.CometChatTheme,在 setContent 中包裹组件,例如 CometChatTheme { CometChatConversations() }。深色模式可写 CometChatTheme(colorScheme = if (isSystemInDarkTheme()) darkColorScheme() else lightColorScheme())。自定义主色可写 CometChatTheme(colorScheme = lightColorScheme(primary = Color(0xFF6851D6)))。自定义 composable 中通过 CometChatTheme.colorScheme、CometChatTheme.typography 读取令牌。
限制与硬性规则:所有 CometChat Compose 组件必须包裹在 CometChatTheme {} 中,否则会崩溃或显示异常;不要在 CometChat 组件内使用 Material 的 MaterialTheme 令牌,应使用 CometChatTheme 的 colorScheme、typography、shapes;CometChatTheme 不继承 MaterialTheme,二者是独立主题系统;lightColorScheme() 与 darkColorScheme() 是工厂函数而非数据类构造器,覆盖特定令牌需使用命名参数。