Skip to content

Commit

Permalink
Add hot reload plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
zsmb13 committed Nov 18, 2024
1 parent a86896c commit 083366d
Show file tree
Hide file tree
Showing 21 changed files with 122 additions and 35 deletions.
2 changes: 1 addition & 1 deletion backend/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ application {
}

dependencies {
implementation(project(":shared"))
implementation(projects.models)
implementation(libs.ktor.server.netty)
implementation(libs.ktor.server.auth)
implementation(libs.ktor.serialization.kotlinx.json)
Expand Down
9 changes: 1 addition & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
allprojects {
repositories {
maven("https://maven.pkg.jetbrains.space/public/p/ktor/eap")
google()
mavenCentral()
}
}

plugins {
alias(libs.plugins.androidApplication) apply false
alias(libs.plugins.androidLibrary) apply false
Expand All @@ -15,6 +7,7 @@ plugins {
alias(libs.plugins.kotlinSerialization) apply false
alias(libs.plugins.kotlinJvm) apply false
alias(libs.plugins.compose.compiler) apply false
alias(libs.plugins.composeHotReload) apply false
}

tasks.wrapper {
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ kotlin = "2.0.21"

compose-android = "1.7.1"
compose-multiplatform = "1.7.0"
compose-hot-reload = "1.0.0-dev.27"

exposed = "0.55.0"
h2 = "2.2.224"
Expand Down Expand Up @@ -99,3 +100,4 @@ kotlinSerialization = { id = "org.jetbrains.kotlin.plugin.serialization", versio
kotlinParcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref = "kotlin" }
kotlinJvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
composeHotReload = { id = "org.jetbrains.compose-hot-reload", version.ref = "compose-hot-reload" }
43 changes: 43 additions & 0 deletions models/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl

plugins {
alias(libs.plugins.androidLibrary)
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.kotlinSerialization)
}

kotlin {
androidTarget()

jvm()

iosX64()
iosArm64()
iosSimulatorArm64()

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

sourceSets.commonMain.dependencies {
api(libs.ktor.serialization.kotlinx.json)
implementation(libs.kotlinx.datetime)
}
}

android {
namespace = "com.jetbrains.kotlinconf"
compileSdk = libs.versions.android.compileSdk.get().toInt()
defaultConfig {
minSdk = libs.versions.android.minSdk.get().toInt()
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlin {
jvmToolchain(11)
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
package org.jetbrains.kotlinconf

import io.ktor.util.date.GMTDate
import kotlinconfapp.shared.generated.resources.Res
import kotlinconfapp.shared.generated.resources.day_1
import kotlinconfapp.shared.generated.resources.day_2
import kotlinconfapp.shared.generated.resources.day_3
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.StringResource
import io.ktor.util.date.*
import org.jetbrains.kotlinconf.utils.time

data class Agenda(
Expand All @@ -20,11 +14,10 @@ data class Speakers(
operator fun get(id: String): Speaker? = dictById[id]
}

@OptIn(ExperimentalResourceApi::class)
enum class EventDay(val title: StringResource) {
May22(Res.string.day_1),
May23(Res.string.day_2),
May24(Res.string.day_3);
enum class EventDay(val title: String) {
May22("May 22"),
May23("May 23"),
May24("May 24");

companion object {
fun from(value: Int) = when (value) {
Expand All @@ -39,7 +32,7 @@ data class Day(
val day: EventDay,
val timeSlots: List<TimeSlot>
) {
val title: StringResource
val title: String
get() = day.title
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ object GMTDateSerializer : KSerializer<GMTDate> {
}
}

internal fun GMTDate.time(): String = "${hours.toString(2)}:${minutes.toString(2)}"
fun GMTDate.time(): String = "${hours.toString(2)}:${minutes.toString(2)}"

internal fun GMTDate.dayAndMonth(): String = "${month.value} $dayOfMonth"

Expand Down
3 changes: 3 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pluginManagement {
google()
gradlePluginPortal()
mavenCentral()
maven("https://repo.sellmair.io")
}
}

Expand All @@ -18,6 +19,7 @@ dependencyResolutionManagement {
maven("https://maven.pkg.jetbrains.space/public/p/ktor/eap")
google()
mavenCentral()
maven("https://repo.sellmair.io")
}
}

Expand All @@ -27,5 +29,6 @@ plugins {

include(":androidApp")
include(":ui-components")
include(":models")
include(":shared")
include(":backend")
1 change: 1 addition & 0 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ kotlin {
sourceSets {
commonMain.dependencies {
implementation(projects.uiComponents)
implementation(projects.models)

api(compose.runtime)
api(compose.foundation)
Expand Down
3 changes: 0 additions & 3 deletions shared/src/commonMain/composeResources/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ Bella Center Copenhagen, Denmark</string>
<string name="speakers">Speakers</string>
<string name="past">Past</string>
<string name="upcoming">Upcoming</string>
<string name="day_1">May 22</string>
<string name="day_2">May 23</string>
<string name="day_3">May 24</string>
<string name="floor_1">Ground floor</string>
<string name="floor_2">First floor</string>
<string name="talks">Talks</string>
Expand Down
7 changes: 7 additions & 0 deletions ui-components/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
alias(libs.plugins.jetbrainsCompose)
alias(libs.plugins.compose.compiler)
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.composeHotReload)
}

kotlin {
Expand All @@ -31,6 +32,12 @@ kotlin {
api(compose.components.resources)
api(compose.components.uiToolingPreview)
}

// For hot-reload
jvmMain.dependencies {
implementation(compose.desktop.currentOs)
implementation(libs.logback.classic)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fun CardTag(

@Preview
@Composable
private fun CardTagPreview() {
internal fun CardTagPreview() {
PreviewHelper {
var state1 by remember { mutableStateOf(false) }
CardTag("Label", state1, { state1 = it })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fun FilterTag(

@Preview
@Composable
private fun FilterTagPreview() {
internal fun FilterTagPreview() {
PreviewHelper {
var state1 by remember { mutableStateOf(false) }
FilterTag("Label", state1, { state1 = it })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fun NowButton(

@Preview
@Composable
private fun NowButtonPreview() {
internal fun NowButtonPreview() {
PreviewHelper {
NowButton(true, {})
NowButton(false, {})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fun NowLabel(modifier: Modifier = Modifier) {

@Composable
@Preview
private fun NowLabelPreview() {
internal fun NowLabelPreview() {
PreviewHelper {
NowLabel()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fun SectionTitle(

@Preview
@Composable
private fun SectionTitlePreview() {
internal fun SectionTitlePreview() {
PreviewHelper {
SectionTitle("Section title")
SectionTitle("7:30")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private fun SwitcherItem(

@Preview
@Composable
private fun SwitcherItemPreview() {
internal fun SwitcherItemPreview() {
PreviewHelper {
SwitcherItem("Normal item", {}, selected = false)
SwitcherItem("Selected item", {}, selected = true)
Expand Down Expand Up @@ -103,7 +103,7 @@ fun Switcher(

@Composable
@Preview
private fun SwitcherPreview() {
internal fun SwitcherPreview() {
PreviewHelper {
var selectedIndex by remember { mutableIntStateOf(0) }
Switcher(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fun TopMenuButton(

@Preview
@Composable
private fun TopMenuButtonPreview() {
internal fun TopMenuButtonPreview() {
PreviewHelper {
var state1 by remember { mutableStateOf(false) }
TopMenuButton(state1, { state1 = it }, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fun TopMenuTitle(

@Preview
@Composable
private fun TopMenuTitlePreview() {
internal fun TopMenuTitlePreview() {
PreviewHelper {
TopMenuTitle("Top Menu Title", TopMenuTitleState.Header)
TopMenuTitle("Top Menu Title", TopMenuTitleState.Completed)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.jetbrains.kotlinconf.ui.components

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
import androidx.compose.ui.window.rememberWindowState
import org.jetbrains.compose.reload.DevelopmentEntryPoint

fun main() {
application {
Window(
onCloseRequest = ::exitApplication,
alwaysOnTop = true,
state = rememberWindowState(width = 1000.dp, height = 800.dp),
title = "Gallery",
) {
DevelopmentEntryPoint {
GalleryApp()
}
}
}
}

@Composable
private fun GalleryApp() {
CompositionLocalProvider(LocalDensity provides Density(4f)) {

Column(Modifier.verticalScroll(rememberScrollState())) {
CardTagPreview()
FilterTagPreview()
NowButtonPreview()
NowLabelPreview()
SectionTitlePreview()
SwitcherItemPreview()
SwitcherPreview()
TopMenuButtonPreview()
TopMenuTitlePreview()
}
}
}

0 comments on commit 083366d

Please sign in to comment.