Skip to content

Commit

Permalink
Add wasmjs target
Browse files Browse the repository at this point in the history
  • Loading branch information
xxfast committed Sep 24, 2024
1 parent a9e84ed commit 523b549
Show file tree
Hide file tree
Showing 17 changed files with 289 additions and 440 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ jobs:
run: chmod +x gradlew

- name: Build with Gradle
run: ./gradlew :app:web:jsBrowserDistribution
run: ./gradlew :app:web:wasmJsBrowserDistribution

- name: Upload pages artifact
uses: actions/upload-pages-artifact@v1
with:
path: ${{ github.workspace }}/app/web/build/dist/js/productionExecutable
path: ${{ github.workspace }}/app/web/build/dist/wasmJs/productionExecutable

- name: Deploy to GitHub Pages
id: deployment
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# <img src=".idea/icon.svg" height="23"/> NYTimes-KMP

[![Build](https://github.com/xxfast/NYTimes-KMP/actions/workflows/build.yml/badge.svg)](https://github.com/xxfast/NYTimes-KMP/actions/workflows/build.yml)
[![Kotlin](https://img.shields.io/badge/Kotlin-2.0.10-blue.svg?style=flat&logo=kotlin)](https://kotlinlang.org)
[![Kotlin](https://img.shields.io/badge/Kotlin-2.0.20-blue.svg?style=flat&logo=kotlin)](https://kotlinlang.org)

![badge-android](http://img.shields.io/badge/platform-android-6EDB8D.svg?style=flat)
![badge-wearos](http://img.shields.io/badge/platform-wearos-8ECDA0.svg?style=flat)
Expand Down
14 changes: 13 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties
import com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl

plugins {
kotlin("multiplatform")
Expand Down Expand Up @@ -39,6 +40,11 @@ kotlin {
browser()
}

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

sourceSets {
val commonMain by getting {
dependencies {
Expand All @@ -53,7 +59,6 @@ kotlin {
implementation(libs.compose.multiplatform.material3.windowsizeclass)
implementation(libs.decompose)
implementation(libs.decompose.compose)
implementation(libs.essenty.parcelable)
implementation(libs.ktor.client.core)
implementation(libs.ktor.client.content.negotiation)
implementation(libs.ktor.client.logging)
Expand Down Expand Up @@ -99,6 +104,13 @@ kotlin {
implementation(libs.kstore.storage)
}
}

val wasmJsMain by getting {
dependencies {
implementation(libs.ktor.client.js)
implementation(libs.kstore.storage)
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.github.xxfast.nytimes.models

import com.arkivanov.essenty.parcelable.Parcelable
import io.github.xxfast.nytimes.models.TopStorySections.arts
import io.github.xxfast.nytimes.models.TopStorySections.automobiles
import io.github.xxfast.nytimes.models.TopStorySections.books
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.github.xxfast.nytimes.data

import io.github.xxfast.kstore.KStore
import io.github.xxfast.kstore.storage.storeOf
import io.github.xxfast.nytimes.models.SavedArticles

actual val store: KStore<SavedArticles> by lazy {
storeOf("saved", emptySet())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.github.xxfast.nytimes.navigation

import com.arkivanov.essenty.instancekeeper.InstanceKeeper
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlin.coroutines.CoroutineContext

actual open class ViewModel : InstanceKeeper.Instance, CoroutineScope {
actual override val coroutineContext: CoroutineContext = Dispatchers.Unconfined + SupervisorJob()
override fun onDestroy() { coroutineContext.cancel() }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.github.xxfast.nytimes.utils

import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.ui.unit.dp

actual val WindowInsets.Companion.statusBarPadding: WindowInsets get() = WindowInsets(0.dp)

actual val WindowInsets.Companion.navigationBarPadding: WindowInsets get() = WindowInsets(0.dp)


1 change: 0 additions & 1 deletion app/wear/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ dependencies {
implementation(libs.wear.compose.material)
implementation(libs.wear.compose.ui.tooling)
implementation(libs.androidx.activity.compose)
implementation(libs.essenty.parcelable)
implementation(libs.decompose)
implementation(libs.decompose.router)
implementation(libs.decompose.router.wear)
Expand Down
10 changes: 9 additions & 1 deletion app/web/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl

plugins {
kotlin("multiplatform")
alias(libs.plugins.compose.multiplatform)
Expand All @@ -10,8 +12,14 @@ kotlin {
binaries.executable()
}

@OptIn(ExperimentalWasmDsl::class)
wasmJs {
browser()
binaries.executable()
}

sourceSets {
val jsMain by getting {
val commonMain by getting {
dependencies {
implementation(project(":app"))
implementation(compose.runtime)
Expand Down
File renamed without changes
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import androidx.compose.material3.windowsizeclass.WindowSizeClass
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.window.CanvasBasedWindow
import androidx.compose.ui.window.ComposeViewport
import io.github.xxfast.androidx.compose.material3.windowsizeclass.LocalWindowSizeClass
import io.github.xxfast.decompose.router.LocalRouterContext
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.github.xxfast.nytimes.web

import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
import androidx.compose.material3.windowsizeclass.WindowSizeClass
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.window.ComposeViewport
import io.github.xxfast.androidx.compose.material3.windowsizeclass.LocalWindowSizeClass
import io.github.xxfast.decompose.router.LocalRouterContext
import io.github.xxfast.decompose.router.RouterContext
import io.github.xxfast.decompose.router.defaultRouterContext
import io.github.xxfast.nytimes.screens.home.HomeScreen
import kotlinx.browser.document

@OptIn(ExperimentalComposeUiApi::class, ExperimentalMaterial3WindowSizeClassApi::class)
fun main() {
val rootRouterContext: RouterContext = defaultRouterContext()

ComposeViewport(document.body!!) {
BoxWithConstraints {
val windowSizeClass: WindowSizeClass = calculateWindowSizeClass()
CompositionLocalProvider(
LocalRouterContext provides rootRouterContext,
LocalWindowSizeClass provides windowSizeClass,
) {
MaterialTheme {
HomeScreen()
}
}
}
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Gradle
org.gradle.jvmargs=-Xmx2048M -Dfile.encoding=UTF-8 -Dkotlin.daemon.jvm.options\="-Xmx2048M"
org.gradle.jvmargs=-Xmx4g -Dfile.encoding=UTF-8 -Dkotlin.daemon.jvm.options\="-Xmx4g"
org.gradle.parallel=true
org.gradle.caching=true

Expand Down
5 changes: 2 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ decompose-router = "0.8.0"
essenty = "1.3.0-beta01"
harawata-appdirs = "1.2.1"
horologist = "0.4.11"
kotlin = "2.0.10"
kotlin = "2.0.20"
kotlinx-coroutines = "1.7.2"
kotlinx-datetime = "0.4.0"
kotlinx-datetime = "0.6.1"
kotlinx-serialization = "1.5.1"
kstore = "0.8.0"
ktor = "3.0.0-rc-1"
Expand All @@ -35,7 +35,6 @@ decompose = { module = "com.arkivanov.decompose:decompose", version.ref = "decom
decompose-router = { module = "io.github.xxfast:decompose-router", version.ref = "decompose-router" }
decompose-router-wear = { module = "io.github.xxfast:decompose-router-wear", version.ref = "decompose-router" }
decompose-compose = { module = "com.arkivanov.decompose:extensions-compose", version.ref = "decompose" }
essenty-parcelable = { module = "com.arkivanov.essenty:parcelable", version.ref = "essenty" }
harawata-appdirs = { module = "net.harawata:appdirs", version.ref = "harawata-appdirs" }
horologist-compose-layouts = { module = "com.google.android.horologist:horologist-compose-layout", version.ref = "horologist" }
kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
Expand Down
Loading

0 comments on commit 523b549

Please sign in to comment.