Skip to content

Commit babafec

Browse files
sadelliepingpongboss
authored andcommitted
Add kmp support to lib/
1 parent e13a14d commit babafec

File tree

15 files changed

+63
-38
lines changed

15 files changed

+63
-38
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@ google-services.json
3232

3333
# Android Profiling
3434
*.hprof
35+
36+
# Kotlin
37+
.kotlin

build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ plugins {
33
alias(libs.plugins.android.application) apply false
44
alias(libs.plugins.kotlin.android) apply false
55
alias(libs.plugins.kotlin.compose) apply false
6+
alias(libs.plugins.multiplatform) apply false
7+
alias(libs.plugins.compose.multiplatform) apply false
68
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# http://www.gradle.org/docs/current/userguide/build_environment.html
77
# Specifies the JVM arguments used for the daemon process.
88
# The setting is particularly useful for tweaking memory settings.
9-
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
9+
org.gradle.jvmargs=-Xmx4096m -Dfile.encoding=UTF-8
1010
# When configured, Gradle will run in incubating parallel mode.
1111
# This option should only be used with decoupled projects. For more details, visit
1212
# https://developer.android.com/r/tools/gradle-multi-project-decoupled-projects

gradle/libs.versions.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
[versions]
2-
agp = "8.13.0"
3-
kotlin = "2.0.21"
2+
kotlin = "2.2.20"
3+
agp = "8.12.3"
44
coreKtx = "1.17.0"
55
junit = "4.13.2"
66
junitVersion = "1.3.0"
77
espressoCore = "3.7.0"
88
lifecycleRuntimeKtx = "2.9.4"
99
activityCompose = "1.11.0"
1010
composeBom = "2025.09.01"
11+
composeMultiplatform = "1.9.0"
12+
material3 = "1.10.0-alpha01"
1113

1214
[libraries]
1315
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
@@ -24,9 +26,12 @@ androidx-compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "u
2426
androidx-compose-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
2527
androidx-compose-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
2628
androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3" }
29+
org-jetbrains-compose-material3-material3 = { module = "org.jetbrains.compose.material3:material3", version.ref = "material3" }
2730

2831
[plugins]
2932
android-application = { id = "com.android.application", version.ref = "agp" }
3033
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
3134
kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
35+
multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
36+
compose-multiplatform = { id = "org.jetbrains.compose", version.ref = "composeMultiplatform" }
3237

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Fri Oct 03 16:13:13 PDT 2025
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists

lib/build.gradle.kts

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,46 @@
1+
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
2+
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
13
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
24

35
plugins {
46
id("com.android.library")
5-
alias(libs.plugins.kotlin.android)
67
alias(libs.plugins.kotlin.compose)
8+
alias(libs.plugins.compose.multiplatform)
9+
alias(libs.plugins.multiplatform)
710

811
id("maven-publish")
912
}
1013

14+
kotlin {
15+
androidTarget {
16+
@OptIn(ExperimentalKotlinGradlePluginApi::class)
17+
compilerOptions { jvmTarget.set(JvmTarget.JVM_11) }
18+
}
19+
20+
jvm {
21+
@OptIn(ExperimentalKotlinGradlePluginApi::class)
22+
compilerOptions { jvmTarget.set(JvmTarget.JVM_11) }
23+
}
24+
25+
@OptIn(ExperimentalWasmDsl::class) wasmJs { browser() }
26+
27+
sourceSets {
28+
commonMain.dependencies {
29+
implementation(compose.ui)
30+
implementation(compose.foundation)
31+
}
32+
androidUnitTest.dependencies { implementation(libs.junit) }
33+
androidInstrumentedTest.dependencies {
34+
implementation(libs.androidx.junit)
35+
implementation(libs.androidx.espresso.core)
36+
implementation(project.dependencies.platform(libs.androidx.compose.bom))
37+
implementation(libs.androidx.compose.ui.test.junit4)
38+
implementation(libs.androidx.compose.ui.tooling)
39+
implementation(libs.androidx.compose.ui.test.manifest)
40+
}
41+
}
42+
}
43+
1144
android {
1245
namespace = "com.github.pingpongboss.explodedlayers"
1346
compileSdk = 36
@@ -32,12 +65,13 @@ android {
3265
sourceCompatibility = JavaVersion.VERSION_11
3366
targetCompatibility = JavaVersion.VERSION_11
3467
}
35-
kotlin { compilerOptions { jvmTarget = JvmTarget.fromTarget("11") } }
3668
buildFeatures { compose = true }
37-
38-
publishing { singleVariant("release") {} }
3969
}
4070

71+
group = "com.github.pingpongboss"
72+
73+
project.extra["artifactId"] = "compose-exploded-layers"
74+
4175
version =
4276
runCatching {
4377
// Try to get the latest annotated or lightweight tag name
@@ -47,7 +81,7 @@ version =
4781
"0.0.0-SNAPSHOT" // fallback if no tags yet
4882
}
4983

50-
fun String.runCommand(): String =
84+
private fun String.runCommand(): String =
5185
ProcessBuilder(*split(" ").toTypedArray())
5286
.redirectErrorStream(true)
5387
.start()
@@ -57,13 +91,7 @@ fun String.runCommand(): String =
5791

5892
publishing {
5993
publications {
60-
create<MavenPublication>("release") {
61-
// For Android:
62-
afterEvaluate { from(components["release"]) }
63-
64-
groupId = "com.github.pingpongboss"
65-
artifactId = "compose-exploded-layers"
66-
94+
publications.withType<MavenPublication>().configureEach {
6795
pom {
6896
name.set("Exploded Layers for Jetpack Compose")
6997
description.set("Turn any composable into an interactive “3D exploded view”.")
@@ -94,21 +122,3 @@ publishing {
94122
}
95123
}
96124
}
97-
98-
dependencies {
99-
implementation(libs.androidx.core.ktx)
100-
implementation(libs.androidx.lifecycle.runtime.ktx)
101-
implementation(libs.androidx.activity.compose)
102-
implementation(platform(libs.androidx.compose.bom))
103-
implementation(libs.androidx.compose.ui)
104-
implementation(libs.androidx.compose.ui.graphics)
105-
implementation(libs.androidx.compose.ui.tooling.preview)
106-
implementation(libs.androidx.compose.material3)
107-
testImplementation(libs.junit)
108-
androidTestImplementation(libs.androidx.junit)
109-
androidTestImplementation(libs.androidx.espresso.core)
110-
androidTestImplementation(platform(libs.androidx.compose.bom))
111-
androidTestImplementation(libs.androidx.compose.ui.test.junit4)
112-
debugImplementation(libs.androidx.compose.ui.tooling)
113-
debugImplementation(libs.androidx.compose.ui.test.manifest)
114-
}

lib/src/main/java/com/github/pingpongboss/explodedlayers/ExplodedLayers.kt renamed to lib/src/commonMain/kotlin/com/github/pingpongboss/explodedlayers/ExplodedLayers.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ import androidx.compose.ui.geometry.Offset
2424
import androidx.compose.ui.graphics.TransformOrigin
2525
import androidx.compose.ui.graphics.drawscope.drawIntoCanvas
2626
import androidx.compose.ui.graphics.graphicsLayer
27-
import androidx.compose.ui.graphics.nativeCanvas
2827
import androidx.compose.ui.layout.onGloballyPositioned
2928
import androidx.compose.ui.layout.positionInWindow
3029
import androidx.compose.ui.platform.LocalDensity
3130
import androidx.compose.ui.unit.DpOffset
3231
import androidx.compose.ui.unit.dp
3332
import androidx.compose.ui.unit.times
33+
import kotlin.math.PI
3434
import kotlin.math.tan
3535

3636
private val LocalState = compositionLocalOf<ExplodedLayersState?> { null }
@@ -256,7 +256,7 @@ private fun Modifier.skew(state: ExplodedLayersState): Modifier {
256256
val halfLifeY = state.initialOffset.y / 1.5f
257257

258258
drawWithContent {
259-
fun tanDeg(d: Float) = tan(Math.toRadians(d.toDouble())).toFloat()
259+
fun tanDeg(d: Float) = tan(toRadians(d.toDouble())).toFloat()
260260

261261
val normalizeX = normalize(state.offset.x.toPx(), halfLife = halfLifeX.toPx())
262262
val normalizeY = normalize(state.offset.y.toPx(), halfLife = halfLifeY.toPx())
@@ -271,7 +271,7 @@ private fun Modifier.skew(state: ExplodedLayersState): Modifier {
271271
drawIntoCanvas { canvas ->
272272
canvas.save()
273273
canvas.translate(px, py)
274-
canvas.nativeCanvas.skew(tanDeg(degreesX), tanDeg(degreesY))
274+
canvas.skew(tanDeg(degreesX), tanDeg(degreesY))
275275
canvas.translate(-px, -py)
276276

277277
// draw the original content under the skew
@@ -408,3 +408,6 @@ object ExplodedLayersDefaults {
408408
*/
409409
fun offset() = DpOffset(x = -40.dp, y = 40.dp)
410410
}
411+
412+
// java.Math is not available in kmp
413+
private fun toRadians(deg: Double): Double = deg / 180.0 * PI

lib/src/main/java/com/github/pingpongboss/explodedlayers/_Gestures.kt renamed to lib/src/commonMain/kotlin/com/github/pingpongboss/explodedlayers/_Gestures.kt

File renamed without changes.

lib/src/main/java/com/github/pingpongboss/explodedlayers/_Glass.kt renamed to lib/src/commonMain/kotlin/com/github/pingpongboss/explodedlayers/_Glass.kt

File renamed without changes.

0 commit comments

Comments
 (0)