Skip to content

Commit

Permalink
add js support (#42)
Browse files Browse the repository at this point in the history
* add js support

* add js support to demo app

Signed-off-by: Calvin Liang <[email protected]>

---------

Signed-off-by: Calvin Liang <[email protected]>
Co-authored-by: Calvin Liang <[email protected]>
  • Loading branch information
EdwinChang24 and Calvin-LL authored Jul 28, 2024
1 parent 62c7392 commit 298101c
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ The latest demo app APK can be found in the [releases](https://github.com/Calvin

## Features

- Supports Compose Multiplatform (Android, iOS, Desktop/JVM, Wasm)
- Supports Compose Multiplatform (Android, iOS, Desktop/JVM, Wasm, JS)
- Supports items of different sizes
- Some items can be made non-reorderable
- Supports dragging immediately or long press to start dragging
Expand Down
10 changes: 10 additions & 0 deletions demoApp/composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ kotlin {
binaries.executable()
}

js {
moduleName = "composeApp"
browser {
commonWebpackConfig {
outputFileName = "composeApp.js"
}
}
binaries.executable()
}

listOf(
iosX64(),
iosArm64(),
Expand Down
13 changes: 13 additions & 0 deletions demoApp/composeApp/src/jsMain/kotlin/main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.window.CanvasBasedWindow
import org.jetbrains.skiko.wasm.onWasmReady
import sh.calvin.reorderable.demo.ui.App

@OptIn(ExperimentalComposeUiApi::class)
fun main() {
onWasmReady {
CanvasBasedWindow(canvasElementId = "ComposeTarget") {
App()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package sh.calvin.reorderable.demo

import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import kotlinx.browser.window

@Composable
actual fun rememberReorderHapticFeedback(): ReorderHapticFeedback {
val reorderHapticFeedback = remember {
object : ReorderHapticFeedback() {
override fun performHapticFeedback(type: ReorderHapticFeedbackType) {
when (type) {
ReorderHapticFeedbackType.START ->
window.navigator.vibrate(5)

ReorderHapticFeedbackType.MOVE ->
window.navigator.vibrate(1)

ReorderHapticFeedbackType.END ->
window.navigator.vibrate(3)
}
}
}
}

return reorderHapticFeedback
}
12 changes: 12 additions & 0 deletions demoApp/composeApp/src/jsMain/resources/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Compose App</title>
<script type="application/javascript" src="skiko.js"></script>
</head>
<body>
<canvas id="ComposeTarget"></canvas>
<script src="composeApp.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ SONATYPE_HOST=S01
RELEASE_SIGNING_ENABLED=true

org.jetbrains.compose.experimental.wasm.enabled=true
org.jetbrains.compose.experimental.jscanvas.enabled=true
5 changes: 5 additions & 0 deletions reorderable/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ kotlin {
binaries.executable()
}

js {
browser()
binaries.executable()
}

listOf(
iosX64(),
iosArm64(),
Expand Down

0 comments on commit 298101c

Please sign in to comment.