Skip to content

Commit 942eb09

Browse files
committed
Add webApp module to follow the project convention
1 parent c7ddc4d commit 942eb09

File tree

15 files changed

+227
-240
lines changed

15 files changed

+227
-240
lines changed

compose-imageviewer/settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ rootProject.name = "imageviewer"
2727
include(":androidApp")
2828
include(":shared")
2929
include(":desktopApp")
30+
include(":webApp")

compose-imageviewer/shared/build.gradle.kts

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,11 @@ kotlin {
2121
// iosSimulatorArm64()
2222

2323
js(IR) {
24-
moduleName = "imageviewer"
2524
browser()
26-
binaries.executable()
2725
}
2826

2927
wasm {
30-
moduleName = "imageviewer"
31-
browser {
32-
commonWebpackConfig {
33-
devServer = (devServer ?: KotlinWebpackConfig.DevServer()).copy(
34-
open = mapOf(
35-
"app" to mapOf(
36-
"name" to "google chrome",
37-
)
38-
),
39-
)
40-
}
41-
}
42-
binaries.executable()
28+
browser()
4329
}
4430

4531
// cocoapods {
@@ -111,10 +97,6 @@ kotlin {
11197
}
11298
}
11399

114-
compose.experimental {
115-
web.application {}
116-
}
117-
118100
android {
119101
compileSdk = 33
120102
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
@@ -131,5 +113,5 @@ android {
131113
}
132114
}
133115

134-
// Use a proper version of webpack, TODO remove after updating to Kotlin 1.9.
135-
rootProject.the<NodeJsRootExtension>().versions.webpack.version = "5.76.2"
116+
// Use a proper version of webpack, TODO remove after updating to Kotlin 1.9.
117+
rootProject.the<NodeJsRootExtension>().versions.webpack.version = "5.76.2"

compose-imageviewer/shared/src/commonMain/kotlin/example/imageviewer/ImageViewer.common.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ enum class ExternalImageViewerEvent {
3434

3535
@OptIn(ExperimentalAnimationApi::class)
3636
@Composable
37-
internal fun ImageViewerCommon(
37+
fun ImageViewerCommon(
3838
dependencies: Dependencies,
3939
externalEvents: Flow<ExternalImageViewerEvent> = emptyFlow()
4040
) {

compose-imageviewer/shared/src/commonMain/kotlin/example/imageviewer/style/Palette.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ object ImageviewerColors {
4848
}
4949

5050
@Composable
51-
internal fun ImageViewerTheme(content: @Composable () -> Unit) {
51+
fun ImageViewerTheme(content: @Composable () -> Unit) {
5252
isSystemInDarkTheme() // todo check and change colors
5353
MaterialTheme(
5454
colorScheme = MaterialTheme.colorScheme.copy(

compose-imageviewer/shared/src/commonMain/kotlin/example/imageviewer/view/Toast.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ sealed interface ToastState {
2222
}
2323

2424
@Composable
25-
internal fun Toast(
25+
fun Toast(
2626
state: MutableState<ToastState>
2727
) {
2828
val value = state.value

compose-imageviewer/shared/src/wasmMain/kotlin/Main.wasm.kt

Lines changed: 0 additions & 188 deletions
This file was deleted.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
2+
3+
plugins {
4+
kotlin("multiplatform")
5+
id("org.jetbrains.compose")
6+
}
7+
8+
val copyJsResources = tasks.create("copyJsResourcesWorkaround", Copy::class.java) {
9+
from(project(":shared").file("src/commonMain/resources"))
10+
into("build/processedResources/js/main")
11+
}
12+
13+
val copyWasmResources = tasks.create("copyWasmResourcesWorkaround", Copy::class.java) {
14+
from(project(":shared").file("src/commonMain/resources"))
15+
into("build/processedResources/wasm/main")
16+
}
17+
18+
afterEvaluate {
19+
project.tasks.getByName("jsProcessResources").finalizedBy(copyJsResources)
20+
project.tasks.getByName("wasmProcessResources").finalizedBy(copyWasmResources)
21+
}
22+
23+
kotlin {
24+
js(IR) {
25+
moduleName = "imageviewer"
26+
browser()
27+
binaries.executable()
28+
}
29+
30+
wasm {
31+
moduleName = "imageviewer"
32+
browser {
33+
commonWebpackConfig {
34+
devServer = (devServer ?: KotlinWebpackConfig.DevServer()).copy(
35+
open = mapOf(
36+
"app" to mapOf(
37+
"name" to "google chrome",
38+
)
39+
),
40+
)
41+
}
42+
}
43+
binaries.executable()
44+
}
45+
46+
sourceSets {
47+
val jsWasmMain by creating {
48+
dependencies {
49+
implementation(project(":shared"))
50+
implementation(compose.runtime)
51+
implementation(compose.ui)
52+
implementation(compose.foundation)
53+
implementation(compose.material)
54+
@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
55+
implementation(compose.components.resources)
56+
}
57+
}
58+
val jsMain by getting {
59+
dependsOn(jsWasmMain)
60+
}
61+
val wasmMain by getting {
62+
dependsOn(jsWasmMain)
63+
}
64+
}
65+
}
66+
67+
compose.experimental {
68+
web.application {}
69+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import example.imageviewer.model.WrappedHttpClient
2+
import io.ktor.client.*
3+
import io.ktor.client.engine.js.*
4+
import io.ktor.client.request.*
5+
import io.ktor.client.statement.*
6+
7+
actual fun createWrappedHttpClient(): WrappedHttpClient {
8+
return object : WrappedHttpClient {
9+
private val ktorClient = HttpClient(JsClient())
10+
override suspend fun getAsBytes(urlString: String): ByteArray {
11+
return ktorClient.get(urlString).readBytes()
12+
}
13+
}
14+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import androidx.compose.runtime.*
2+
import androidx.compose.ui.ExperimentalComposeUiApi
3+
import androidx.compose.ui.window.CanvasBasedWindow
4+
import example.imageviewer.*
5+
import example.imageviewer.model.*
6+
import io.ktor.client.*
7+
import io.ktor.client.engine.js.*
8+
import io.ktor.client.request.*
9+
import io.ktor.client.statement.*
10+
import org.jetbrains.skiko.wasm.onWasmReady
11+
12+
@OptIn(ExperimentalComposeUiApi::class)
13+
fun main() {
14+
onWasmReady {
15+
CanvasBasedWindow("ImageViewer") {
16+
ImageViewerWeb()
17+
}
18+
}
19+
}

compose-imageviewer/shared/src/jsMain/resources/index.html renamed to compose-imageviewer/webApp/src/jsMain/resources/index.html

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
<script src="skiko.js"> </script>
77
</head>
88
<body>
9-
<center>
10-
<div style="background-color: darkslategrey;">
11-
<canvas id="ComposeTarget" width="800" height="1000"></canvas>
12-
</div>
13-
</center>
9+
<canvas id="ComposeTarget"></canvas>
1410
<script src="imageviewer.js"> </script>
1511
</body>
16-
</html>
12+
</html>

0 commit comments

Comments
 (0)