Skip to content

Commit 5ac309c

Browse files
committed
Merge branch 'feature/swift-export'
2 parents 1c13d41 + 6b0cd65 commit 5ac309c

File tree

36 files changed

+1958
-804
lines changed

36 files changed

+1958
-804
lines changed

.idea/codeStyles/Project.xml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/copilot.data.migration.agent.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/copilot.data.migration.edit.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/kotlinc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
# Changelog
22

3+
## [2.3.0-dev-4778-1.9.0-beta03]
4+
5+
- Kotlin 2.3.0-dev-4778
6+
7+
**Note:** This development version is required for Swift Export support until the official release of Kotlin 2.3.0.
8+
---
9+
310
## [2.2.20-RC-1.9.0-beta03]
411

512
- Kotlin 2.2.20-RC
13+
- Adds experimental support to Swift Export
14+
15+
**Note:** Kotlin 2.2.20-RC has the following issues with Swift Export: [KT-80347](https://youtrack.jetbrains.com/issue/KT-80347/Swift-Export-IllegalArgumentException-Collection-contains-more-than-one-matching-element), [KT-79889](https://youtrack.jetbrains.com/issue/KT-79889/K-N-swift-export-fails-under-several-different-conditions).
16+
Use `2.3.0-dev-4778-1.9.0-beta03` if you need Swift Export support.
617

718
---
819

CHANGELOG_PLUGIN.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
# Changelog
22

3+
## [2.3.0-dev-4778-1.9.0-beta03]
4+
5+
- Compatible with 2.3.0-dev-4778-1.9.0-beta03
6+
7+
---
8+
39
## [2.2.20-RC-1.9.0-beta03]
410

5-
- Compatible with 2.2.10-1.9.0-beta03
11+
- Compatible with 2.2.20-RC-1.9.0-beta03
612

713
---
814

README.md

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22

33
# KMP-ComposeUIViewController
44

5-
KSP library for generating `ComposeUIViewController` and `UIViewControllerRepresentable` implementations when using [Compose Multiplatform](https://www.jetbrains.com/lp/compose-multiplatform/) for iOS.
5+
KSP library and Gradle plugin for generating `ComposeUIViewController` and `UIViewControllerRepresentable` files when using [Compose Multiplatform](https://www.jetbrains.com/lp/compose-multiplatform/) for iOS.
66

77
| Version | Kotlin | KSP | Compose Multiplatform | Xcode |
88
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:---------:|:-----:|:---------------------:|:------:|
99
| [![Gradle Plugin Portal Version](https://img.shields.io/gradle-plugin-portal/v/io.github.guilhe.kmp.plugin-composeuiviewcontroller)](https://plugins.gradle.org/plugin/io.github.guilhe.kmp.plugin-composeuiviewcontroller) | 2.2.20-RC | 2.0.2 | 1.9.0-beta03 | 16.4.0 |
1010

1111
[![Android Weekly](https://androidweekly.net/issues/issue-583/badge)](https://androidweekly.net/issues/issue-583) [![Featured in Kotlin Weekly - Issue #378](https://img.shields.io/badge/Featured_in_Kotlin_Weekly-Issue_%23378-7878b4)](https://mailchi.mp/kotlinweekly/kotlin-weekly-378) [![Featured in Kotlin Weekly - Issue #389](https://img.shields.io/badge/Featured_in_Kotlin_Weekly-Issue_%23389-7878b4)](https://mailchi.mp/kotlinweekly/kotlin-weekly-389) <a href="https://jetc.dev/issues/177.html"><img src="https://img.shields.io/badge/As_Seen_In-jetc.dev_Newsletter_Issue_%23177-blue?logo=Jetpack+Compose&amp;logoColor=white" alt="As Seen In - jetc.dev Newsletter Issue #177"></a> <a href="https://jetc.dev/issues/188.html"><img src="https://img.shields.io/badge/As_Seen_In-jetc.dev_Newsletter_Issue_%23188-blue?logo=Jetpack+Compose&amp;logoColor=white" alt="As Seen In - jetc.dev Newsletter Issue #188"></a>
1212

13+
> [!TIP]
14+
> For Swift Export support, until the official release of Kotlin 2.3.0, use `2.3.0-dev-4778-1.9.0-beta03`
15+
1316
## Motivation
1417
As the project expands, the codebase required naturally grows, which can quickly become cumbersome and susceptible to errors. To mitigate this challenge, this library leverages [Kotlin Symbol Processing](https://kotlinlang.org/docs/ksp-overview.html) to automatically generate the necessary Kotlin and Swift code for you.
1518

@@ -23,12 +26,12 @@ It can be used for **simple** and **advanced** use cases.
2326

2427
Kotlin Multiplatform and Compose Multiplatform are built upon the philosophy of incremental adoption and sharing only what you require. Consequently, the support for this specific use-case - in my opinion - is of paramount importance, especially in its capacity to entice iOS developers to embrace Compose Multiplatform.
2528

26-
> [!TIP]
29+
> [!NOTE]
2730
> This library takes care of the heavy lifting for you, but if you're interested in understanding how it works, the detailed approach is explained here: [Compose Multiplatform — Managing UI State on iOS](https://proandroiddev.com/compose-multiplatform-managing-ui-state-on-ios-45d37effeda9).
2831
2932
## Installation
3033

31-
By using the Gradle plugin all configurations will be applied automatically. If you wish to change the default values, you can configure its parameters using the available [extension](kmp-composeuiviewcontroller-gradle-plugin/src/main/kotlin/com/github/guilhe/kmp/composeuiviewcontroller/gradle/ComposeUiViewControllerParameters.kt).
34+
Configure the `plugins` block with the following three plugins. Once added, you can use the `ComposeUiViewController` block to set up the plugin’s configuration.
3235

3336
```kotlin
3437
plugins {
@@ -43,6 +46,21 @@ ComposeUiViewController {
4346
}
4447
```
4548

49+
With this setup, all necessary configurations are automatically applied. You only need to adjust the `ComposeUiViewController` block to match your
50+
project settings (e.g. `iosAppName` and `targetName`). If you wish to change the default values, you can configure its parameters:
51+
52+
<details><summary>Parameters available</summary>
53+
54+
- `iosAppFolderName` name of the folder containing the iosApp in the root's project tree;
55+
- `iosAppName` name of the iOS project (`name.xcodeproj`);
56+
- `targetName` name of the iOS project's target;
57+
- `exportFolderName` name of the destination folder inside iOS project (`iosAppFolderName`) where the `UIViewControllerRepresentable` files will be copied to when `autoExport` is `true`;
58+
- `autoExport` enables auto export generated files to Xcode project. If set to `false`, you will find the generated files under `/build/generated/ksp/`;
59+
60+
[Default values](kmp-composeuiviewcontroller-gradle-plugin/src/main/kotlin/com/github/guilhe/kmp/composeuiviewcontroller/gradle/ComposeUiViewControllerParameters.kt).
61+
62+
</details>
63+
4664
## Code generation
4765

4866
### KMP module
@@ -57,10 +75,6 @@ To annotate the parameter as the composable state variable (for **advanced** use
5775

5876
> [!IMPORTANT]
5977
> Only 0 or 1 `@ComposeUIViewControllerState` and an arbitrary number of parameter types (excluding `@Composable`) are allowed in `@ComposeUIViewController` functions.
60-
>
61-
> The `@ComposeUIViewController` includes a `frameworkBaseName` parameter, allowing you to specify a framework name manually. While the plugin typically attempts to retrieve this name automatically, you can use this parameter to enforce a specific name <ins>if the automatic retrieval fails</ins>.
62-
>
63-
> For more information consult the [ProcessorTest.kt](kmp-composeuiviewcontroller-ksp/src/test/kotlin/composeuiviewcontroller/ProcessorTest.kt) file from `kmp-composeuiviewcontroller-ksp`.
6478
6579
#### Examples
6680

@@ -86,14 +100,14 @@ object ComposeSimpleViewUIViewController {
86100
and also a `ComposeSimpleViewRepresentable`:
87101
```swift
88102
import SwiftUI
89-
import SharedUI
103+
import Shared
90104

91105
public struct ComposeSimpleViewRepresentable: UIViewControllerRepresentable {
92-
106+
93107
func makeUIViewController(context: Context) -> UIViewController {
94108
ComposeSimpleViewUIViewController().make()
95109
}
96-
110+
97111
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {
98112
//unused
99113
}
@@ -131,30 +145,33 @@ object ComposeAdvancedViewUIViewController {
131145
and also a `ComposeAdvancedViewRepresentable`:
132146
```swift
133147
import SwiftUI
134-
import SharedUI
148+
import Shared
135149

136150
public struct ComposeAdvancedViewRepresentable: UIViewControllerRepresentable {
137151
@Binding var viewState: ViewState
138152
let callback: () -> Void
139-
153+
140154
func makeUIViewController(context: Context) -> UIViewController {
141155
ComposeAdvancedViewUIViewController().make(callback: callback)
142156
}
143-
157+
144158
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {
145159
ComposeAdvancedViewUIViewController().update(viewState: viewState)
146160
}
147161
}
148162
```
149163
</details>
150164

165+
> [!TIP]
166+
> The `@ComposeUIViewController` has a `frameworkBaseName` parameter to manually set the framework name. This parameter will only be used <ins>if detection fails within the Processor</ins>.
167+
151168
### iOSApp
152169

153170
After a successful build the `UIViewControllerRepresentable` files are included and referenced in the `xcodeproj` ready to be used:
154171

155172
```swift
156173
import SwiftUI
157-
import SharedUI
174+
import Shared
158175

159176
struct SomeView: View {
160177
@State private var state: ViewState = ViewState(isLoading: false)
@@ -170,16 +187,16 @@ struct SomeView: View {
170187
> Avoid deleting `iosApp/Representables` without first using Xcode to `Remove references`.
171188
172189
## Sample
173-
For a working [sample](sample) open `iosApp/Gradient.xcodeproj` in Xcode and run standard configuration or use KMM plugin for Android Studio and choose `iosApp` in run configurations.
190+
For a working [sample](sample) open `iosApp/Gradient.xcodeproj` in Xcode and run standard configuration or use KMP plugin for Android Studio and choose `iosApp` in run configurations.
174191

175192
```bash
176193
> Task :shared:kspKotlinIosSimulatorArm64
177194
note: [ksp] loaded provider(s): [com.github.guilhe.kmp.composeuiviewcontroller.ksp.ProcessorProvider]
178195
note: [ksp] GradientScreenUIViewController created!
179-
note: [ksp] GradientScreenRepresentable created!
196+
note: [ksp] GradientScreenUIViewControllerRepresentable created!
180197

181198
> Task :CopyFilesToXcode
182-
> Copying files to iosApp/SharedRepresentables/
199+
> Copying files to iosApp/Representables/
183200
> Checking for new references to be added to xcodeproj
184201
> GradientScreenUIViewControllerRepresentable.swift added!
185202
> Done

build-logic/conventions/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ dependencies {
1212
}
1313

1414
kotlin {
15-
jvmToolchain(11)
15+
jvmToolchain(17)
1616
}
1717

1818
gradlePlugin {

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ buildscript {
1515

1616
allprojects {
1717
group = "com.github.guilhe.kmp"
18-
version = "2.2.20-RC-1.9.0-beta03"
18+
version = "2.3.0-dev-4778-1.9.0-beta03"
1919
}
2020

2121
tasks.register("publishLibraryModules") {

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[versions]
22

3-
kotlin = "2.2.20-RC"
3+
kotlin = "2.3.0-dev-4778"
44
ksp = "2.2.20-RC-2.0.2"
55
kotlinCompose = "1.9.0-beta03"
66
kotlinxSerialization = "1.9.0"

0 commit comments

Comments
 (0)