From ebdf1da04ee21a38b621129fa96bb7b1dc7f9a7f Mon Sep 17 00:00:00 2001 From: Saket Narayan Date: Thu, 21 Sep 2023 15:10:42 -0400 Subject: [PATCH] Migrate to compose multiplatform --- build.gradle.kts | 2 + gradle.properties | 4 ++ gradle/libs.versions.toml | 4 +- library/build.gradle.kts | 44 +++++++++++++----- .../me/saket/swipe/SwipeableActionsBoxTest.kt | 0 ... to actions according on their weights.png | Bin ..._SwipeableActionsBoxTest_empty actions.png | Bin ...peableActionsBoxTest_non-empty actions.png | Bin ...round until swipe threshold is reached.png | Bin ...n swipe distance exceeds content width.png | Bin ...und should not be drawn behind content.png | Bin .../kotlin/me/saket/swipe/ActionFinder.kt | 0 .../kotlin/me/saket/swipe/SwipeAction.kt | 0 .../kotlin/me/saket/swipe/SwipeRipple.kt | 0 .../me/saket/swipe/SwipeableActionsBox.kt | 0 .../me/saket/swipe/SwipeableActionsState.kt | 0 .../kotlin/me/saket/swipe/defaults.kt | 0 settings.gradle | 1 - 18 files changed, 41 insertions(+), 14 deletions(-) rename library/src/{test => androidTest}/kotlin/me/saket/swipe/SwipeableActionsBoxTest.kt (100%) rename library/src/{test => androidTest}/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_distribute widths to actions according on their weights.png (100%) rename library/src/{test => androidTest}/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_empty actions.png (100%) rename library/src/{test => androidTest}/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_non-empty actions.png (100%) rename library/src/{test => androidTest}/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_show a placeholder background until swipe threshold is reached.png (100%) rename library/src/{test => androidTest}/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_show last swipe action even when swipe distance exceeds content width.png (100%) rename library/src/{test => androidTest}/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_swipe action's background should not be drawn behind content.png (100%) rename library/src/{main => commonMain}/kotlin/me/saket/swipe/ActionFinder.kt (100%) rename library/src/{main => commonMain}/kotlin/me/saket/swipe/SwipeAction.kt (100%) rename library/src/{main => commonMain}/kotlin/me/saket/swipe/SwipeRipple.kt (100%) rename library/src/{main => commonMain}/kotlin/me/saket/swipe/SwipeableActionsBox.kt (100%) rename library/src/{main => commonMain}/kotlin/me/saket/swipe/SwipeableActionsState.kt (100%) rename library/src/{main => commonMain}/kotlin/me/saket/swipe/defaults.kt (100%) diff --git a/build.gradle.kts b/build.gradle.kts index 041722a..3690930 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -14,7 +14,9 @@ buildscript { plugins { alias(libs.plugins.android.application) apply false alias(libs.plugins.android.library) apply false + alias(libs.plugins.kotlin.multiplatform) apply false alias(libs.plugins.kotlin.android) apply false + alias(libs.plugins.compose.multiplatform) apply false alias(libs.plugins.mavenPublish) apply false alias(libs.plugins.paparazzi) apply false alias(libs.plugins.dokka) apply false diff --git a/gradle.properties b/gradle.properties index e4cf333..5d17721 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,3 +18,7 @@ org.gradle.jvmargs=-Xmx1536m android.useAndroidX=true android.enableJetifier=false + +kotlin.mpp.androidSourceSetLayoutVersion=2 +kotlin.mpp.androidGradlePluginCompatibility.nowarn=true +org.jetbrains.compose.experimental.uikit.enabled=true diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index b0e2c35..0aa0996 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -6,6 +6,7 @@ agp = "8.1.0" androidx-compose-ui = "1.5.1" # https://developer.android.com/jetpack/androidx/releases/compose-ui androidx-compose-ui-material3 = "1.1.1" androidx-compose-compiler = "1.5.3" # https://developer.android.com/jetpack/androidx/releases/compose-compiler +compose-multiplatform = "1.5.1" # https://github.com/JetBrains/compose-multiplatform/releases androidx-appcompat = "1.6.1" androidx-activity = "1.7.2" # https://developer.android.com/jetpack/androidx/releases/activity androidx-savedstate = "1.2.1" # https://developer.android.com/jetpack/androidx/releases/savedstate @@ -21,11 +22,12 @@ android-application = { id = "com.android.application", version.ref = "agp" } android-library = { id = "com.android.library", version.ref = "agp" } paparazzi = { id = "app.cash.paparazzi", version.ref = "paparazzi" } kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } +kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } +compose-multiplatform = { id = "org.jetbrains.compose", version.ref = "compose-multiplatform" } dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" } mavenPublish = { id = "com.vanniktech.maven.publish", version.ref = "mavenPublish" } [libraries] -## TODO remove compose libs in favor of declaring via jetbrains compose plugin compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "androidx-compose-ui" } compose-ui = { module = "androidx.compose.ui:ui", version.ref = "androidx-compose-ui" } compose-material3 = { module = "androidx.compose.material3:material3", version.ref = "androidx-compose-ui-material3" } diff --git a/library/build.gradle.kts b/library/build.gradle.kts index e520db2..d2719c8 100644 --- a/library/build.gradle.kts +++ b/library/build.gradle.kts @@ -1,10 +1,41 @@ plugins { alias(libs.plugins.android.library) - alias(libs.plugins.kotlin.android) + alias(libs.plugins.kotlin.multiplatform) + alias(libs.plugins.compose.multiplatform) alias(libs.plugins.mavenPublish) alias(libs.plugins.paparazzi) } +kotlin { + @Suppress("OPT_IN_USAGE") + targetHierarchy.default() + + androidTarget() + jvm() + iosX64() + iosArm64() + iosSimulatorArm64() + + sourceSets { + val commonMain by getting { + dependencies { + implementation(compose.ui) + implementation(compose.foundation) + } + } + + val androidUnitTest by getting { + dependencies { + implementation(libs.junit) + implementation(libs.compose.material3) + implementation(libs.compose.materialIcons) + implementation(libs.androidx.savedstate) + implementation(libs.androidx.lifecycle) + } + } + } +} + android { namespace = "me.saket.swipe" @@ -26,17 +57,6 @@ android { } } -dependencies { - implementation(libs.compose.ui) - implementation(libs.compose.foundation) - - testImplementation(libs.junit) - testImplementation(libs.compose.material3) - testImplementation(libs.compose.materialIcons) - testImplementation(libs.androidx.savedstate) - testImplementation(libs.androidx.lifecycle) -} - // Used on CI to prevent publishing of non-snapshot versions. tasks.register("throwIfVersionIsNotSnapshot") { val libraryVersion = properties["VERSION_NAME"] as String diff --git a/library/src/test/kotlin/me/saket/swipe/SwipeableActionsBoxTest.kt b/library/src/androidTest/kotlin/me/saket/swipe/SwipeableActionsBoxTest.kt similarity index 100% rename from library/src/test/kotlin/me/saket/swipe/SwipeableActionsBoxTest.kt rename to library/src/androidTest/kotlin/me/saket/swipe/SwipeableActionsBoxTest.kt diff --git a/library/src/test/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_distribute widths to actions according on their weights.png b/library/src/androidTest/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_distribute widths to actions according on their weights.png similarity index 100% rename from library/src/test/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_distribute widths to actions according on their weights.png rename to library/src/androidTest/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_distribute widths to actions according on their weights.png diff --git a/library/src/test/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_empty actions.png b/library/src/androidTest/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_empty actions.png similarity index 100% rename from library/src/test/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_empty actions.png rename to library/src/androidTest/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_empty actions.png diff --git a/library/src/test/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_non-empty actions.png b/library/src/androidTest/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_non-empty actions.png similarity index 100% rename from library/src/test/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_non-empty actions.png rename to library/src/androidTest/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_non-empty actions.png diff --git a/library/src/test/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_show a placeholder background until swipe threshold is reached.png b/library/src/androidTest/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_show a placeholder background until swipe threshold is reached.png similarity index 100% rename from library/src/test/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_show a placeholder background until swipe threshold is reached.png rename to library/src/androidTest/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_show a placeholder background until swipe threshold is reached.png diff --git a/library/src/test/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_show last swipe action even when swipe distance exceeds content width.png b/library/src/androidTest/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_show last swipe action even when swipe distance exceeds content width.png similarity index 100% rename from library/src/test/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_show last swipe action even when swipe distance exceeds content width.png rename to library/src/androidTest/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_show last swipe action even when swipe distance exceeds content width.png diff --git a/library/src/test/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_swipe action's background should not be drawn behind content.png b/library/src/androidTest/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_swipe action's background should not be drawn behind content.png similarity index 100% rename from library/src/test/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_swipe action's background should not be drawn behind content.png rename to library/src/androidTest/snapshots/images/me.saket.swipe_SwipeableActionsBoxTest_swipe action's background should not be drawn behind content.png diff --git a/library/src/main/kotlin/me/saket/swipe/ActionFinder.kt b/library/src/commonMain/kotlin/me/saket/swipe/ActionFinder.kt similarity index 100% rename from library/src/main/kotlin/me/saket/swipe/ActionFinder.kt rename to library/src/commonMain/kotlin/me/saket/swipe/ActionFinder.kt diff --git a/library/src/main/kotlin/me/saket/swipe/SwipeAction.kt b/library/src/commonMain/kotlin/me/saket/swipe/SwipeAction.kt similarity index 100% rename from library/src/main/kotlin/me/saket/swipe/SwipeAction.kt rename to library/src/commonMain/kotlin/me/saket/swipe/SwipeAction.kt diff --git a/library/src/main/kotlin/me/saket/swipe/SwipeRipple.kt b/library/src/commonMain/kotlin/me/saket/swipe/SwipeRipple.kt similarity index 100% rename from library/src/main/kotlin/me/saket/swipe/SwipeRipple.kt rename to library/src/commonMain/kotlin/me/saket/swipe/SwipeRipple.kt diff --git a/library/src/main/kotlin/me/saket/swipe/SwipeableActionsBox.kt b/library/src/commonMain/kotlin/me/saket/swipe/SwipeableActionsBox.kt similarity index 100% rename from library/src/main/kotlin/me/saket/swipe/SwipeableActionsBox.kt rename to library/src/commonMain/kotlin/me/saket/swipe/SwipeableActionsBox.kt diff --git a/library/src/main/kotlin/me/saket/swipe/SwipeableActionsState.kt b/library/src/commonMain/kotlin/me/saket/swipe/SwipeableActionsState.kt similarity index 100% rename from library/src/main/kotlin/me/saket/swipe/SwipeableActionsState.kt rename to library/src/commonMain/kotlin/me/saket/swipe/SwipeableActionsState.kt diff --git a/library/src/main/kotlin/me/saket/swipe/defaults.kt b/library/src/commonMain/kotlin/me/saket/swipe/defaults.kt similarity index 100% rename from library/src/main/kotlin/me/saket/swipe/defaults.kt rename to library/src/commonMain/kotlin/me/saket/swipe/defaults.kt diff --git a/settings.gradle b/settings.gradle index 3185cad..cdef391 100644 --- a/settings.gradle +++ b/settings.gradle @@ -7,7 +7,6 @@ pluginManagement { } dependencyResolutionManagement { - repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral()