Skip to content

Commit 86632d1

Browse files
authored
Merge pull request #3 from pahill/main
Update tutorial with new Kotlin, Compose, Wizard
2 parents 412dcb2 + 17d7bdc commit 86632d1

File tree

99 files changed

+1112
-708
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+1112
-708
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
.DS_Store
22

3+
.idea
4+

ComposeDemoStage1/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ captures
1616
!*.xcodeproj/project.xcworkspace/
1717
!*.xcworkspace/contents.xcworkspacedata
1818
**/xcshareddata/WorkspaceSettings.xcsettings
19+
.kotlin

ComposeDemoStage1/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ plugins {
44
alias(libs.plugins.androidApplication) apply false
55
alias(libs.plugins.androidLibrary) apply false
66
alias(libs.plugins.jetbrainsCompose) apply false
7+
alias(libs.plugins.compose.compiler) apply false
78
alias(libs.plugins.kotlinMultiplatform) apply false
89
}

ComposeDemoStage1/composeApp/build.gradle.kts

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,44 @@
1-
import org.jetbrains.compose.ExperimentalComposeLibrary
21
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
2+
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
3+
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
4+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
5+
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
36

47
plugins {
58
alias(libs.plugins.kotlinMultiplatform)
69
alias(libs.plugins.androidApplication)
710
alias(libs.plugins.jetbrainsCompose)
11+
alias(libs.plugins.compose.compiler)
812
}
913

1014
kotlin {
11-
androidTarget {
12-
compilations.all {
13-
kotlinOptions {
14-
jvmTarget = "1.8"
15+
@OptIn(ExperimentalWasmDsl::class)
16+
wasmJs {
17+
moduleName = "composeApp"
18+
browser {
19+
val projectDirPath = project.projectDir.path
20+
commonWebpackConfig {
21+
outputFileName = "composeApp.js"
22+
devServer = (devServer ?: KotlinWebpackConfig.DevServer()).apply {
23+
static = (static ?: mutableListOf()).apply {
24+
// Serve sources to debug inside browser
25+
add(projectDirPath)
26+
}
27+
}
1528
}
1629
}
30+
binaries.executable()
31+
}
32+
33+
androidTarget {
34+
@OptIn(ExperimentalKotlinGradlePluginApi::class)
35+
compilerOptions {
36+
jvmTarget.set(JvmTarget.JVM_11)
37+
}
1738
}
18-
39+
1940
jvm("desktop")
20-
41+
2142
listOf(
2243
iosX64(),
2344
iosArm64(),
@@ -28,40 +49,45 @@ kotlin {
2849
isStatic = true
2950
}
3051
}
31-
52+
3253
sourceSets {
3354
val desktopMain by getting
34-
55+
3556
androidMain.dependencies {
36-
implementation(libs.compose.ui.tooling.preview)
57+
implementation(compose.preview)
3758
implementation(libs.androidx.activity.compose)
3859
}
3960
commonMain.dependencies {
4061
implementation(compose.runtime)
4162
implementation(compose.foundation)
4263
implementation(compose.material)
4364
implementation(compose.ui)
44-
@OptIn(ExperimentalComposeLibrary::class)
4565
implementation(compose.components.resources)
46-
47-
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.1")
66+
implementation(compose.components.uiToolingPreview)
67+
implementation(libs.androidx.lifecycle.viewmodel)
68+
implementation(libs.androidx.lifecycle.runtime.compose)
69+
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.6.0")
4870
}
4971
desktopMain.dependencies {
5072
implementation(compose.desktop.currentOs)
73+
implementation(libs.kotlinx.coroutines.swing)
74+
}
75+
wasmJsMain.dependencies {
76+
implementation(npm("@js-joda/timezone", "2.3.0"))
5177
}
5278
}
5379
}
5480

5581
android {
56-
namespace = "kmp.compose.demo"
82+
namespace = "compose.project.demo"
5783
compileSdk = libs.versions.android.compileSdk.get().toInt()
5884

5985
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
6086
sourceSets["main"].res.srcDirs("src/androidMain/res")
6187
sourceSets["main"].resources.srcDirs("src/commonMain/resources")
6288

6389
defaultConfig {
64-
applicationId = "kmp.compose.demo"
90+
applicationId = "compose.project.demo"
6591
minSdk = libs.versions.android.minSdk.get().toInt()
6692
targetSdk = libs.versions.android.targetSdk.get().toInt()
6793
versionCode = 1
@@ -78,21 +104,24 @@ android {
78104
}
79105
}
80106
compileOptions {
81-
sourceCompatibility = JavaVersion.VERSION_1_8
82-
targetCompatibility = JavaVersion.VERSION_1_8
107+
sourceCompatibility = JavaVersion.VERSION_11
108+
targetCompatibility = JavaVersion.VERSION_11
109+
}
110+
buildFeatures {
111+
compose = true
83112
}
84113
dependencies {
85-
debugImplementation(libs.compose.ui.tooling)
114+
debugImplementation(compose.uiTooling)
86115
}
87116
}
88117

89118
compose.desktop {
90119
application {
91-
mainClass = "MainKt"
120+
mainClass = "compose.project.demo.MainKt"
92121

93122
nativeDistributions {
94123
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
95-
packageName = "kmp.compose.demo"
124+
packageName = "compose.project.demo"
96125
packageVersion = "1.0.0"
97126
}
98127
}

ComposeDemoStage1/composeApp/src/androidMain/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
</activity>
2121
</application>
2222

23-
</manifest>
23+
</manifest>

ComposeDemoStage4/composeApp/src/androidMain/kotlin/kmp/compose/demo/MainActivity.kt renamed to ComposeDemoStage1/composeApp/src/androidMain/kotlin/compose/project/demo/MainActivity.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
package kmp.compose.demo
1+
package compose.project.demo
22

3-
import App
43
import android.os.Bundle
54
import androidx.activity.ComponentActivity
65
import androidx.activity.compose.setContent

ComposeDemoStage1/composeApp/src/androidMain/kotlin/Platform.android.kt renamed to ComposeDemoStage1/composeApp/src/androidMain/kotlin/compose/project/demo/Platform.android.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package compose.project.demo
2+
13
import android.os.Build
24

35
class AndroidPlatform : Platform {

ComposeDemoStage1/composeApp/src/androidMain/res/drawable/ic_launcher_background.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,4 @@
167167
android:pathData="M79,19L79,89"
168168
android:strokeWidth="0.8"
169169
android:strokeColor="#33FFFFFF" />
170-
</vector>
170+
</vector>

ComposeDemoStage1/composeApp/src/commonMain/composeResources/drawable/compose-multiplatform.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@
3333
android:fillColor="#00000000"
3434
android:strokeColor="#083042"
3535
android:fillType="nonZero"/>
36-
</vector>
36+
</vector>
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package compose.project.demo
2+
13
import androidx.compose.animation.AnimatedVisibility
24
import androidx.compose.foundation.Image
35
import androidx.compose.foundation.layout.Column
@@ -6,57 +8,52 @@ import androidx.compose.foundation.layout.padding
68
import androidx.compose.material.Button
79
import androidx.compose.material.MaterialTheme
810
import androidx.compose.material.Text
9-
import androidx.compose.runtime.Composable
10-
import androidx.compose.runtime.getValue
11-
import androidx.compose.runtime.mutableStateOf
12-
import androidx.compose.runtime.remember
13-
import androidx.compose.runtime.setValue
11+
import androidx.compose.runtime.*
1412
import androidx.compose.ui.Alignment
1513
import androidx.compose.ui.Modifier
1614
import androidx.compose.ui.text.style.TextAlign
1715
import androidx.compose.ui.unit.dp
1816
import androidx.compose.ui.unit.sp
19-
import kotlinproject.composeapp.generated.resources.*
17+
import org.jetbrains.compose.resources.painterResource
18+
import org.jetbrains.compose.ui.tooling.preview.Preview
19+
20+
import composedemo.composeapp.generated.resources.Res
21+
import composedemo.composeapp.generated.resources.compose_multiplatform
2022
import kotlinx.datetime.Clock
2123
import kotlinx.datetime.LocalDateTime
2224
import kotlinx.datetime.TimeZone
2325
import kotlinx.datetime.toLocalDateTime
24-
import org.jetbrains.compose.resources.ExperimentalResourceApi
25-
import org.jetbrains.compose.resources.painterResource
26-
27-
fun todaysDate(): String {
28-
fun LocalDateTime.format() = toString().substringBefore('T')
29-
30-
val now = Clock.System.now()
31-
val zone = TimeZone.currentSystemDefault()
32-
return now.toLocalDateTime(zone).format()
33-
}
3426

35-
@OptIn(ExperimentalResourceApi::class)
3627
@Composable
28+
@Preview
3729
fun App() {
3830
MaterialTheme {
39-
var greetingText by remember { mutableStateOf("Hello World!") }
40-
var showImage by remember { mutableStateOf(false) }
31+
var showContent by remember { mutableStateOf(false) }
32+
val greeting = remember { Greeting().greet() }
4133
Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
4234
Text(
4335
text = "Today's date is ${todaysDate()}",
4436
modifier = Modifier.padding(20.dp),
4537
fontSize = 24.sp,
4638
textAlign = TextAlign.Center
4739
)
48-
Button(onClick = {
49-
greetingText = "Compose: ${Greeting().greet()}"
50-
showImage = !showImage
51-
}) {
52-
Text(greetingText)
40+
Button(onClick = { showContent = !showContent }) {
41+
Text("Click me!")
5342
}
54-
AnimatedVisibility(showImage) {
55-
Image(
56-
painterResource(Res.drawable.compose_multiplatform),
57-
null
58-
)
43+
AnimatedVisibility(showContent) {
44+
Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
45+
Image(painterResource(Res.drawable.compose_multiplatform), null)
46+
Text("Compose: $greeting")
47+
}
5948
}
6049
}
6150
}
51+
}
52+
53+
fun todaysDate(): String {
54+
fun LocalDateTime.format() = toString().substringBefore('T')
55+
56+
val now = Clock.System.now()
57+
val zone = TimeZone.currentSystemDefault()
58+
return now.toLocalDateTime(zone).format()
6259
}

0 commit comments

Comments
 (0)