Skip to content

Commit

Permalink
added basic iOS support
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed Nov 9, 2023
1 parent 74454a1 commit 5f6d80e
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
79 changes: 78 additions & 1 deletion app/shared/src/iosMain/kotlin/main.ios.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,82 @@
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.uikit.ComposeUIViewControllerDelegate
import androidx.compose.ui.window.ComposeUIViewController
import com.arkivanov.decompose.DefaultComponentContext
import com.arkivanov.essenty.lifecycle.Lifecycle
import com.arkivanov.essenty.lifecycle.LifecycleOwner
import com.arkivanov.essenty.lifecycle.LifecycleRegistry
import com.arkivanov.essenty.lifecycle.start
import com.arkivanov.essenty.lifecycle.resume
import com.arkivanov.essenty.lifecycle.destroy
import com.arkivanov.essenty.lifecycle.stop
import dev.datlag.burningseries.common.lifecycle.LocalLifecycleOwner
import dev.datlag.burningseries.App
import dev.datlag.burningseries.module.NetworkModule
import dev.datlag.burningseries.ui.navigation.NavHostComponent
import io.kamel.core.config.KamelConfig
import io.kamel.core.config.takeFrom
import io.kamel.image.config.Default
import io.kamel.image.config.LocalKamelConfig
import org.kodein.di.DI
import platform.UIKit.UIViewController

fun MainViewController() = ComposeUIViewController {
fun MainViewController(): UIViewController {
val lifecycleRegistry = LifecycleRegistry()

val lifecycleOwner = object : LifecycleOwner {
override val lifecycle: Lifecycle = lifecycleRegistry
}

val di = DI {
import(NetworkModule.di)
}

val root = NavHostComponent(
componentContext = DefaultComponentContext(
lifecycle = lifecycleOwner.lifecycle
),
di = di
)

val imageConfig = KamelConfig {
takeFrom(KamelConfig.Default)
}

return ComposeUIViewController(configure = {
delegate = object : ComposeUIViewControllerDelegate {
override fun viewDidLoad() {
super.viewDidLoad()
lifecycleRegistry.start()
}

override fun viewDidAppear(animated: Boolean) {
super.viewDidAppear(animated)
lifecycleRegistry.resume()
}

override fun viewDidDisappear(animated: Boolean) {
super.viewDidDisappear(animated)
lifecycleRegistry.destroy()
}

override fun viewWillAppear(animated: Boolean) {
super.viewWillAppear(animated)
lifecycleRegistry.resume()
}

override fun viewWillDisappear(animated: Boolean) {
super.viewWillDisappear(animated)
lifecycleRegistry.stop()
}
}
}) {
CompositionLocalProvider(
LocalLifecycleOwner provides lifecycleOwner,
LocalKamelConfig provides imageConfig
) {
App(di) {
root.render()
}
}
}
}
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ plugins {
alias(libs.plugins.osdetector) apply false
alias(libs.plugins.protobuf) apply false
alias(libs.plugins.serialization) apply false
alias(libs.plugins.complete.kotlin)
alias(libs.plugins.versions)
}

Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ android = "8.1.3"
android-core = "1.12.0"
appcompat = "1.6.1"
compose = "1.5.10"
complete-kotlin = "1.1.0"
context-menu = "0.2.0"
coroutines = "1.7.3"
datastore = "1.0.0"
Expand Down Expand Up @@ -94,6 +95,7 @@ android-application = { id = "com.android.application", version.ref = "android"
android-library = { id = "com.android.library", version.ref = "android" }
cocoapods = { id = "org.jetbrains.kotlin.native.cocoapods", version.ref = "kotlin" }
compose = { id = "org.jetbrains.compose", version.ref = "compose" }
complete-kotlin = { id = "com.louiscad.complete-kotlin", version.ref = "complete-kotlin" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
ktorfit = { id = "de.jensklingenberg.ktorfit", version.ref = "ktorfit" }
moko-resources = { id = "dev.icerock.mobile.multiplatform-resources", version.ref = "moko-resources" }
Expand Down

0 comments on commit 5f6d80e

Please sign in to comment.