-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WEAR] Add VM sharing logic and temp unit switcher
- Loading branch information
Showing
3 changed files
with
67 additions
and
153 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
shared/src/commonMain/kotlin/com/kgurgul/cpuinfo/utils/KoinExtensions.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,19 @@ | ||
package com.kgurgul.cpuinfo.utils | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.lifecycle.ViewModel | ||
import androidx.navigation.NavBackStackEntry | ||
import androidx.navigation.NavController | ||
import org.koin.compose.viewmodel.koinViewModel | ||
|
||
@Composable | ||
inline fun <reified T : ViewModel> NavBackStackEntry.sharedViewModel( | ||
navController: NavController, | ||
): T { | ||
val navGraphRoute = destination.parent?.route ?: return koinViewModel() | ||
val parentEntry = remember(this) { | ||
navController.getBackStackEntry(navGraphRoute) | ||
} | ||
return koinViewModel(viewModelStoreOwner = parentEntry) | ||
} |
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