Skip to content

Commit

Permalink
Merge pull request #120 from arkivanov/add-app-darwin-compose
Browse files Browse the repository at this point in the history
[compose-darwin] Added app-darwin-compose sample app
  • Loading branch information
arkivanov authored Jun 19, 2022
2 parents b5dc311 + 9252e16 commit 1ad8eb8
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 0 deletions.
7 changes: 7 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ kotlin.native.disableCompilerDaemon=true
org.gradle.parallel=true
org.gradle.caching=true
systemProp.org.gradle.internal.publish.checksums.insecure=true

# Workaround for a build failure on CI:
# e: Module "org.jetbrains.compose.runtime:runtime-saveable (org.jetbrains.compose.runtime:runtime-saveable-uikitx64)"
# has a reference to symbol androidx.compose.runtime/remember|-2215966373931868872[0]. Neither the module itself nor
# its dependencies contain such declaration.
# See: https://github.com/JetBrains/compose-jb/issues/2046
kotlin.native.cacheKind=none
76 changes: 76 additions & 0 deletions sample/app-darwin-compose/build.gradle.kts
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"
}
}
}
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()
}
}
10 changes: 10 additions & 0 deletions sample/shared/compose/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import com.arkivanov.gradle.bundle
import com.arkivanov.gradle.dependsOn
import com.arkivanov.gradle.iosCompat
import com.arkivanov.gradle.setupMultiplatform
import com.arkivanov.gradle.setupSourceSets

Expand All @@ -12,11 +14,19 @@ plugins {
setupMultiplatform {
android()
jvm()
iosCompat(
arm64 = null, // Comment out to enable arm64 target
simulatorArm64 = null, // Not supported by Compose yet
)
}

kotlin {
setupSourceSets {
val jvm by bundle()
val ios by bundle()

ios dependsOn common
iosSet dependsOn ios

common.main.dependencies {
implementation(project(":decompose"))
Expand Down
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")
}
}
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")
}
}
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
5 changes: 5 additions & 0 deletions sample/shared/dynamic-features/compose-api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import com.arkivanov.gradle.iosCompat
import com.arkivanov.gradle.setupMultiplatform
import com.arkivanov.gradle.setupSourceSets

Expand All @@ -11,6 +12,10 @@ plugins {
setupMultiplatform {
android()
jvm()
iosCompat(
arm64 = null, // Comment out to enable arm64 target
simulatorArm64 = null, // Not supported by Compose yet
)
}

kotlin {
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ if (!startParameter.projectProperties.containsKey("check_publication")) {
include(":sample:shared:dynamic-features:feature2Impl")
include(":sample:app-android")
include(":sample:app-desktop")
include(":sample:app-darwin-compose")
include(":sample:app-js")
} else {
include(":tools:check-publication")
Expand Down

0 comments on commit 1ad8eb8

Please sign in to comment.