-
-
Notifications
You must be signed in to change notification settings - Fork 85
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 #120 from arkivanov/add-app-darwin-compose
[compose-darwin] Added app-darwin-compose sample app
- Loading branch information
Showing
9 changed files
with
217 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import com.arkivanov.gradle.bundle | ||
import com.arkivanov.gradle.dependsOn | ||
import com.arkivanov.gradle.setupMultiplatform | ||
import com.arkivanov.gradle.setupSourceSets | ||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget | ||
import org.jetbrains.compose.experimental.dsl.IOSDevices | ||
|
||
plugins { | ||
id("kotlin-multiplatform") | ||
id("org.jetbrains.compose") | ||
id("com.arkivanov.gradle.setup") | ||
} | ||
|
||
setupMultiplatform(targets = {}) | ||
|
||
kotlin { | ||
iosX64("uikitX64") { | ||
binaries { | ||
executable { | ||
entryPoint = "com.arkivanov.sample.app.main" | ||
freeCompilerArgs += listOf( | ||
"-linker-option", "-framework", "-linker-option", "Metal", | ||
"-linker-option", "-framework", "-linker-option", "CoreText", | ||
"-linker-option", "-framework", "-linker-option", "CoreGraphics" | ||
) | ||
} | ||
} | ||
} | ||
|
||
setupSourceSets { | ||
val uikit by bundle() | ||
|
||
uikit dependsOn common | ||
iosSet dependsOn uikit | ||
|
||
common.main.dependencies { | ||
implementation(project(":decompose")) | ||
implementation(project(":extensions-compose-jetbrains")) | ||
implementation(project(":sample:shared:shared")) | ||
implementation(project(":sample:shared:compose")) | ||
implementation(compose.runtime) | ||
implementation(compose.foundation) | ||
implementation(compose.material) | ||
} | ||
} | ||
} | ||
|
||
kotlin.targets.withType<KotlinNativeTarget> { | ||
binaries.all { | ||
binaryOptions["memoryModel"] = "experimental" | ||
binaryOptions["freezing"] = "disabled" | ||
} | ||
} | ||
|
||
compose.experimental { | ||
uikit.application { | ||
bundleIdPrefix = "com.arkivanov.decompose.sample" | ||
projectName = "DecomposeSample" | ||
|
||
deployConfigurations { | ||
simulator("IPhone12Pro") { | ||
//Usage: ./gradlew iosDeployIPhone12ProDebug | ||
device = IOSDevices.IPHONE_12_PRO | ||
} | ||
} | ||
} | ||
} | ||
|
||
kotlin { | ||
targets.withType<KotlinNativeTarget> { | ||
binaries.all { | ||
// TODO: the current compose binary surprises LLVM, so disable checks for now. | ||
freeCompilerArgs += "-Xdisable-phases=VerifyBitcode" | ||
} | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
sample/app-darwin-compose/src/uikitMain/kotlin/com/arkivanov/sample/app/Main.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,83 @@ | ||
package com.arkivanov.sample.app | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.window.Application | ||
import com.arkivanov.decompose.DefaultComponentContext | ||
import com.arkivanov.essenty.lifecycle.LifecycleRegistry | ||
import com.arkivanov.essenty.lifecycle.destroy | ||
import com.arkivanov.essenty.lifecycle.resume | ||
import com.arkivanov.essenty.lifecycle.stop | ||
import com.arkivanov.sample.shared.dynamicfeatures.dynamicfeature.DefaultFeatureInstaller | ||
import com.arkivanov.sample.shared.root.RootComponent | ||
import com.arkivanov.sample.shared.root.RootContent | ||
import kotlinx.cinterop.* | ||
import platform.UIKit.* | ||
import platform.Foundation.* | ||
|
||
fun main() { | ||
val args = emptyArray<String>() | ||
memScoped { | ||
val argc = args.size + 1 | ||
val argv = (arrayOf("skikoApp") + args).map { it.cstr.ptr }.toCValues() | ||
autoreleasepool { | ||
UIApplicationMain(argc, argv, null, NSStringFromClass(SkikoAppDelegate)) | ||
} | ||
} | ||
} | ||
|
||
class SkikoAppDelegate : UIResponder, UIApplicationDelegateProtocol { | ||
companion object : UIResponderMeta(), UIApplicationDelegateProtocolMeta | ||
|
||
@ObjCObjectBase.OverrideInit | ||
constructor() : super() | ||
|
||
private val lifecycle = LifecycleRegistry() | ||
|
||
private val root = | ||
RootComponent( | ||
componentContext = DefaultComponentContext(lifecycle = lifecycle), | ||
featureInstaller = DefaultFeatureInstaller, | ||
) | ||
|
||
private var _window: UIWindow? = null | ||
override fun window() = _window | ||
override fun setWindow(window: UIWindow?) { | ||
_window = window | ||
} | ||
|
||
override fun application(application: UIApplication, didFinishLaunchingWithOptions: Map<Any?, *>?): Boolean { | ||
window = UIWindow(frame = UIScreen.mainScreen.bounds) | ||
window!!.rootViewController = Application("Minesweeper") { | ||
Column { | ||
// To skip upper part of screen. | ||
Box(modifier = Modifier | ||
.height(100.dp)) | ||
|
||
RootContent( | ||
root = root, | ||
modifier = Modifier.weight(1F).fillMaxWidth(), | ||
) | ||
} | ||
} | ||
window!!.makeKeyAndVisible() | ||
return true | ||
} | ||
|
||
override fun applicationDidBecomeActive(application: UIApplication) { | ||
lifecycle.resume() | ||
} | ||
|
||
override fun applicationWillResignActive(application: UIApplication) { | ||
lifecycle.stop() | ||
|
||
} | ||
|
||
override fun applicationWillTerminate(application: UIApplication) { | ||
lifecycle.destroy() | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
.../kotlin/com/arkivanov/sample/shared/dynamicfeatures/feature1/Feature1ContentFactoryIos.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,14 @@ | ||
package com.arkivanov.sample.shared.dynamicfeatures.feature1 | ||
|
||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import com.arkivanov.sample.shared.dynamicfeatures.DynamicFeatureContent | ||
|
||
internal actual fun feature1Content(): DynamicFeatureContent<Feature1> = | ||
object : DynamicFeatureContent<Feature1> { | ||
@Composable | ||
override fun invoke(component: Feature1, modifier: Modifier) { | ||
Text(text = "Not implemented") | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
.../kotlin/com/arkivanov/sample/shared/dynamicfeatures/feature2/Feature2ContentFactoryIos.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,14 @@ | ||
package com.arkivanov.sample.shared.dynamicfeatures.feature2 | ||
|
||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import com.arkivanov.sample.shared.dynamicfeatures.DynamicFeatureContent | ||
|
||
internal actual fun feature2Content(): DynamicFeatureContent<Feature2> = | ||
object : DynamicFeatureContent<Feature2> { | ||
@Composable | ||
override fun invoke(component: Feature2, modifier: Modifier) { | ||
Text(text = "Not implemented") | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
sample/shared/compose/src/iosMain/kotlin/com/arkivanov/sample/shared/utils/Orientation.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,7 @@ | ||
package com.arkivanov.sample.shared.utils | ||
|
||
import androidx.compose.runtime.Composable | ||
|
||
internal actual val orientation: Orientation | ||
@Composable | ||
get() = Orientation.PORTRAIT |
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