diff --git a/flexiui-core/src/androidMain/kotlin/com/highcapable/flexiui/Colors.android.kt b/flexiui-core/src/androidMain/kotlin/com/highcapable/flexiui/Colors.android.kt new file mode 100644 index 0000000..030c09e --- /dev/null +++ b/flexiui-core/src/androidMain/kotlin/com/highcapable/flexiui/Colors.android.kt @@ -0,0 +1,83 @@ +/* + * Flexi UI - A flexible and useful UI component library. + * Copyright (C) 2019-2023 HighCapable + * https://github.com/BetterAndroid/FlexiUI + * + * Apache License Version 2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This file is created by fankes on 2023/11/18. + */ +@file:Suppress("unused") + +package com.highcapable.flexiui + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.ReadOnlyComposable +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.platform.LocalContext +import com.highcapable.betterandroid.ui.extension.component.feature.SystemColors + +internal actual val DynamicLightColors + @Composable + @ReadOnlyComposable + get() = if (SystemColors.isAvailable) Colors( + backgroundPrimary = Color(DynamicColors.materialDynamicNeutral(95)), + backgroundSecondary = Color(DynamicColors.materialDynamicNeutral(90)), + foregroundPrimary = Color(DynamicColors.materialDynamicNeutral(99)), + foregroundSecondary = Color(DynamicColors.materialDynamicNeutral(95)), + themePrimary = Color(DynamicColors.materialDynamicPrimary(60)), + themeSecondary = Color(DynamicColors.materialDynamicPrimary(60)).copy(alpha = 0.65f), + themeTertiary = Color(DynamicColors.materialDynamicNeutral(60)).copy(alpha = 0.15f), + textPrimary = DefaultLightColors.textPrimary, + textSecondary = DefaultLightColors.textSecondary, + isLight = true + ) else DefaultLightColors + +internal actual val DynamicDarkColors + @Composable + @ReadOnlyComposable + get() = if (SystemColors.isAvailable) Colors( + backgroundPrimary = Color(DynamicColors.materialDynamicNeutral(10)), + backgroundSecondary = Color(DynamicColors.materialDynamicNeutral(20)), + foregroundPrimary = Color(DynamicColors.materialDynamicNeutral(20)), + foregroundSecondary = Color(DynamicColors.materialDynamicNeutral(30)), + themePrimary = Color(DynamicColors.materialDynamicSecondary(60)), + themeSecondary = Color(DynamicColors.materialDynamicSecondary(60)).copy(alpha = 0.65f), + themeTertiary = Color(DynamicColors.materialDynamicSecondary(60)).copy(alpha = 0.25f), + textPrimary = DefaultDarkColors.textPrimary, + textSecondary = DefaultDarkColors.textSecondary, + isLight = false + ) else DefaultDarkColors + +internal actual val DynamicBlackColors + @Composable + @ReadOnlyComposable + get() = if (SystemColors.isAvailable) Colors( + backgroundPrimary = Color(DynamicColors.materialDynamicNeutral(0)), + backgroundSecondary = Color(DynamicColors.materialDynamicNeutral(0)), + foregroundPrimary = Color(DynamicColors.materialDynamicNeutral(10)), + foregroundSecondary = Color(DynamicColors.materialDynamicNeutral(20)), + themePrimary = Color(DynamicColors.materialDynamicSecondary(60)), + themeSecondary = Color(DynamicColors.materialDynamicSecondary(60)).copy(alpha = 0.65f), + themeTertiary = Color(DynamicColors.materialDynamicSecondary(60)).copy(alpha = 0.27f), + textPrimary = DefaultBlackColors.textPrimary, + textSecondary = DefaultBlackColors.textSecondary, + isLight = false + ) else DefaultBlackColors + +private val DynamicColors + @Composable + @ReadOnlyComposable + get() = SystemColors.from(LocalContext.current) \ No newline at end of file diff --git a/flexiui-core/src/commonMain/kotlin/com/highcapable/flexiui/Colors.kt b/flexiui-core/src/commonMain/kotlin/com/highcapable/flexiui/Colors.kt index 7027a89..6c1724e 100644 --- a/flexiui-core/src/commonMain/kotlin/com/highcapable/flexiui/Colors.kt +++ b/flexiui-core/src/commonMain/kotlin/com/highcapable/flexiui/Colors.kt @@ -23,12 +23,12 @@ package com.highcapable.flexiui +import androidx.compose.runtime.Composable +import androidx.compose.runtime.ReadOnlyComposable import androidx.compose.runtime.Stable import androidx.compose.runtime.staticCompositionLocalOf import androidx.compose.ui.graphics.Color -// TODO: Dynamic colors support - @Stable data class Colors( var backgroundPrimary: Color, @@ -43,7 +43,19 @@ data class Colors( var isLight: Boolean ) -private val DefaultLightColors = Colors( +@get:Composable +@get:ReadOnlyComposable +internal expect val DynamicLightColors: Colors + +@get:Composable +@get:ReadOnlyComposable +internal expect val DynamicDarkColors: Colors + +@get:Composable +@get:ReadOnlyComposable +internal expect val DynamicBlackColors: Colors + +internal val DefaultLightColors = Colors( backgroundPrimary = Color(0xFFF5F5F5), backgroundSecondary = Color(0xFFEDEDED), foregroundPrimary = Color(0xFFFFFFFF), @@ -56,7 +68,7 @@ private val DefaultLightColors = Colors( isLight = true ) -private val DefaultDarkColors = Colors( +internal val DefaultDarkColors = Colors( backgroundPrimary = Color(0xFF2D2D2D), backgroundSecondary = Color(0xFF484848), foregroundPrimary = Color(0xFF474747), @@ -69,7 +81,7 @@ private val DefaultDarkColors = Colors( isLight = false ) -private val DefaultBlackColors = Colors( +internal val DefaultBlackColors = Colors( backgroundPrimary = Color(0xFF000000), backgroundSecondary = Color(0xFF1B1B1B), foregroundPrimary = Color(0xFF1A1A1A), @@ -355,6 +367,13 @@ private val BlueBlackColors = Colors( isLight = false ) +@Composable +@ReadOnlyComposable +fun dynamicColors(darkMode: Boolean = false, blackDarkMode: Boolean = false) = when { + darkMode -> if (blackDarkMode) DynamicBlackColors else DynamicDarkColors + else -> DynamicLightColors +} + fun defaultColors(darkMode: Boolean = false, blackDarkMode: Boolean = false) = when { darkMode -> if (blackDarkMode) DefaultBlackColors else DefaultDarkColors else -> DefaultLightColors diff --git a/flexiui-core/src/desktopMain/kotlin/com/highcapable/flexiui/Colors.desktop.kt b/flexiui-core/src/desktopMain/kotlin/com/highcapable/flexiui/Colors.desktop.kt new file mode 100644 index 0000000..9e0477c --- /dev/null +++ b/flexiui-core/src/desktopMain/kotlin/com/highcapable/flexiui/Colors.desktop.kt @@ -0,0 +1,30 @@ +/* + * Flexi UI - A flexible and useful UI component library. + * Copyright (C) 2019-2023 HighCapable + * https://github.com/BetterAndroid/FlexiUI + * + * Apache License Version 2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This file is created by fankes on 2023/11/18. + */ +@file:Suppress("unused") + +package com.highcapable.flexiui + +internal actual val DynamicLightColors = DefaultLightColors + +internal actual val DynamicDarkColors = DefaultDarkColors + +internal actual val DynamicBlackColors = DefaultBlackColors \ No newline at end of file diff --git a/flexiui-core/src/iosMain/kotlin/com/highcapable/flexiui/Colors.ios.kt b/flexiui-core/src/iosMain/kotlin/com/highcapable/flexiui/Colors.ios.kt new file mode 100644 index 0000000..9e0477c --- /dev/null +++ b/flexiui-core/src/iosMain/kotlin/com/highcapable/flexiui/Colors.ios.kt @@ -0,0 +1,30 @@ +/* + * Flexi UI - A flexible and useful UI component library. + * Copyright (C) 2019-2023 HighCapable + * https://github.com/BetterAndroid/FlexiUI + * + * Apache License Version 2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This file is created by fankes on 2023/11/18. + */ +@file:Suppress("unused") + +package com.highcapable.flexiui + +internal actual val DynamicLightColors = DefaultLightColors + +internal actual val DynamicDarkColors = DefaultDarkColors + +internal actual val DynamicBlackColors = DefaultBlackColors \ No newline at end of file