-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Merseyside/develop
Develop
- Loading branch information
Showing
56 changed files
with
557 additions
and
1,074 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
archy-android/src/main/java/com/merseyside/merseyLib/archy/android/utils/KoinExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.merseyside.merseyLib.archy.android.utils | ||
|
||
import androidx.annotation.IdRes | ||
import androidx.fragment.app.Fragment | ||
import androidx.lifecycle.ViewModel | ||
import androidx.navigation.NavBackStackEntry | ||
import androidx.navigation.fragment.findNavController | ||
import org.koin.androidx.viewmodel.ViewModelOwner | ||
import org.koin.androidx.viewmodel.scope.getViewModel | ||
import org.koin.core.annotation.KoinInternalApi | ||
import org.koin.core.component.KoinComponent | ||
import org.koin.core.context.GlobalContext | ||
import org.koin.core.scope.Scope | ||
import kotlin.reflect.KClass | ||
|
||
fun <VM : ViewModel> Fragment.navGraphViewModel( | ||
@IdRes navGraphId: Int, | ||
clazz: KClass<VM> | ||
): VM { | ||
val backStackEntry: NavBackStackEntry by lazy { findNavController().getBackStackEntry(navGraphId) } | ||
return getKoinScope(this).getViewModel( | ||
owner = { ViewModelOwner(backStackEntry.viewModelStore) }, | ||
clazz = clazz | ||
) | ||
} | ||
|
||
@OptIn(KoinInternalApi::class) | ||
fun getKoinScope(any: Any): Scope { | ||
return when (any) { | ||
is KoinComponent -> any.getKoin().scopeRegistry.rootScope | ||
else -> GlobalContext.get().scopeRegistry.rootScope | ||
} | ||
} |
Oops, something went wrong.