Skip to content
This repository was archived by the owner on Mar 6, 2024. It is now read-only.

Commit c0e9718

Browse files
authored
Merge pull request #32 from dropbox/ios-client
Add iOS client
2 parents 69221a9 + 201686a commit c0e9718

File tree

18 files changed

+242
-12
lines changed

18 files changed

+242
-12
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ plugins {
2323
classpath("com.vanniktech:gradle-maven-publish-plugin:0.18.0")
2424
classpath("org.jetbrains.kotlinx:kover:0.5.0")
2525
classpath("org.jetbrains.kotlinx:kotlinx-cli:0.3.4")
26-
26+
classpath("com.rickclephas.kmp:kmp-nativecoroutines-gradle-plugin:0.11.3")
2727
}
2828
}
2929

componentbox/build.gradle.kts

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import com.vanniktech.maven.publish.JavadocJar.Dokka
22
import com.vanniktech.maven.publish.KotlinMultiplatform
33
import com.vanniktech.maven.publish.MavenPublishBaseExtension
44
import org.jetbrains.dokka.gradle.DokkaTask
5+
import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFramework
56

67
plugins {
78
kotlin("multiplatform")
@@ -11,6 +12,7 @@ plugins {
1112
id("com.vanniktech.maven.publish.base")
1213
id("org.jetbrains.dokka")
1314
id("org.jetbrains.kotlin.native.cocoapods")
15+
id("com.rickclephas.kmp.nativecoroutines")
1416
}
1517

1618
group = "com.dropbox.componentbox"
@@ -23,13 +25,13 @@ kotlin {
2325
binaries.executable()
2426
}
2527

26-
val iosTarget: (String, org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget.() -> Unit) -> org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget =
27-
when {
28-
System.getenv("SDK_NAME")?.startsWith("iphoneos") == true -> ::iosArm64
29-
System.getenv("NATIVE_ARCH")?.startsWith("arm") == true -> ::iosSimulatorArm64
30-
else -> ::iosX64
28+
val xcf = XCFramework("componentbox")
29+
listOf(iosX64(), iosArm64(), iosSimulatorArm64()).forEach {
30+
it.binaries.framework {
31+
baseName = "componentbox"
32+
xcf.add(this)
3133
}
32-
iosTarget("iOS") {}
34+
}
3335

3436
cocoapods {
3537
summary = "ComponentBox"
@@ -50,7 +52,11 @@ kotlin {
5052
implementation(ziplineLoader)
5153
}
5254

53-
55+
implementation("io.ktor:ktor-client-core:2.0.0-beta-1")
56+
implementation("io.ktor:ktor-client-serialization:2.0.0-beta-1")
57+
implementation("io.ktor:ktor-client-content-negotiation:2.0.0-beta-1")
58+
implementation("io.ktor:ktor-serialization-kotlinx-json:2.0.0-beta-1")
59+
implementation("io.ktor:ktor-client-logging:2.0.0-beta-1")
5460
}
5561
}
5662

@@ -96,6 +102,27 @@ kotlin {
96102
api(compose.runtime)
97103
}
98104
}
105+
106+
val iosX64Main by getting
107+
val iosArm64Main by getting
108+
val iosSimulatorArm64Main by getting
109+
val iosMain by creating {
110+
dependsOn(commonMain)
111+
112+
dependencies {
113+
implementation("io.ktor:ktor-client-ios:2.0.0-beta-1")
114+
115+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0-native-mt") {
116+
version {
117+
strictly("1.6.0-native-mt")
118+
}
119+
}
120+
}
121+
122+
iosX64Main.dependsOn(this)
123+
iosArm64Main.dependsOn(this)
124+
iosSimulatorArm64Main.dependsOn(this)
125+
}
99126
}
100127
}
101128

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.dropbox.componentbox
2+
3+
import com.dropbox.componentbox.foundation.ComponentBox
4+
import io.ktor.client.HttpClient
5+
import io.ktor.client.call.body
6+
import io.ktor.client.plugins.ContentNegotiation
7+
import io.ktor.client.plugins.logging.DEFAULT
8+
import io.ktor.client.plugins.logging.LogLevel
9+
import io.ktor.client.plugins.logging.Logger
10+
import io.ktor.client.plugins.logging.Logging
11+
import io.ktor.client.request.get
12+
import io.ktor.serialization.kotlinx.json.json
13+
import kotlinx.serialization.json.Json
14+
import kotlin.native.concurrent.ThreadLocal
15+
16+
@ThreadLocal
17+
public object ComponentBoxClient {
18+
private val safeJson = Json { isLenient = true; ignoreUnknownKeys = true }
19+
20+
val client: HttpClient = HttpClient {
21+
install(ContentNegotiation) {
22+
json(safeJson)
23+
}
24+
25+
install(Logging) {
26+
logger = Logger.DEFAULT
27+
level = LogLevel.ALL
28+
}
29+
}
30+
31+
suspend fun fetchScreen(url: String): ComponentBox.Screen = client.get(url).body()
32+
33+
suspend inline fun <reified C : ComponentBox> fetchComponentBox(url: String): C = client.get(url).body()
34+
}
35+
36+
fun <T> T.freeze(): T = this.freeze()

componentbox/src/iOSMain/kotlin/com/dropbox/componentbox/foundation/Icons.kt renamed to componentbox/src/iosMain/kotlin/com/dropbox/componentbox/foundation/Icons.kt

File renamed without changes.

componentbox/src/iOSMain/kotlin/com/dropbox/componentbox/foundation/Image.kt renamed to componentbox/src/iosMain/kotlin/com/dropbox/componentbox/foundation/Image.kt

File renamed without changes.

componentbox/src/iOSMain/kotlin/com/dropbox/componentbox/foundation/Inflater.kt renamed to componentbox/src/iosMain/kotlin/com/dropbox/componentbox/foundation/Inflater.kt

File renamed without changes.

componentbox/src/iOSMain/kotlin/com/dropbox/componentbox/foundation/MultiplatformRes.kt renamed to componentbox/src/iosMain/kotlin/com/dropbox/componentbox/foundation/MultiplatformRes.kt

File renamed without changes.

componentbox/src/iOSMain/kotlin/com/dropbox/componentbox/foundation/TextStyle.kt renamed to componentbox/src/iosMain/kotlin/com/dropbox/componentbox/foundation/TextStyle.kt

File renamed without changes.

componentbox/src/iOSMain/kotlin/com/dropbox/componentbox/foundation/Themer.kt renamed to componentbox/src/iosMain/kotlin/com/dropbox/componentbox/foundation/Themer.kt

File renamed without changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.dropbox.componentbox.foundation
2+
3+
import com.dropbox.componentbox.ComponentBoxClient
4+
import kotlin.native.concurrent.freeze
5+
6+
fun ComponentBoxClient.freeze() = this.freeze()

0 commit comments

Comments
 (0)