Skip to content

Commit c6ce6f5

Browse files
Merge pull request #3 from UmairKhalid786/feature/web_support_added
Web browser support added
2 parents 3fde166 + 46e1fd9 commit c6ce6f5

File tree

12 files changed

+2881
-4
lines changed

12 files changed

+2881
-4
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,7 @@ If you need to change this setting after you open the project in Android Studio,
9898
- open the project in Android Studio again
9999

100100
For configuring advanced settings, you can use Xcode. Open the `iosApp/iosApp.xcworkspace` in Xcode after opening the project in Android Studio, and use Xcode to make your changes.
101+
102+
### Web
103+
104+
- Run command for testing on web `gradle jsBrowserRun`

kotlin-js-store/yarn.lock

Lines changed: 2773 additions & 0 deletions
Large diffs are not rendered by default.

settings.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ pluginManagement {
2020
}
2121
}
2222

23-
rootProject.name = "My application"
23+
rootProject.name = "ServerDrivenUI"
2424

2525
include(":androidApp")
2626
include(":shared")
2727
include(":desktopApp")
28+
include(":webApp")

shared/build.gradle.kts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,24 @@ version = "1.0-SNAPSHOT"
1111

1212
kotlin {
1313
android()
14-
1514
jvm("desktop")
16-
1715
ios()
1816
iosSimulatorArm64()
17+
js(IR) {
18+
browser {
19+
testTask {
20+
testLogging.showStandardStreams = true
21+
useKarma {
22+
useChromeHeadless()
23+
useFirefox()
24+
}
25+
}
26+
}
27+
binaries.executable()
28+
}
29+
// js(IR) {
30+
// browser()
31+
// }
1932

2033
cocoapods {
2134
summary = "Some description for the Shared Module"
@@ -55,6 +68,13 @@ kotlin {
5568
implementation(compose.desktop.common)
5669
}
5770
}
71+
72+
val jsMain by getting {
73+
dependsOn(commonMain)
74+
dependencies {
75+
implementation(compose.web.core)
76+
}
77+
}
5878
}
5979
}
6080

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import App
21
import androidx.compose.ui.window.ComposeUIViewController
32

43
fun MainViewController() = ComposeUIViewController { App() }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
actual fun getPlatformName(): String = "Web"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import androidx.compose.runtime.Composable
2+
3+
@Composable
4+
fun CommonMainWeb() {
5+
App()
6+
}
7+
8+

webApp/build.gradle.kts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
plugins {
2+
kotlin("multiplatform")
3+
id("org.jetbrains.compose")
4+
}
5+
6+
kotlin {
7+
js(IR) {
8+
browser()
9+
binaries.executable()
10+
}
11+
sourceSets {
12+
val jsMain by getting {
13+
dependencies {
14+
implementation(project(":shared"))
15+
implementation(npm("path-browserify", "^1.0.1"))
16+
implementation(npm("os-browserify", "^0.3.0"))
17+
}
18+
}
19+
}
20+
}
21+
22+
compose.experimental {
23+
web.application {}
24+
}

webApp/src/jsMain/kotlin/WebApp.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import androidx.compose.foundation.layout.Column
2+
import androidx.compose.foundation.layout.fillMaxSize
3+
import androidx.compose.ui.Modifier
4+
import androidx.compose.ui.window.Window
5+
import org.jetbrains.skiko.wasm.onWasmReady
6+
7+
fun main() {
8+
onWasmReady {
9+
Window("Server Driven UI") {
10+
Column(modifier = Modifier.fillMaxSize()) {
11+
CommonMainWeb()
12+
}
13+
}
14+
}
15+
}
16+
17+
18+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Music App</title>
6+
<script src="skiko.js"></script>
7+
<link type="text/css" rel="stylesheet" href="styles.css"/>
8+
</head>
9+
<body>
10+
<div width="600" height="600">
11+
<canvas id="ComposeTarget"></canvas>
12+
</div>
13+
<script src="webApp.js"></script>
14+
</body>
15+
</html>

0 commit comments

Comments
 (0)