fix(ui): top bar title translation

This commit is contained in:
rhunk 2024-04-09 23:36:39 +02:00
parent 1f03592499
commit 9024b22b99
2 changed files with 4 additions and 3 deletions

View File

@ -41,7 +41,8 @@ class Navigation(
} == true }
TopAppBar(title = {
routes.getCurrentRoute(navBackStackEntry)?.title?.invoke() ?: Text(text = routes.getCurrentRoute(navBackStackEntry)?.routeInfo?.translatedKey ?: "Unknown Page")
val currentRoute = routes.getCurrentRoute(navBackStackEntry)
currentRoute?.title?.invoke() ?: Text(text = currentRoute?.routeInfo?.translatedKey?.value ?: "Unknown Page")
}, navigationIcon = {
val backButtonAnimation by animateFloatAsState(if (canGoBack) 1f else 0f,
label = "backButtonAnimation"

View File

@ -35,7 +35,7 @@ data class RouteInfo(
val icon: ImageVector = Icons.Default.Home,
val primary: Boolean = false,
) {
var translatedKey: String? = null
var translatedKey: Lazy<String?>? = null
val childIds = mutableListOf<String>()
}
@ -132,7 +132,7 @@ class Routes(
this.routeInfo = routeInfo
routes = this@Routes
context = this@Routes.context
this.routeInfo.translatedKey = context.translation.getOrNull("manager.routes.${route.routeInfo.key.substringBefore("/")}")
this.routeInfo.translatedKey = lazy { context.translation.getOrNull("manager.routes.${route.routeInfo.key.substringBefore("/")}") }
}
routes.add(route)
return route