add web appbar color customization

This commit is contained in:
2026-08-15 08:30:39 +03:00
parent d6a0d058ed
commit 036aeba245
7 changed files with 43 additions and 7 deletions
@@ -1,6 +1,7 @@
package ru.shadowsparky.backend.data
import com.auth0.jwt.JWT
import com.auth0.jwt.JWTVerifier
import com.auth0.jwt.algorithms.Algorithm
import com.auth0.jwt.interfaces.DecodedJWT
import org.koin.core.annotation.Factory
@@ -14,7 +15,7 @@ class TokenVerifier(
private val loginVerifier: LoginVerifier
) {
val verifier = JWT.require(Algorithm.HMAC512(jwtInfo.secret))
val verifier: JWTVerifier = JWT.require(Algorithm.HMAC512(jwtInfo.secret))
.withAudience(jwtInfo.audience)
.withIssuer(jwtInfo.issuer)
.build()
@@ -7,6 +7,8 @@ import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyItemScope
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
@@ -89,11 +91,13 @@ fun ExpressiveLazyColumn(
reverseLayout: Boolean = false,
verticalArrangement: Arrangement.Vertical =
if (!reverseLayout) Arrangement.Top else Arrangement.Bottom,
state: LazyListState = rememberLazyListState(),
content: ExpressiveLazyListScope.() -> Unit
) {
val scope = ExpressiveLazyListScope().apply(content)
LazyColumn(
state = state,
modifier = modifier,
contentPadding = contentPadding,
reverseLayout = reverseLayout,
@@ -9,6 +9,7 @@ import com.arkivanov.decompose.extensions.compose.stack.animation.fade
import com.arkivanov.decompose.extensions.compose.stack.animation.predictiveback.androidPredictiveBackAnimatableV2
import com.arkivanov.decompose.extensions.compose.stack.animation.predictiveback.predictiveBackAnimation
import com.arkivanov.decompose.extensions.compose.stack.animation.stackAnimation
import ru.shadowsparky.ui.theme.getColorScheme
@OptIn(ExperimentalDecomposeApi::class, ExperimentalMaterial3ExpressiveApi::class)
@Composable
@@ -16,7 +17,7 @@ fun Nav(
rootComponent: RootComponent<*>,
process: @Composable (child: Child, route: Route) -> Unit
) {
MaterialExpressiveTheme {
MaterialExpressiveTheme(getColorScheme()) {
Children(
stack = rootComponent.valueChildStack,
animation = predictiveBackAnimation(
@@ -1,5 +1,6 @@
package ru.shadowsparky.ui
import androidx.compose.ui.graphics.Color
import com.arkivanov.essenty.lifecycle.Lifecycle
import com.arkivanov.essenty.lifecycle.LifecycleRegistry
import com.arkivanov.essenty.lifecycle.create
@@ -8,6 +9,7 @@ import com.arkivanov.essenty.lifecycle.resume
import com.arkivanov.essenty.lifecycle.start
import com.arkivanov.essenty.lifecycle.stop
import kotlinx.browser.document
import org.w3c.dom.HTMLMetaElement
import org.w3c.dom.events.Event
@JsFun(
@@ -80,3 +82,26 @@ fun hookPageVisibility(lifecycle: LifecycleRegistry) {
document.addEventListener("pagehide", { onPageHideShow(true) })
document.addEventListener("pageshow", { onPageHideShow(false) })
}
fun updateBrowserAppBarColor(color: Color) {
var metaElement = document.querySelector("meta[name='theme-color']") as? HTMLMetaElement
if (metaElement == null) {
val meta = document.createElement("meta") as HTMLMetaElement
meta.setAttribute("name", "theme-color")
document.head?.appendChild(meta)
metaElement = meta
}
metaElement.setAttribute("content", color.toHexStr())
}
private fun Color.toHexStr(): String {
val r = (this.red * 255).toInt()
val g = (this.green * 255).toInt()
val b = (this.blue * 255).toInt()
return "#${r.toHexString()}${g.toHexString()}${b.toHexString()}"
}
private fun Int.toHexString(): String {
val hex = this.toString(16)
return if (hex.length == 1) "0$hex" else hex
}