Skip to content

Commit f8a366a

Browse files
committed
Add Web (wasm JS) support and update theme preference handling
1 parent 35589ef commit f8a366a

13 files changed

Lines changed: 104 additions & 3 deletions

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Supported platforms:
88
- Android
99
- iOS
1010
- Desktop JVM (MacOS, Linux, Windows)
11+
- Web (wasm JS)
1112

1213
![Android screenshot](doc/screenshots/gif/android/material_design_3/demo.gif)
1314
![iOS screenshot](doc/screenshots/gif/iOS/material_design_3/demo.gif)
@@ -103,6 +104,13 @@ private val preferences: NSUserDefaults = NSUserDefaults.standardUserDefaults
103104
actual var themeEnum: ThemeEnum
104105
get() = preferences.integerForKey(THEME_KEY).let(ThemeEnum.values()::get)
105106
set(value) = preferences.setInteger(value.ordinal, THEME_KEY)
107+
108+
// wasm js:
109+
private val storage: Storage = window.localStorage
110+
111+
actual var themeEnum: ThemeEnum
112+
get() = storage.getItem(THEME_KEY)?.toIntOrNull()?.let(ThemeEnum.values()::get) ?: ThemeEnum.SystemDefault
113+
set(value) = storage.setItem(THEME_KEY, value.ordinal.toString())
106114
```
107115
Also used [composition local](https://developer.android.com/jetpack/compose/compositionlocal) for access from theme-scoped as an implicit way:
108116
```kotlin

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
GROUP=io.github.softartdev
2-
VERSION=0.9.6
2+
VERSION=0.9.7
33

44
org.gradle.jvmargs=-Xmx16g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -Dkotlin.daemon.jvm.options\="-Xmx16g" -XX:+UseParallelGC -XX:MaxMetaspaceSize=1g
55
org.gradle.parallel=true

sample/build.gradle.kts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
22
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
3+
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
34

45
plugins {
56
kotlin("multiplatform")
@@ -24,6 +25,24 @@ kotlin {
2425
isStatic = true
2526
}
2627
}
28+
wasmJs {
29+
moduleName = "composeApp"
30+
browser {
31+
val rootDirPath = project.rootDir.path
32+
val projectDirPath = project.projectDir.path
33+
commonWebpackConfig {
34+
outputFileName = "composeApp.js"
35+
devServer = (devServer ?: KotlinWebpackConfig.DevServer()).apply {
36+
static = (static ?: mutableListOf()).apply {
37+
// Serve sources to debug inside browser
38+
add(rootDirPath)
39+
add(projectDirPath)
40+
}
41+
}
42+
}
43+
}
44+
binaries.executable()
45+
}
2746
sourceSets {
2847
commonMain.dependencies {
2948
api(project(":theme:theme-material"))
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.softartdev.shared
2+
3+
import androidx.compose.runtime.Composable
4+
5+
@Composable
6+
actual fun EnableEdgeToEdge(material3: Boolean, inDark: Boolean) {
7+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.softartdev.shared
2+
3+
import androidx.compose.ui.ExperimentalComposeUiApi
4+
import androidx.compose.ui.window.ComposeViewport
5+
import kotlinx.browser.document
6+
7+
@OptIn(ExperimentalComposeUiApi::class)
8+
fun main() {
9+
ComposeViewport(document.body!!) {
10+
App()
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Material Theme Preferences</title>
7+
<link type="text/css" rel="stylesheet" href="styles.css">
8+
<script type="application/javascript" src="composeApp.js"></script>
9+
</head>
10+
<body>
11+
</body>
12+
</html>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
html, body {
2+
width: 100%;
3+
height: 100%;
4+
margin: 0;
5+
padding: 0;
6+
overflow: hidden;
7+
}

theme/theme-material/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ kotlin {
2323
iosX64()
2424
iosArm64()
2525
iosSimulatorArm64()
26+
wasmJs {
27+
browser()
28+
binaries.executable()
29+
}
2630
sourceSets {
2731
commonMain.dependencies {
2832
api(project(":theme:theme-prefs"))

theme/theme-material3/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ kotlin {
2323
iosX64()
2424
iosArm64()
2525
iosSimulatorArm64()
26+
wasmJs {
27+
browser()
28+
binaries.executable()
29+
}
2630
sourceSets {
2731
commonMain.dependencies {
2832
api(project(":theme:theme-prefs"))

theme/theme-prefs/build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ kotlin {
2121
iosX64()
2222
iosArm64()
2323
iosSimulatorArm64()
24+
wasmJs {
25+
browser()
26+
binaries.executable()
27+
}
2428
applyDefaultHierarchyTemplate()
2529

2630
sourceSets {
@@ -35,6 +39,9 @@ kotlin {
3539
androidMain.dependencies {
3640
api(compose.ui)
3741
}
42+
wasmJsMain.dependencies {
43+
implementation("org.jetbrains.kotlinx:kotlinx-browser:0.3")
44+
}
3845
}
3946
explicitApi()
4047
}

0 commit comments

Comments
 (0)