jean
10/28/2024, 8:41 PMdave08
10/29/2024, 7:54 AMjean
10/29/2024, 7:58 AMdave08
10/29/2024, 8:03 AMjean
10/29/2024, 8:05 AMdave08
10/29/2024, 8:07 AMjean
10/29/2024, 8:07 AMflowOf
and make sure the correct outputs are generated.jean
10/29/2024, 8:08 AMproduceSavebleState
using a rememberSaveble
function to accomplish something similardave08
10/29/2024, 8:10 AMjean
10/29/2024, 8:10 AMdave08
10/29/2024, 8:38 AMyuya
10/29/2024, 3:53 PMclass Presenter : ViewModel() {
var value1 by mutableStateOf(false)
@Composable
fun uiState(events: Flow<Event>): UiState {
var value2 by remember { mutableStateOf(false) }
LaunchedEffect(events) {
events.collect { event ->
when(event) {
Event.Load -> {
withContext(viewModelScope.
coroutineContext) {
launch {
value1 = true
value2 = true
}
}
}
}
}
return UiState(value1, value2)
}
}
@Composable
fun Screen() {
val eventBus = remember { EventBus<Event> }
val presenter = viewModel { Presenter() }
val uiState = presenter.uiState(eventBus.events)
Button(onclick = { eventBus.produceEvent(Event.Load) } {
Text("Click here")
}
}
In this case, value1 is stored in 'ViewModel' and value2 is stored in Composable's 'remember'.yuya
10/29/2024, 4:20 PMjean
10/29/2024, 4:24 PMyuya
10/29/2024, 4:30 PMjean
10/30/2024, 7:23 AMproduceState
is build on top of remember
and LaunchedEffect
. That seems to be enough to survive screen orientation and theme changes.jean
12/21/2024, 9:29 PMandroid:configChanges="orientation|...
in the manifest file 🤦🏻 I did create a sample repo to study the subject without distraction of an actual app https://github.com/jeantuffier/CounterTest It’s quite clear there that the counter is reset after a screen orientation. But I did find https://github.com/takahirom/Rin that basically extracted the rememberRetained
from Circuit to solve that particular issue.