-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] Custom Theme #1473
base: main
Are you sure you want to change the base?
[Feature] Custom Theme #1473
Conversation
app/shared/ui-settings/src/commonMain/kotlin/ui/settings/tabs/theme/ThemePreferences.kt
Outdated
Show resolved
Hide resolved
app/shared/ui-settings/src/commonMain/kotlin/ui/settings/tabs/theme/ThemePreferences.kt
Outdated
Show resolved
Hide resolved
app/shared/ui-settings/src/commonMain/kotlin/ui/settings/tabs/theme/ThemePreferences.kt
Outdated
Show resolved
Hide resolved
app/shared/ui-settings/src/commonMain/kotlin/ui/settings/tabs/theme/ThemePreferences.kt
Outdated
Show resolved
Hide resolved
app/shared/ui-settings/src/commonMain/kotlin/ui/settings/tabs/theme/ThemePreferences.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有没有设置页效果截图? 所有涉及的页面
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
默认是什么颜色?仍然是 M3 紫色吗,我觉得非必要不修改默认色
app/shared/app-data/src/commonMain/kotlin/data/models/preference/ThemeSettings.kt
Outdated
Show resolved
Hide resolved
data class ThemeSettings( | ||
val darkMode: DarkMode = DarkMode.AUTO, | ||
val useDynamicTheme: Boolean = false, // default "true" on Android && Build.VERSION.SDK_INT >= 31 | ||
val isAmoled: Boolean = false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这听起来不对吧, amoled 是设备自己的属性, 应当实时检测, 不是设置. 如果这个的作用是让背景颜色为纯黑, 那就应当用直接的名字例如 useBlackBackgroundColor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
更深层次的原因是,设备是否是 oled 屏和是否使用纯黑背景不是强制绑定的关系,如果我的设备不是 oled 屏但我也想用纯黑背景,那 isAmoled 这个参数名字就不能表示正确的意义
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- StageGuard 说得对。
- 我这个名字取得不好。改成
useTrueBlackTheme
- 推荐在 AMOLED 设备上使用纯黑背景。
- 这玩意对于大多数人没用。纯黑背景对 AMOLED 看起来只是省电。视觉效果肯定是有背景色好看。
综上废弃了。懒得弄,以后再说。
定义这个完全只是因为 rememberDynamicColorScheme
必须传入这个参数
我设置页没放 Switch
@Immutable | ||
data class ThemeSettings( | ||
val darkMode: DarkMode = DarkMode.AUTO, | ||
val useDynamicTheme: Boolean = false, // default "true" on Android && Build.VERSION.SDK_INT >= 31 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
注释与实际默认值不符. 我觉得可以考虑默认 true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
必须默认 false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个设置放在欢迎页里就行了
不过我觉得可以考虑默认 true。优先使用用户系统 Monet 颜色。但是需要判断 on Android && Build.VERSION.SDK_INT >= 31。dynamicThemeSupported
@@ -122,14 +120,15 @@ fun ProvideCompositionLocalsForPreview( | |||
override val lifecycle: Lifecycle get() = TestGlobalLifecycle | |||
} | |||
}, | |||
// TODO: LocalThemeSettings provides themeSettings, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需要实现这个, 否则破坏所有 preview
回答 discussions
|
// Set statusBarStyle & navigationBarStyle | ||
val activity = LocalContext.current.findActivity() as? ComponentActivity | ||
if (activity != null) { | ||
DisposableEffect(activity, isDark) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里有必要吗? MainActivity#onCreate 里已经有了,如果去掉没有影响那就去掉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我也提到了(Discussion needed 3),我觉得可以去掉。你们本来也是有这段代码的。
Him188:
3. Application 里的是为了实现启动时读配置之前的流畅效果; composable 里的才是真正根据设置的深色/浅色设置状态栏.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有必要
app/shared/ui-foundation/src/commonMain/kotlin/ui/foundation/layout/CarouselItem.kt
Outdated
Show resolved
Hide resolved
@@ -252,3 +261,7 @@ data class NavigationMotionScheme( | |||
val LocalNavigationMotionScheme = compositionLocalOf<NavigationMotionScheme> { | |||
error("No LocalNavigationMotionScheme provided") | |||
} | |||
|
|||
val LocalThemeSettings = compositionLocalOf<ThemeSettings> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
目前这个 provider 看起来有很大的问题,会导致所有使用 aniColorTheme
的地方直接强制依赖 LocalThemeSettings
,而 ThemeSettings
是数据层的数据类,最终会导致 ui-foundation
模块又增加了对 app-data
模块的耦合程度。
实际上 ui-foundation
模块不应该有对 app-data
的依赖,未来也会考虑去掉这个,所以目前请不要增加耦合度。
以下为去掉 LocalThemeSettings
的一种思路
- 把上面的
aniColorTheme
和AniTheme
使用的 ThemeSettings 属性直接作为参数传递给 composable,不用担心参数过多
@Composable
expect fun aniColorTheme(
seedColor: Color,
useDynamicScheme: Boolean,
isAmoled: Boolean,
isDark: Boolean = isSystemInDarkTheme()
): ColorScheme
- 查找业务 UI 中所有强制指定亮暗色的地方,例如
MaterialTheme(aniColorTheme(isDark = true))
,改为AniTheme(isDark = true)
,避免直接在业务中使用aniColorTheme
,而是使用AniTheme
- 去掉
LocalThemeSettings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
把上面的 aniColorTheme 和 AniTheme 使用的 ThemeSettings 属性直接作为参数传递给 composable
抱歉没理解这句是什么意思
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
把上面的 aniColorTheme 和 AniTheme 使用的 ThemeSettings 属性直接作为参数传递给 composable
抱歉没理解这句是什么意思
我给了代码示例
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我想问,具体怎么把 ThemeSettings 传递给 composable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
具体怎么把 ThemeSettings 传递给 composable
-
把 AniTheme 里的 DisposableEffect 拿到外面, 例如
@Composable fun SystemBarColorEffect(isDark)
. -
AniTheme 增加参数
isDark: Boolean
.
在AniApp
里有 AniAppViewModel, 可以读配置获取 ThemeSettings. 将根据设置判断是否采用 dark 的逻辑挪到AniApp
里. -
把
aniColorTheme
改成这个结构, 所有参数都直接由函数传入, 不依赖ThemeSettings
.
@Composable
expect fun aniColorTheme(
seedColor: Color,
useDynamicScheme: Boolean,
isAmoled: Boolean,
isDark: Boolean = isSystemInDarkTheme()
): ColorScheme
最终在 AniApp 的以下地方实现默认主题.
animeko/app/shared/src/commonMain/kotlin/ui/main/AniApp.kt
Lines 78 to 80 in 12bec05
MaterialTheme( | |
overrideColorTheme ?: currentPlatformColorTheme(theme.darkMode, theme.dynamicTheme), | |
) { |
例如改成:
val isDark = ...
SystemBarColorEffect(isDark)
AniTheme(isDark) {
....
}
对于那些覆盖主题颜色为深色/浅色的地方, 使用 AniTheme(isDark = true) { }
app/shared/ui-settings/src/commonMain/kotlin/ui/settings/tabs/theme/ThemePreferences.kt
Outdated
Show resolved
Hide resolved
复现方法? |
4585c93
to
1012ab3
Compare
我 100% 复现,你可以在 desktop 模拟更窄的屏幕试试。看你上面的图可以显示完整的 4 个按钮,如果屏幕不够宽或者 DPI 低而没办法显示可能就会有这个问题 |
成功复现。用 |
好了之后 request review 我 |
1b8020e
to
46d2b70
Compare
46d2b70
to
cd64c01
Compare
ci failed 你可以本地跑 ./gradlew check 测试 |
请尽量避免 force push |
#1450
Discussion needed:
APPEARANCE
应该被重命名为UISETTINGS
,APPEARANCE
应该被用作主题页。现在用的是THEME
。AniApp.android.kt
(现在是AppTheme.android.kt
) 的设置系统栏样式的代码有什么作用?MainActivity
中已经有了。删除的话可以合并三个平台的AniTheme
简洁一点Help needed:
ProvideCompositionLocalsForPreview
里如何正确引用我的themeSettings
Known Problems: