Skip to content

Commit

Permalink
initialise Koin in shared code
Browse files Browse the repository at this point in the history
  • Loading branch information
joreilly committed Nov 2, 2024
1 parent 370f64d commit 179fb96
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.jetbrains.kmpapp

import android.app.Application
import com.jetbrains.kmpapp.di.initKoin

class MuseumApp : Application() {
override fun onCreate() {
super.onCreate()
initKoin()
}
}
43 changes: 25 additions & 18 deletions composeApp/src/commonMain/kotlin/com/jetbrains/kmpapp/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import androidx.navigation.toRoute
import com.jetbrains.kmpapp.di.dataModule
import com.jetbrains.kmpapp.di.viewModelModule
import com.jetbrains.kmpapp.screens.detail.DetailScreen
import com.jetbrains.kmpapp.screens.list.ListScreen
import kotlinx.serialization.Serializable
import org.koin.compose.KoinApplication

@Serializable
object ListDestination
Expand All @@ -23,24 +26,28 @@ data class DetailDestination(val objectId: Int)

@Composable
fun App() {
MaterialTheme(
colors = if (isSystemInDarkTheme()) darkColors() else lightColors()
) {
Surface {
val navController: NavHostController = rememberNavController()
NavHost(navController = navController, startDestination = ListDestination) {
composable<ListDestination> {
ListScreen(navigateToDetails = { objectId ->
navController.navigate(DetailDestination(objectId))
})
}
composable<DetailDestination> { backStackEntry ->
DetailScreen(
objectId = backStackEntry.toRoute<DetailDestination>().objectId,
navigateBack = {
navController.popBackStack()
}
)
KoinApplication(application = {
modules(dataModule, viewModelModule)
}) {
MaterialTheme(
colors = if (isSystemInDarkTheme()) darkColors() else lightColors()
) {
Surface {
val navController: NavHostController = rememberNavController()
NavHost(navController = navController, startDestination = ListDestination) {
composable<ListDestination> {
ListScreen(navigateToDetails = { objectId ->
navController.navigate(DetailDestination(objectId))
})
}
composable<DetailDestination> { backStackEntry ->
DetailScreen(
objectId = backStackEntry.toRoute<DetailDestination>().objectId,
navigateBack = {
navController.popBackStack()
}
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,3 @@ val viewModelModule = module {
factoryOf(::ListViewModel)
factoryOf(::DetailViewModel)
}

fun initKoin() {
startKoin {
modules(
dataModule,
viewModelModule,
)
}
}
4 changes: 0 additions & 4 deletions iosApp/iosApp/iOSApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import ComposeApp

@main
struct iOSApp: App {
init() {
KoinKt.doInitKoin()
}

var body: some Scene {
WindowGroup {
ContentView()
Expand Down

0 comments on commit 179fb96

Please sign in to comment.