feat: dynamic colour, and android maps dark theme
This commit is contained in:
parent
34923ce743
commit
ea08db364e
5 changed files with 72 additions and 2 deletions
|
|
@ -0,0 +1,32 @@
|
|||
package moe.lava.banksia.native
|
||||
|
||||
import android.os.Build
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.darkColorScheme
|
||||
import androidx.compose.material3.dynamicDarkColorScheme
|
||||
import androidx.compose.material3.dynamicLightColorScheme
|
||||
import androidx.compose.material3.lightColorScheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
|
||||
@Composable
|
||||
actual fun BanksiaTheme(
|
||||
darkTheme: Boolean,
|
||||
dynamicColor: Boolean,
|
||||
content: @Composable (() -> Unit)
|
||||
) {
|
||||
val colorScheme = when {
|
||||
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
|
||||
val context = LocalContext.current
|
||||
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
|
||||
}
|
||||
|
||||
darkTheme -> darkColorScheme()
|
||||
else -> lightColorScheme()
|
||||
}
|
||||
|
||||
MaterialTheme(
|
||||
colorScheme = colorScheme,
|
||||
content = content
|
||||
)
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ package moe.lava.banksia.native.maps
|
|||
|
||||
import android.Manifest
|
||||
import android.content.pm.PackageManager
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.add
|
||||
import androidx.compose.foundation.layout.asPaddingValues
|
||||
|
|
@ -83,7 +84,8 @@ actual fun Maps(
|
|||
GoogleMap(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
cameraPositionState = camPos,
|
||||
mapColorScheme = ComposeMapColorScheme.FOLLOW_SYSTEM,
|
||||
mapColorScheme = if (isSystemInDarkTheme()) { ComposeMapColorScheme.DARK } else {
|
||||
ComposeMapColorScheme.LIGHT },
|
||||
properties = DefaultMapProperties.copy(
|
||||
mapStyleOptions = MapStyleOptions.loadRawResourceStyle(LocalContext.current, R.raw.def_mapstyle),
|
||||
isMyLocationEnabled = checkLocationPermission(),
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ import kotlinx.coroutines.launch
|
|||
import moe.lava.banksia.api.ptv.PtvService
|
||||
import moe.lava.banksia.api.ptv.structures.Route
|
||||
import moe.lava.banksia.api.ptv.structures.getProperties
|
||||
import moe.lava.banksia.native.BanksiaTheme
|
||||
import moe.lava.banksia.native.maps.Maps
|
||||
import moe.lava.banksia.native.maps.Point
|
||||
import moe.lava.banksia.native.maps.Polyline
|
||||
|
|
@ -146,7 +147,7 @@ fun App() {
|
|||
var peekHeight by remember { mutableStateOf(128.dp) }
|
||||
var peekHeightMultiplier by remember { mutableFloatStateOf(1F) }
|
||||
|
||||
MaterialTheme {
|
||||
BanksiaTheme {
|
||||
BottomSheetScaffold(
|
||||
scaffoldState = scaffoldState,
|
||||
sheetPeekHeight = peekHeight * peekHeightMultiplier,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
package moe.lava.banksia.native
|
||||
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
|
||||
@Composable
|
||||
expect fun BanksiaTheme(
|
||||
darkTheme: Boolean = isSystemInDarkTheme(),
|
||||
// Dynamic color is available on Android 12+
|
||||
dynamicColor: Boolean = true,
|
||||
content: @Composable () -> Unit
|
||||
)
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package moe.lava.banksia.native
|
||||
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.darkColorScheme
|
||||
import androidx.compose.material3.lightColorScheme
|
||||
import androidx.compose.runtime.Composable
|
||||
|
||||
@Composable
|
||||
actual fun BanksiaTheme(
|
||||
darkTheme: Boolean,
|
||||
dynamicColor: Boolean,
|
||||
content: @Composable (() -> Unit)
|
||||
) {
|
||||
val colorScheme = when {
|
||||
darkTheme -> darkColorScheme()
|
||||
else -> lightColorScheme()
|
||||
}
|
||||
|
||||
MaterialTheme(
|
||||
colorScheme = colorScheme,
|
||||
content = content
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue