diff --git a/README.md b/README.md index 84838ca..6aa577c 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ kotlin { ### SwiftUI ### -You need add the following file [Observer.kt](./mobk-swift/Observer.kt) to your +You need add the following file [Observer.swift](./mobk-swift/Observer.swift) to your Xcode project. Be sure to replace the import line with the name of your Kotlin framework. diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 74dc6b9..0000000 --- a/build.gradle +++ /dev/null @@ -1,32 +0,0 @@ -buildscript { - Properties properties = new Properties() - properties.load(project.rootProject.file("secret.properties").newDataInputStream()) - - ext { - bintrayUsername = properties.getProperty("bintrayUsername") - bintrayPassword = properties.getProperty("bintrayPassword") - coroutines_version = "1.5.1-native-mt" - } - repositories { - google() - } - - dependencies { - classpath 'com.android.tools.build:gradle:7.0.0' - } -} - -plugins { - id 'org.jetbrains.kotlin.multiplatform' version '1.5.21' -} - -allprojects { - repositories { - google() - mavenCentral() - } -} - -kotlin { - jvm() -} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..6c8d832 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,27 @@ +buildscript { + repositories { + google() + mavenCentral() + } + + dependencies { + classpath("com.android.tools.build:gradle:8.1.1") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21") + classpath("org.jetbrains.compose:compose-gradle-plugin:1.5.1") + } +} + +plugins { + kotlin("multiplatform") version "1.9.10" +} + +allprojects { + repositories { + google() + mavenCentral() + } +} + +kotlin { + jvm() +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 2d8d1e4..a50f1ab 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1,2 @@ -android.useAndroidX=true \ No newline at end of file +android.useAndroidX=true +org.jetbrains.compose.experimental.uikit.enabled=true \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 673e9fd..7f50d7b 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Aug 11 10:48:24 CEST 2021 +#Wed Sep 20 20:55:00 CEST 2023 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip distributionPath=wrapper/dists -zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/mobk-compose/build.gradle b/mobk-compose/build.gradle deleted file mode 100644 index fdf5c49..0000000 --- a/mobk-compose/build.gradle +++ /dev/null @@ -1,73 +0,0 @@ -plugins { - id 'maven-publish' -} - -apply plugin: 'com.android.library' -apply plugin: 'org.jetbrains.kotlin.android' - -group "io.monkeypatch" -version "0.0.9" - -android { - compileSdkVersion(30) - defaultConfig { - minSdkVersion(24) - targetSdkVersion(30) - } - buildFeatures { - compose = true - } - compileOptions { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 - } - - composeOptions { - kotlinCompilerExtensionVersion "1.0.1" - kotlinCompilerVersion "1.5.21" - } - - kotlinOptions { - - jvmTarget = "1.8" - useIR = true - } -} - -dependencies { - implementation project(":mobk-core") - implementation "androidx.compose.ui:ui:1.0.1" -} - -publishing { - repositories { - maven{ - url = "https://api.bintray.com/maven/alexandre-delattre/MonkeyPatchLibs/mobk-compose/;publish=1" - credentials { - username bintrayUsername - password bintrayPassword - } - authentication { - basic(BasicAuthentication) - } - } - } -} - - -afterEvaluate { - publishing { - publications { - // Creates a Maven publication called "release". - release(MavenPublication) { - // Applies the component for the release build variant. - from components.release - } - // Creates a Maven publication called “debug”. - debug(MavenPublication) { - // Applies the component for the debug build variant. - from components.debug - } - } - } -} \ No newline at end of file diff --git a/mobk-core/build.gradle b/mobk-core/build.gradle deleted file mode 100644 index 331b461..0000000 --- a/mobk-core/build.gradle +++ /dev/null @@ -1,57 +0,0 @@ -plugins { - id 'org.jetbrains.kotlin.multiplatform' - id 'maven-publish' -} - -apply plugin: 'com.android.library' -group = "io.monkeypatch" -version = "0.0.9" - -kotlin { - explicitApi() - - android { - publishLibraryVariants("release", "debug") - } - ios() - sourceSets { - commonMain { - dependencies { - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version") - } - } - commonTest { - dependencies { - implementation(kotlin("test-common")) - implementation(kotlin("test-annotations-common")) - } - } - - androidTest { - dependencies { - implementation(kotlin("test")) - implementation(kotlin("test-junit")) - } - } - } -} - -android { - compileSdkVersion(30) - defaultConfig { - minSdkVersion(21) - targetSdkVersion(30) - } -} - -publishing { - repositories { - maven{ - url = "https://api.bintray.com/maven/alexandre-delattre/MonkeyPatchLibs/mobk-core/;publish=1" - credentials { - username bintrayUsername - password bintrayPassword - } - } - } -} \ No newline at end of file diff --git a/mobk-core/build.gradle.kts b/mobk-core/build.gradle.kts new file mode 100644 index 0000000..20677b8 --- /dev/null +++ b/mobk-core/build.gradle.kts @@ -0,0 +1,74 @@ +plugins { + kotlin("multiplatform") + id("com.android.library") + id("org.jetbrains.compose") + id("maven-publish") +} + +group = "io.monkeypatch" +version = "0.0.11" + +@OptIn(org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi::class) +kotlin { + targetHierarchy.default() + + androidTarget { + compilations.all { + kotlinOptions { + jvmTarget = "1.8" + } + } + + publishLibraryVariants("release") + } + + listOf( + iosX64(), + iosArm64(), + iosSimulatorArm64() + ).forEach { + it.binaries.framework { + baseName = "shared" + } + + } + sourceSets { + val commonMain by getting{ + dependencies { + implementation(compose.runtime) + implementation(compose.foundation) + implementation("org.jetbrains.kotlinx:atomicfu:0.21.0") + } + + } + val commonTest by getting { + dependencies { + implementation(kotlin("test")) + } + } + val iosMain by getting + val iosTest by getting + } +} + +android { + namespace = "io.monkeypatch.mobk.core" + compileSdk = 34 + defaultConfig { + minSdk = 24 + } +} + + + +publishing { + repositories { + maven{ + url = uri("https://api.bintray.com/maven/alexandre-delattre/MonkeyPatchLibs/mobk-core/;publish=1") + credentials { + username = project.findProperty("bintrayUsername") as String? ?: "" + password = project.findProperty("bintrayPassword") as String? ?: "" + } + } + } +} \ No newline at end of file diff --git a/mobk-compose/src/main/AndroidManifest.xml b/mobk-core/src/androidMain/AndroidManifest.xml similarity index 76% rename from mobk-compose/src/main/AndroidManifest.xml rename to mobk-core/src/androidMain/AndroidManifest.xml index 4c760d5..abc6037 100644 --- a/mobk-compose/src/main/AndroidManifest.xml +++ b/mobk-core/src/androidMain/AndroidManifest.xml @@ -1,4 +1,4 @@ - diff --git a/mobk-compose/src/main/java/io/monkeypatch/mobk/ui/Observer.kt b/mobk-core/src/commonMain/kotlin/io/monkeypatch/mobk/ui/Observer.kt similarity index 100% rename from mobk-compose/src/main/java/io/monkeypatch/mobk/ui/Observer.kt rename to mobk-core/src/commonMain/kotlin/io/monkeypatch/mobk/ui/Observer.kt diff --git a/mobk-swift/Observer.swift b/mobk-swift/Observer.swift new file mode 100644 index 0000000..e549034 --- /dev/null +++ b/mobk-swift/Observer.swift @@ -0,0 +1,39 @@ +// +// Observer.swift +// + +import SwiftUI +import + +struct ObserverView : View { + @ObservedObject var reactionObservable: ReactionObservable + + var body: some View { + self.reactionObservable.view + } +} + +func Observer(@ViewBuilder f: @escaping () -> V) -> some View { + let reactionObservable = ReactionObservable(f: f) + return ObserverView(reactionObservable: reactionObservable) +} + +class ReactionObservable: ObservableObject { + @Published var view: V? = nil + var disposer: ReactionDisposer? = nil + + init(f: @escaping () -> V) { + disposer = ApiKt.autorun { [weak self] in + self?.view = f() + } + } + + deinit { + let d = disposer + disposer = nil + DispatchQueue.main.async { + d?.invoke() + } + } + +} diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index 604fc13..0000000 --- a/settings.gradle +++ /dev/null @@ -1,2 +0,0 @@ -rootProject.name = 'mobk' -include ':mobk-core', ':mobk-compose' \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..3691190 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,2 @@ +rootProject.name = "mobk" +include(":mobk-core") \ No newline at end of file