https://kotlinlang.org logo
#compose
Title
# compose
m

Marko Novakovic

01/25/2022, 9:49 PM
am a bit confused. when using
AnimatedNavHost
from
Accompanist
composable(...) {...}
is recomposed multiple times due to animation. so every value inside the
composable
lambda should be `remember`ed right? for extracting arguments it doesn't really matter because they are static but with
remember
we avoid constant extraction of arguments? what about
hiltViewModel
inside
composable
lambda? is it ok to do something like this:
Copy code
composable(
    route = Screen.Checkout.route,
    arguments = ...,
    enterTransition = { forwardTransitionSharedAxisXIn() },
    exitTransition = { backwardsTransitionSharedAxisXOut() },
) { backStackEntry ->
    val someArg = remember { backStackEntry.arguments!!.getFloat("arg") }
    val viewModel = hiltViewModel<CheckoutViewModel>(backStackEntry)
    CheckoutScreen(
        ...
        navigateUp = navController::popBackStack,
    )
}
?
i

Ian Lake

01/25/2022, 11:35 PM
I think you'll find the microsecond needed to do
getFloat
isn't ever actually going to impact your performance
m

Marko Novakovic

01/26/2022, 9:19 AM
I was actually asking about
hiltViewModel()
in example above, how will that behave
i

Ian Lake

01/26/2022, 3:51 PM
ViewModels are only created once; you're just accessing an already created object. Also fine
🦜 1
m

Marko Novakovic

01/26/2022, 4:21 PM
thank you very much
2 Views