Open cye10 opened 4 months ago
I would say what this library does is nearly the same as a recomposition in compose, except that it only works for strings. So you could achieve the exact same behavior by simply triggering a recomposition.
private val recomposeToggleState: MutableState<Boolean> = mutableStateOf(false)
@Composable
fun YourView() {
Text(text = stringResource(R.string.a_string))
LaunchedEffect(recomposeToggleState.value) {}
}
fun recompose() {
recomposeToggleState.value = !recomposeToggleState.value
}
I am not sure if this is helpful in your case though, what would be your use case for using Reword with compose?
At present, we have a large amount of compose code. The above code is modified by modifying the source location. Can we only make individual modifications to each location to achieve this.
So since Compose only updates Composables that changed I had the issue with this as well where only parts of the app were reworded. I bypassed it by showing loading content instead of content of the app for a few milliseconds after the update in the MainActivity.
class MainActivity : AppCompatActivity() {
private val restringRecompose: MutableState<Boolean> = mutableStateOf(false)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
collectStringUpdates()
setContent {
AppTheme {
// Shows loading instead of the app content (MainScreen).
if (restringRecompose.value) {
LoadingLayout()
} else {
MainScreen()
}
// Hides loading after delay
LaunchedEffect(key1 = restringRecompose.value) {
delay(500) // Set the delay you want to show to the user. If there is none then it just blinks the loading layout.
if (restringRecompose.value) {
restringRecompose.value = false
}
}
}
}
private fun collectStringUpdates() {
vm.srings.collect {
// Triggers Restring and loading
Restring.putStrings(dictionary.locale, dictionary.texts)
restringRecompose.value = true
}
}
}
I think I might use this intead of Reword library.
Is there an existing method that supports compose.