Skip to content

Commit

Permalink
feat: add WASM support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lavmee committed Dec 19, 2023
1 parent f2b9e28 commit a7443a1
Show file tree
Hide file tree
Showing 26 changed files with 253 additions and 23 deletions.
32 changes: 26 additions & 6 deletions compose/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import org.jetbrains.compose.ExperimentalComposeLibrary
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl

// Copyright 2023, Sergei Gagarin and the project contributors
// SPDX-License-Identifier: Apache-2.0
Expand Down Expand Up @@ -30,6 +31,15 @@ kotlin {
}
}

js(IR) {
browser()
}

@OptIn(ExperimentalWasmDsl::class)
wasmJs {
browser()
}

macosArm64()
macosX64()

Expand Down Expand Up @@ -76,8 +86,6 @@ kotlin {
implementation(compose.runtime)
@OptIn(ExperimentalComposeLibrary::class)
implementation(compose.components.resources)
implementation(libs.annotation)
implementation(libs.collection)
implementation(libs.kotlin.stdlib)
implementation(kotlin("reflect"))
}
Expand All @@ -87,11 +95,23 @@ kotlin {
dependsOn(commonMain)
}

val jvmMain by getting
val androidMain by getting
val jvmMain by getting {
dependsOn(jvmCommonMain)
}
val androidMain by getting {
dependsOn(jvmCommonMain)
}

jvmMain.dependsOn(jvmCommonMain)
androidMain.dependsOn(jvmCommonMain)
val webMain by creating {
dependsOn(commonMain)
}

val jsMain by getting {
dependsOn(webMain)
}
val wasmJsMain by getting {
dependsOn(webMain)
}

val commonTest by getting {
dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

package androidx.constraintlayout.compose

import androidx.annotation.FloatRange
import androidx.compose.foundation.layout.LayoutScopeMarker
import androidx.compose.runtime.Stable
import androidx.compose.ui.graphics.TransformOrigin
import androidx.compose.ui.layout.FirstBaseline
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.constraintlayout.compose.platform.annotation.FloatRange
import androidx.constraintlayout.core.parser.CLArray
import androidx.constraintlayout.core.parser.CLNumber
import androidx.constraintlayout.core.parser.CLObject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package androidx.constraintlayout.compose

import androidx.collection.IntIntPair
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.AnimationSpec
import androidx.compose.animation.core.tween
Expand Down Expand Up @@ -78,6 +77,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.util.fastForEach
import androidx.compose.ui.util.fastForEachIndexed
import androidx.constraintlayout.compose.extra.IntIntPair
import androidx.constraintlayout.compose.extra.parseLong
import androidx.constraintlayout.compose.platform.Log
import androidx.constraintlayout.compose.platform.annotation.Language
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import androidx.compose.runtime.Stable
import androidx.compose.ui.layout.FirstBaseline
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.constraintlayout.compose.platform.javaKlass
import androidx.constraintlayout.compose.extra.javaKlass
import androidx.constraintlayout.core.parser.CLArray
import androidx.constraintlayout.core.parser.CLElement
import androidx.constraintlayout.core.parser.CLNumber
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package androidx.constraintlayout.compose

import androidx.compose.runtime.Immutable
import androidx.compose.ui.layout.Measurable
import androidx.constraintlayout.compose.platform.javaKlass
import androidx.constraintlayout.compose.extra.javaKlass
import androidx.constraintlayout.core.parser.CLObject
import androidx.constraintlayout.core.state.ConstraintSetParser
import androidx.constraintlayout.core.state.ConstraintSetParser.LayoutVariables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.TextUnit
import androidx.constraintlayout.compose.platform.javaKlass
import androidx.constraintlayout.compose.extra.javaKlass
import androidx.constraintlayout.core.parser.CLObject

private const val UNDEFINED_NAME_PREFIX = "androidx.constraintlayout"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
package androidx.constraintlayout.compose

import androidx.compose.runtime.Immutable
import androidx.constraintlayout.compose.extra.javaKlass
import androidx.constraintlayout.compose.platform.Log
import androidx.constraintlayout.compose.platform.annotation.Language
import androidx.constraintlayout.compose.platform.annotation.SuppressLint
import androidx.constraintlayout.compose.platform.javaKlass
import androidx.constraintlayout.core.parser.CLObject
import androidx.constraintlayout.core.parser.CLParser
import androidx.constraintlayout.core.parser.CLParsingException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

package androidx.constraintlayout.compose

import androidx.annotation.FloatRange
import androidx.annotation.IntRange
import androidx.compose.foundation.layout.LayoutScopeMarker
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.constraintlayout.compose.platform.annotation.FloatRange
import androidx.constraintlayout.compose.platform.annotation.IntRange
import androidx.constraintlayout.core.parser.CLArray
import androidx.constraintlayout.core.parser.CLContainer
import androidx.constraintlayout.core.parser.CLNumber
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package androidx.constraintlayout.compose.extra

internal val Any.javaKlass get() = this::class
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package androidx.constraintlayout.compose.extra

import kotlin.jvm.JvmField
import kotlin.jvm.JvmInline

/**
* Container to ease passing around a tuple of two [Int] values.
*
* *Note*: This class is optimized by using a value class, a Kotlin language featured
* not available from Java code. Java developers can get the same functionality by
* using [Pair] or by constructing a custom implementation using Int parameters
* directly (see [LongLongPair] for an example).
*/
@JvmInline
internal value class IntIntPair internal constructor(
@PublishedApi @JvmField internal val packedValue: Long,
) {
/**
* Constructs a [IntIntPair] with two [Int] values.
*
* @param first the first value in the pair
* @param second the second value in the pair
*/
public constructor(first: Int, second: Int) : this(packInts(first, second))

/**
* The first value in the pair.
*/
public val first: Int
get() = (packedValue shr 32).toInt()

/**
* The second value in the pair.
*/
public val second: Int
get() = (packedValue and 0xFFFFFFFF).toInt()

/**
* Returns the [first] component of the pair. For instance, the first component
* of `PairIntInt(3, 4)` is `3`.
*
* This method allows to use destructuring declarations when working with pairs,
* for example:
* ```
* val (first, second) = myPair
* ```
*/
// NOTE: Unpack the value directly because using `first` forces an invokestatic
public inline operator fun component1(): Int = (packedValue shr 32).toInt()

/**
* Returns the [second] component of the pair. For instance, the second component
* of `PairIntInt(3, 4)` is `4`.
*
* This method allows to use destructuring declarations when working with pairs,
* for example:
* ```
* val (first, second) = myPair
* ```
*/
// NOTE: Unpack the value directly because using `second` forces an invokestatic
public inline operator fun component2(): Int = (packedValue and 0xFFFFFFFF).toInt()

override fun toString(): String = "($first, $second)"
}

/**
* Packs two Int values into one Long value for use in inline classes.
*/
private inline fun packInts(val1: Int, val2: Int): Long {
return (val1.toLong() shl 32) or (val2.toLong() and 0xFFFFFFFF)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package androidx.constraintlayout.compose.platform.annotation

/**
* Replace when androidx.annotation.FloatRange support wasm
*/
@Retention(AnnotationRetention.BINARY)
@Target(
AnnotationTarget.FUNCTION,
AnnotationTarget.PROPERTY_GETTER,
AnnotationTarget.PROPERTY_SETTER,
AnnotationTarget.VALUE_PARAMETER,
AnnotationTarget.FIELD,
AnnotationTarget.LOCAL_VARIABLE,
AnnotationTarget.ANNOTATION_CLASS,
)
annotation class FloatRange(
val from: Double = Double.NEGATIVE_INFINITY,
val to: Double = Double.POSITIVE_INFINITY,
val fromInclusive: Boolean = true,
val toInclusive: Boolean = true,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package androidx.constraintlayout.compose.platform.annotation

/**
* Replace when androidx.annotation.IntRange support wasm
*/
@Retention(AnnotationRetention.BINARY)
@Target(
AnnotationTarget.FUNCTION,
AnnotationTarget.PROPERTY_GETTER,
AnnotationTarget.PROPERTY_SETTER,
AnnotationTarget.VALUE_PARAMETER,
AnnotationTarget.FIELD,
AnnotationTarget.LOCAL_VARIABLE,
AnnotationTarget.ANNOTATION_CLASS,
)
annotation class IntRange(
val from: Long = Long.MIN_VALUE,
val to: Long = Long.MAX_VALUE,
)
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package androidx.constraintlayout.compose.platform.annotation

actual annotation class SuppressLint constructor(actual vararg val value: String)
actual annotation class SuppressLint(actual vararg val value: String)
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package androidx.constraintlayout.core.platform

import org.jetbrains.skiko.currentNanoTime

internal actual object System {
actual fun nanoTime(): Long = kotlin.system.getTimeNanos()
actual fun nanoTime(): Long = currentNanoTime()

actual val err: PrintStream
get() = object : PrintStream {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package androidx.constraintlayout.compose

internal actual val isShowingLayoutBounds: Boolean = false
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package androidx.constraintlayout.compose.platform

internal val Any.javaKlass get() = this::class
internal actual typealias Log = BasicLog
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package androidx.constraintlayout.compose.platform.annotation

actual annotation class Language actual constructor(actual val value: String)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package androidx.constraintlayout.compose.platform.annotation

actual annotation class SuppressLint actual constructor(actual vararg val value: String)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package androidx.constraintlayout.compose.platform.annotation

actual annotation class SuppressWarnings actual constructor(actual vararg val value: String)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package androidx.constraintlayout.core.platform

import org.jetbrains.skiko.currentNanoTime

internal actual object System {
actual fun nanoTime(): Long = currentNanoTime()

actual val err: PrintStream
get() = object : PrintStream {
override fun println(value: String) {
println(value)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package androidx.constraintlayout.core.platform

actual class WeakReference<T : Any> actual constructor(referred: T) {
private val workaroundReference: T = referred
actual fun get(): T? = workaroundReference
actual fun clear() {}
}
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ kotlin.mpp.enableCInteropCommonization=true
org.jetbrains.compose.experimental.uikit.enabled=true
org.jetbrains.compose.experimental.jscanvas.enabled=true
org.jetbrains.compose.experimental.macos.enabled=true
org.jetbrains.compose.experimental.wasm.enabled=true

#Android
android.useAndroidX=true
Expand All @@ -29,7 +30,7 @@ SONATYPE_CONNECT_TIMEOUT_SECONDS=600
SONATYPE_CLOSE_TIMEOUT_SECONDS=1800

GROUP=tech.annexflow.compose
VERSION_NAME=0.2.3
VERSION_NAME=0.3.0-alpha01

POM_URL=https://github.com/lavmee/constraintlayout-compose-multiplatform/
POM_SCM_URL=https://github.com/lavmee/constraintlayout-compose-multiplatform/
Expand Down
10 changes: 5 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[versions]

agp = "8.1.2"
agp = "8.1.4"
androidx-appcompat = "1.6.1"
androidx-activityCompose = "1.8.1"
annotation = "1.7.0"
collection = "1.4.0-beta01"
compose = "1.5.11"
androidx-activityCompose = "1.8.2"
annotation = "1.7.1"
collection = "1.4.0-beta02"
compose = "1.6.0-alpha01"
compose-uitooling = "1.5.4"
kotlin = "1.9.21"
maven-publish = "0.25.3"
Expand Down
Loading

0 comments on commit a7443a1

Please sign in to comment.