Skip to content

Commit 3ab5558

Browse files
Setup Koin for Android;
1 parent 6644b1f commit 3ab5558

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

composeApp/src/androidMain/AndroidManifest.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
33

44
<application
5+
android:name=".App"
56
android:allowBackup="true"
67
android:icon="@mipmap/ic_launcher"
78
android:label="@string/app_name"
89
android:roundIcon="@mipmap/ic_launcher_round"
910
android:supportsRtl="true"
1011
android:theme="@android:style/Theme.Material.Light.NoActionBar">
1112
<activity
12-
android:exported="true"
13+
android:name=".MainActivity"
1314
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden|mnc|colorMode|density|fontScale|fontWeightAdjustment|keyboard|layoutDirection|locale|mcc|navigation|smallestScreenSize|touchscreen|uiMode"
14-
android:name=".MainActivity">
15+
android:exported="true">
1516
<intent-filter>
1617
<action android:name="android.intent.action.MAIN" />
1718

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import android.content.Context
2+
import org.koin.android.ext.koin.androidContext
3+
import org.koin.android.ext.koin.androidLogger
4+
import org.koin.core.context.GlobalContext.startKoin
5+
6+
actual class KoinInitializer(
7+
private val context: Context
8+
) {
9+
10+
actual fun init() {
11+
startKoin {
12+
androidContext(context)
13+
androidLogger()
14+
modules(applicationModule, viewModelModule)
15+
}
16+
}
17+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import org.koin.androidx.viewmodel.dsl.viewModelOf
2+
import org.koin.core.module.Module
3+
import org.koin.dsl.module
4+
5+
actual val viewModelModule: Module = module {
6+
viewModelOf(::ScreenAViewModel)
7+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package xyz.teamgravity.viewmodelcomposemultiplatform
2+
3+
import KoinInitializer
4+
import android.app.Application
5+
6+
class App : Application() {
7+
8+
override fun onCreate() {
9+
super.onCreate()
10+
KoinInitializer(this).init()
11+
}
12+
}

0 commit comments

Comments
 (0)