Skip to content

Commit

Permalink
Makes stringRes Stable for compose
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorpamplona committed Aug 5, 2024
1 parent 84df86f commit ab772eb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,19 @@ fun stringRes(id: Int): String = resourceCache.get(id) ?: stringResource(id).als
@Composable
fun stringRes(
id: Int,
vararg args: Any,
vararg args: String,
): String =
String
.format(
LocalConfiguration.current.locales.get(0),
resourceCache.get(id) ?: stringResource(id).also { resourceCache.put(id, it) },
*args,
)

@Composable
fun stringRes(
id: Int,
vararg args: Int?,
): String =
String
.format(
Expand All @@ -66,7 +78,22 @@ fun stringRes(
fun stringRes(
ctx: Context,
id: Int,
vararg args: Any?,
vararg args: String?,
): String {
val res = ctx.resources

return String
.format(
res.configuration.locales.get(0),
resourceCache.get(id) ?: res.getString(id).also { resourceCache.put(id, it) },
*args,
)
}

fun stringRes(
ctx: Context,
id: Int,
vararg args: Int?,
): String {
val res = ctx.resources

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ fun authenticate(
stringRes(
context,
R.string.biometric_authentication_failed_explainer_with_error,
errString,
errString.toString(),
),
)
}
Expand Down

0 comments on commit ab772eb

Please sign in to comment.