loloof64
12/15/2021, 12:09 PMclass
and String
? Or is even this last very bad practice ?Leo Zam
12/15/2021, 1:20 PMloloof64
12/15/2021, 1:32 PM@Composable
: so to do state hoisting.
I think i can handle that way also.Colton Idle
12/15/2021, 3:01 PMCaution: Passing complex data structures over arguments is considered an anti-pattern. Each destination should be responsible for loading UI data based on the minimum necessary information, such as item IDs. This simplifies process recreation and avoids potential data inconsistencies.tldr. Just use identifiers. Bonus being you can retrieve stuff after process death. if you really want to "share" an object, just put the object in some shared scope by the two things that need it.
Ian Lake
12/15/2021, 3:40 PMloloof64
12/16/2021, 8:54 AMComposable
in main activityColton Idle
12/16/2021, 12:15 PMloloof64
12/16/2021, 3:29 PM@Parcelize
and to use this feature
val games = extractGames(fileData = it, context = context)
navController.currentBackStackEntry?.savedStateHandle?.set(
NavHostParcelizeArgs.gamesList,
games
)
navController.navigate(NavHostRoutes.gamePage)
and
val gamesList =
navController.previousBackStackEntry?.savedStateHandle?.get<List<PGNGame>>(
NavHostParcelizeArgs.gamesList
)
and
@Composable
fun MainContent(stockfishLib: StockfishLib) {
val navController = rememberNavController()
NavHost(navController, startDestination = NavHostRoutes.gamesListPage) {
composable(NavHostRoutes.gamesListPage) {
GamesListPage(
navController = navController,
)
}
composable(NavHostRoutes.gamePage) {
GamePage(
navController = navController,
stockfishLib = stockfishLib,
)
}
}
}
This way should be far cleaner.Ian Lake
12/16/2021, 11:55 PMrememberSaveable
above the NavHost layer acting as a "repository" that both destinations use as their source of truthloloof64
12/23/2021, 10:12 AM@composable
which defines the NavHost
? And how to pass it to all screens ?
In short, where should I create the single instance of GamesFromFileExtractorUseCase
? Otherwise, should the GamesFromFileExtractorUseCase
be a Singleton / object class ?Javier
12/23/2021, 10:54 AMobject
+ lateinit var
if I could use a class
+ @Singleton
+ val
loloof64
12/23/2021, 10:55 AM@Singleton
is also a Dagger annotation. Thank you very much 🙂@Singleton
does not make it a Singleton : https://stackoverflow.com/a/44237507/662618Javier
12/23/2021, 12:57 PM@Singleton
, you should get the same instance always which is your use caseloloof64
12/23/2021, 2:29 PM(context.applicationContext as MyApplication).gamesFromFileExtractorUseCase.extractGame()
but I'm wondering whether it is better or worse than setting it inside NavHost state.