Isolating kotlin api called by swift to iosapi module to improve compile time
From 14 minutes to 15 seconds!
This commit is contained in:
56
iosapi/src/commonMain/kotlin/app/klottr/api/IosFacade.kt
Normal file
56
iosapi/src/commonMain/kotlin/app/klottr/api/IosFacade.kt
Normal file
@@ -0,0 +1,56 @@
|
||||
package app.klottr.api
|
||||
|
||||
// This file defines ONLY what Swift needs. Everything else stays in :shared.
|
||||
|
||||
/**
|
||||
* Public delegate protocol visible to Swift.
|
||||
* Keep this in :iosapi so we don't leak :shared types in the public headers.
|
||||
*/
|
||||
interface AuthStorageDelegate {
|
||||
fun get(key: String): String?
|
||||
fun set(key: String, value: String?)
|
||||
fun clear()
|
||||
}
|
||||
|
||||
/**
|
||||
* IMPORTANT: make this an `object`, not a `class`.
|
||||
* Kotlin/Native exposes `object Foo` to Swift as `Foo.shared`.
|
||||
*/
|
||||
object PlatformAuthStorage {
|
||||
// Adapter to bridge iosapi.AuthStorageDelegate -> shared.AuthStorageDelegate
|
||||
private class SharedDelegateAdapter(
|
||||
private val d: AuthStorageDelegate
|
||||
) : app.klottr.util.AuthStorageDelegate {
|
||||
override fun get(key: String): String? = d.get(key)
|
||||
override fun set(key: String, value: String?) = d.set(key, value)
|
||||
override fun clear() = d.clear()
|
||||
}
|
||||
fun install(delegate: AuthStorageDelegate) {
|
||||
app.klottr.util.PlatformAuthStorage.install(SharedDelegateAdapter(delegate))
|
||||
}
|
||||
fun get(key: String): String? = app.klottr.util.PlatformAuthStorage.get(key)
|
||||
fun set(key: String, value: String?) { app.klottr.util.PlatformAuthStorage.set(key, value) }
|
||||
fun clear() { app.klottr.util.PlatformAuthStorage.clear() }
|
||||
}
|
||||
|
||||
// Public API that Swift calls, delegating into your real implementation in :shared
|
||||
//
|
||||
object AuthShared {
|
||||
fun applyLogin(token: String?, sub: String?, mail: String?) {
|
||||
// call into your existing code in :shared
|
||||
app.klottr.util.AuthShared.applyLogin(token, sub, mail)
|
||||
}
|
||||
|
||||
fun loadFromStorage() {
|
||||
app.klottr.util.AuthShared.loadFromStorage()
|
||||
}
|
||||
|
||||
fun clearAll() {
|
||||
app.klottr.util.AuthShared.clearAll()
|
||||
}
|
||||
}
|
||||
|
||||
// (Optional) whatever tiny test surface Swift currently uses
|
||||
class SharedPing {
|
||||
fun ping(): String = "iosapi ping"
|
||||
}
|
||||
19
iosapi/src/iosMain/kotlin/app/klottr/api/Main.kt
Normal file
19
iosapi/src/iosMain/kotlin/app/klottr/api/Main.kt
Normal file
@@ -0,0 +1,19 @@
|
||||
@file:Suppress("FunctionName")
|
||||
|
||||
package app.klottr.api
|
||||
|
||||
import platform.UIKit.UIViewController
|
||||
|
||||
// Keep the exact symbol Swift uses: MainKt.MainViewController(...)
|
||||
fun MainViewController(
|
||||
onRequestPerms: () -> Unit = {},
|
||||
onLogin: () -> Unit = {},
|
||||
onLogout: () -> Unit = {},
|
||||
): UIViewController =
|
||||
// Forward to your existing implementation in :shared
|
||||
app.klottr.MainViewController(
|
||||
onRequestPerms = onRequestPerms,
|
||||
onLogin = onLogin,
|
||||
onLogout = onLogout
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user