Skip to content

Commit

Permalink
Fix #2034 ViewModel Navigation restoring SavedStateHandle from right …
Browse files Browse the repository at this point in the history
…arguments
  • Loading branch information
arnaudgiuliani committed Feb 7, 2025
1 parent 1e30f2c commit ea0ee4d
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,15 @@ import org.koin.core.qualifier.Qualifier
inline fun <reified VM : ViewModel> Fragment.koinNavGraphViewModel(
@IdRes navGraphId: Int,
qualifier: Qualifier? = null,
noinline ownerProducer: () -> ViewModelStoreOwner = { findNavController().getBackStackEntry(navGraphId) },
noinline ownerProducer: (() -> ViewModelStoreOwner)? = null,
noinline extrasProducer: (() -> CreationExtras)? = null,
noinline parameters: (() -> ParametersHolder)? = null,
): Lazy<VM> {
return viewModel(qualifier, ownerProducer, extrasProducer, parameters)
val backStackEntry by lazy { findNavController().getBackStackEntry(navGraphId) }
return viewModel(
qualifier,
ownerProducer ?: { backStackEntry },
extrasProducer ?: { backStackEntry.defaultViewModelCreationExtras },
parameters
)
}

0 comments on commit ea0ee4d

Please sign in to comment.