Lilly
04/09/2021, 12:59 AMvar uiState: UiState by mutableStateOf(UiState.Loading)
private set
I also have 2 screens, each of them uses its own view model. viewModelScreenA and viewModelScreenB. When I print the uiState in both view models like:
init {
Timber.e("VM A - uiState: $uiState")
}
The uiState of both view models are identical UiState$Loading@220c954
. I would expect that they are different, not?ephemient
04/09/2021, 1:01 AMsealed class UiState {
object Loading : UiState ()
}
then there's only one UiState.Loading
instance. why do you expect them to be different?Ian Lake
04/09/2021, 1:09 AMLilly
04/09/2021, 1:22 AMcompose-router
. I have a related problem but I can't figure it out. Forget the second screen. When I enter screen A, I'm doing this:
DisposableEffect(Unit) {
presenter.connect(device)
onDispose { presenter.disconnect() }
}
var connectionState: BluetoothConnectionState by remember {
mutableStateOf(BluetoothConnectionState.Initial)
}
when (val state = presenter.uiState) {
UiState.Success -> {
connectionState = BluetoothConnectionState.Connected
}
is UiState.Failure -> {
connectionState = BluetoothConnectionState.Disconnected
showErrorMessage(state.message)
}
}
Within my view model, uiState
is set to UiState.Success after successfully connecting, but it never steps into Success case in screen. This worked before refactoring my code base.Ian Lake
04/09/2021, 1:26 AMLilly
04/09/2021, 1:27 AMLilly
04/09/2021, 1:37 AMDisposableEffect(Unit) {
presenter.connect(device)
onDispose { presenter.disconnect() }
}
but rather:
DisposableEffect(Unit) {
onConnect()
onDispose { presenter.disconnect() }
}
so I don't have to pass BluetoothDevice
to make the screen more testable. onConnect()
looks like:
ScreenA(
presenter = presenterA,
onConnect = { presenterA.connect(device) },
...
I didn't expect that it makes a different, but when changing it to first sample it steps into Success case like expected. Can you explain why the solution with onConnect
does not work??Lilly
04/09/2021, 2:08 AMonConnect
:
ScreenA(
presenter = presenterA,
onConnect = { presenterA.connect(device) },
...
and this to obtain the presenter:
val presenterA: APresenter
get() = APresenter(someUseCase)
I was dealing with two different presenter objects 🙋♀️ This took a while to notice. Sorry guys 🙏Ian Lake
04/09/2021, 2:51 AM