Skip to content

Commit 4e29db2

Browse files
committed
feat: add iOS support with updated XCFramework name and new build script
1 parent 407677a commit 4e29db2

File tree

13 files changed

+555
-11
lines changed

13 files changed

+555
-11
lines changed

build.xcframework.sh

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
./gradlew :compose-remote-layout:clean
4+
./gradlew :compose-remote-layout:assembleComposeRemoteLayoutCoreXCFramework
5+
if [ $? -ne 0 ]; then
6+
echo "Gradle task failed."
7+
exit 1
8+
fi
9+
10+
GENERATED_PATH="compose-remote-layout/build/XCFrameworks/release/ComposeRemoteLayoutCore.xcframework"
11+
OUTPUT_DIR="../ComposeRemoteLayoutCoreBinary"
12+
DEST_PATH="$OUTPUT_DIR/ComposeRemoteLayoutCore.xcframework"
13+
14+
mkdir -p "$DEST_PATH"
15+
16+
cp "$GENERATED_PATH" "$DEST_PATH"
17+
if [ $? -ne 0 ]; then
18+
echo "Failed copy the XCFramework."
19+
exit 1
20+
fi
21+
22+
#swift package compute-checksum "$ZIP_FILE"

compose-remote-layout/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ plugins {
1212
kotlin {
1313
jvmToolchain(17)
1414

15-
val xcframeworkName = "ComposeRemoteLayout"
15+
val xcframeworkName = "ComposeRemoteLayoutCore"
1616
val xcf = XCFramework(xcframeworkName)
1717

1818
androidTarget { publishLibraryVariants("release") }

compose-remote-layout/src/commonMain/kotlin/com/utsman/composeremote/LayoutParsers.kt

-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ object LayoutParser {
2020
}
2121

2222
fun parseLayoutJson(jsonString: String): LayoutComponent? = try {
23-
println("cuaks..... parse layout...")
2423
val jsonElement = json.parseToJsonElement(jsonString)
2524
val modifierOrder = extractModifierOrder(jsonElement)
2625
ModifierOrderTracker.setCurrentOrder(modifierOrder)
@@ -36,8 +35,6 @@ object LayoutParser {
3635
val jsonObject = element.jsonObject
3736
val (type, content) = jsonObject.entries.first()
3837

39-
println("cuaks.... exist...... -> $type | ${CustomNodes.exists(type)}")
40-
4138
if (CustomNodes.exists(type)) {
4239
val contentObj = content.jsonObject
4340
val modifier = contentObj["modifier"]?.let {

compose-remote-layout/src/iosMain/kotlin/com/utsman/composeremote/RemoteViewControllerAdapter.kt

+31-7
Original file line numberDiff line numberDiff line change
@@ -16,40 +16,57 @@ import androidx.compose.ui.unit.dp
1616
import androidx.compose.ui.viewinterop.UIKitView
1717
import androidx.compose.ui.window.ComposeUIViewController
1818
import com.utsman.composeremote.LayoutParser.parseLayoutJson
19+
import kotlinx.coroutines.MainScope
20+
import kotlinx.coroutines.delay
1921
import kotlinx.coroutines.flow.MutableStateFlow
22+
import kotlinx.coroutines.flow.collectLatest
23+
import kotlinx.coroutines.launch
2024
import platform.CoreGraphics.CGFloat
2125
import platform.UIKit.UIView
2226
import platform.UIKit.UIViewController
2327
import kotlin.experimental.ExperimentalObjCName
2428

25-
data class UIViewData(
29+
public data class UIViewData(
2630
val uiView: UIView,
2731
val widthDp: CGFloat,
2832
val heightDp: CGFloat,
2933
)
3034

31-
typealias Param = Map<String, String>
35+
public typealias Param = Map<String, String>
3236

3337
@OptIn(ExperimentalObjCName::class)
3438
@ObjCName(swiftName = "RemoteViewControllerAdapter")
35-
class RemoteViewControllerAdapter {
39+
public class RemoteViewControllerAdapter {
3640
private val jsonStringState: MutableStateFlow<String> =
3741
MutableStateFlow("{}")
3842

43+
private val clickHandler: MutableStateFlow<String> = MutableStateFlow("")
3944
private val bindValue = BindsValue()
4045

41-
fun setJsonString(jsonString: String) {
46+
private val mainScope = MainScope()
47+
48+
public fun setJsonString(jsonString: String) {
4249
jsonStringState.value = jsonString
4350
}
4451

45-
fun setBindValue(
52+
public fun setBindValue(
4653
key: String,
4754
value: Any,
4855
) {
4956
bindValue.setValue(key, value)
5057
}
5158

52-
fun registerUiView(
59+
public fun setClickHandler(
60+
handler: (String) -> Unit,
61+
) {
62+
mainScope.launch {
63+
clickHandler.collectLatest {
64+
if (it.isNotEmpty()) handler.invoke(it)
65+
}
66+
}
67+
}
68+
69+
public fun registerUiView(
5370
type: String,
5471
viewDataBuilder: (Param) -> UIViewData,
5572
) {
@@ -72,7 +89,7 @@ class RemoteViewControllerAdapter {
7289
}
7390
}
7491

75-
fun viewController(): UIViewController = ComposeUIViewController(
92+
public fun viewController(): UIViewController = ComposeUIViewController(
7693
configure = {
7794
enforceStrictPlistSanityCheck = false
7895
},
@@ -89,6 +106,13 @@ class RemoteViewControllerAdapter {
89106
component = component,
90107
modifier = Modifier.wrapContentSize(),
91108
bindValue = bindValue,
109+
onClickHandler = {
110+
mainScope.launch {
111+
clickHandler.value = it
112+
delay(50)
113+
clickHandler.value = ""
114+
}
115+
},
92116
)
93117
}
94118
}

0 commit comments

Comments
 (0)