Tiago Nunes
07/19/2021, 12:32 PMTgo1014
07/19/2021, 12:36 PMTiago Nunes
07/19/2021, 12:44 PMTiago Nunes
07/19/2021, 12:47 PMTiago Nunes
07/19/2021, 12:48 PMTgo1014
07/19/2021, 12:51 PMTiago Nunes
07/19/2021, 12:53 PMTiago Nunes
07/19/2021, 12:53 PMnglauber
07/19/2021, 12:56 PMprivate val _errorEvent = MutableSharedFlow<ErrorEntity.Error?>(replay = 0)
nglauber
07/19/2021, 12:56 PMTiago Nunes
07/19/2021, 12:57 PMTiago Nunes
07/19/2021, 12:57 PMTiago Nunes
07/19/2021, 12:57 PMComposablesĀ should be side-effect free
Tiago Nunes
07/19/2021, 12:58 PMAĀ *side-effect*Ā is a change to the state of the app that happens outside the scope of a composable function
nglauber
07/19/2021, 12:58 PMTiago Nunes
07/19/2021, 12:58 PMAnĀ *effect*Ā is a composable function that doesn't emit UI and causes side effects to run when a composition completes
Tiago Nunes
07/19/2021, 12:59 PMTiago Nunes
07/19/2021, 1:00 PMManuel Vivo
07/19/2021, 1:41 PMnavController
as a dependency to the ViewModel so that the VM can handle the event instead of sending it to the composable?Tiago Nunes
07/19/2021, 2:01 PMManuel Vivo
07/19/2021, 2:05 PMnavController
instead of a composable. Thereās nothing wrong with thatManuel Vivo
07/19/2021, 2:07 PMManuel Vivo
07/19/2021, 2:08 PMnavController
. This is something thatās not possible with the View system where the navigation state is a black box inside the NavHost
itselfManuel Vivo
07/19/2021, 2:09 PMManuel Vivo
07/19/2021, 2:10 PMnglauber
07/19/2021, 2:15 PMNavHost(...) {
composable("ScreenA") {
ScreenA(
onBack = { navController.navigateUp() },
onNext = { navController.navigate("ScreenB") }
)
}
composable("ScreenB") {
ScreenB(
onBack = { navController.navigateUp() },
onNext = { navController.navigate("ScreenC") }
)
}
...
}
Adam Powell
07/19/2021, 2:18 PMManuel Vivo
07/19/2021, 2:18 PMnavController
and handles all interactions with itColton Idle
07/19/2021, 2:33 PMManuel Vivo
07/19/2021, 2:42 PMsnackbarHostState
, and call showSnackbar
when needed. The same pattern applies for navController.navigate
calls.Colton Idle
07/19/2021, 2:43 PMManuel Vivo
07/19/2021, 2:43 PMLocalLifecycleOwner
is at least STARTED
Manuel Vivo
07/19/2021, 2:45 PMYouād use state for a navigation event?Nope. Youād pass the
navController
to the state holder (that would then become the SoT for that state) and call navigate
directly from the state holderColton Idle
07/19/2021, 2:45 PMManuel Vivo
07/19/2021, 2:45 PMColton Idle
07/19/2021, 2:46 PMManuel Vivo
07/19/2021, 2:47 PMDo you think any of the compose sample apps do a good job at showing how navigation should be done in a pure compose app?You have to bear with us š this is also very new to us and weāre experimenting. In fact, I think there are only a couple of samples that use Compose Navigation. So I agree we need to cover more ground here
Manuel Vivo
07/19/2021, 2:48 PMI wonder if that keeps the AAC VM testableMost of the state involved here is hoisted, so yes, this is all very testable š
Colton Idle
07/19/2021, 2:49 PMColton Idle
07/19/2021, 2:50 PMManuel Vivo
07/19/2021, 2:53 PMMy question was mostly towards if the VM is testable rather than composable.Yeah, the VM is also testable because it takes the other hoisted states (e.g.
navController
and snackbarHostState
) as dependencies so you can assert interactions with them and even fake them if neededTiago Nunes
07/19/2021, 2:56 PMManuel Vivo
07/19/2021, 3:01 PMManuel Vivo
07/19/2021, 3:02 PMTiago Nunes
07/19/2021, 3:08 PMNikola Drljaca
07/19/2021, 3:18 PMAdam Powell
07/19/2021, 3:32 PMAdam Powell
07/19/2021, 3:35 PMNikola Drljaca
07/19/2021, 9:07 PMtheapache64
07/20/2021, 6:09 AMMutableSharedFlow
with replay=0
and extraBufferCapacity = 1
. Here is an example of it.Manuel Vivo
07/20/2021, 2:56 PMSTARTED
https://github.com/android/compose-samples/pull/608/files
Iād love to know your thoughts!
Disclaimer: this is an experiment and shouldnāt be taken as guidance by any means š