refactor: abstract colourScheme into common code
This commit is contained in:
parent
121b2bb555
commit
fa81dd8c0f
3 changed files with 34 additions and 35 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
package moe.lava.banksia.native
|
package moe.lava.banksia.native
|
||||||
|
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.ColorScheme
|
||||||
import androidx.compose.material3.darkColorScheme
|
import androidx.compose.material3.darkColorScheme
|
||||||
import androidx.compose.material3.dynamicDarkColorScheme
|
import androidx.compose.material3.dynamicDarkColorScheme
|
||||||
import androidx.compose.material3.dynamicLightColorScheme
|
import androidx.compose.material3.dynamicLightColorScheme
|
||||||
|
|
@ -10,23 +10,15 @@ import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
actual fun BanksiaTheme(
|
actual fun BanksiaTheme.colors(
|
||||||
darkTheme: Boolean,
|
darkTheme: Boolean,
|
||||||
dynamicColor: Boolean,
|
dynamicColor: Boolean
|
||||||
content: @Composable (() -> Unit)
|
): ColorScheme = when {
|
||||||
) {
|
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
|
||||||
val colorScheme = when {
|
val context = LocalContext.current
|
||||||
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
|
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
|
||||||
val context = LocalContext.current
|
|
||||||
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
|
|
||||||
}
|
|
||||||
|
|
||||||
darkTheme -> darkColorScheme()
|
|
||||||
else -> lightColorScheme()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MaterialTheme(
|
darkTheme -> darkColorScheme()
|
||||||
colorScheme = colorScheme,
|
else -> lightColorScheme()
|
||||||
content = content
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,27 @@
|
||||||
package moe.lava.banksia.native
|
package moe.lava.banksia.native
|
||||||
|
|
||||||
import androidx.compose.foundation.isSystemInDarkTheme
|
import androidx.compose.foundation.isSystemInDarkTheme
|
||||||
|
import androidx.compose.material3.ColorScheme
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
expect fun BanksiaTheme(
|
fun BanksiaTheme(
|
||||||
darkTheme: Boolean = isSystemInDarkTheme(),
|
darkTheme: Boolean = isSystemInDarkTheme(),
|
||||||
// Dynamic color is available on Android 12+
|
|
||||||
dynamicColor: Boolean = true,
|
dynamicColor: Boolean = true,
|
||||||
content: @Composable () -> Unit
|
content: @Composable (() -> Unit)
|
||||||
)
|
) {
|
||||||
|
MaterialTheme(
|
||||||
|
colorScheme = BanksiaTheme.colors(darkTheme, dynamicColor),
|
||||||
|
content = content
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
expect fun BanksiaTheme.colors(darkTheme: Boolean, dynamicColor: Boolean): ColorScheme
|
||||||
|
|
||||||
|
object BanksiaTheme {
|
||||||
|
val colors: ColorScheme
|
||||||
|
@Composable
|
||||||
|
get() = colors(isSystemInDarkTheme(), true)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,15 @@
|
||||||
package moe.lava.banksia.native
|
package moe.lava.banksia.native
|
||||||
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.ColorScheme
|
||||||
import androidx.compose.material3.darkColorScheme
|
import androidx.compose.material3.darkColorScheme
|
||||||
import androidx.compose.material3.lightColorScheme
|
import androidx.compose.material3.lightColorScheme
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
actual fun BanksiaTheme(
|
actual fun BanksiaTheme.colors(
|
||||||
darkTheme: Boolean,
|
darkTheme: Boolean,
|
||||||
dynamicColor: Boolean,
|
dynamicColor: Boolean
|
||||||
content: @Composable (() -> Unit)
|
): ColorScheme = when {
|
||||||
) {
|
darkTheme -> darkColorScheme()
|
||||||
val colorScheme = when {
|
else -> lightColorScheme()
|
||||||
darkTheme -> darkColorScheme()
|
|
||||||
else -> lightColorScheme()
|
|
||||||
}
|
|
||||||
|
|
||||||
MaterialTheme(
|
|
||||||
colorScheme = colorScheme,
|
|
||||||
content = content
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue