Skip to content

Commit b6f6f18

Browse files
authored
Merge pull request #11 from evilya/main
Update tutorial with wizard changes
2 parents 316d97f + a47107a commit b6f6f18

File tree

254 files changed

+723
-6732
lines changed

Some content is hidden

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

254 files changed

+723
-6732
lines changed

.gitignore

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,18 @@
1-
/.idea/
2-
.kotlin/
1+
*.iml
2+
.kotlin
3+
.gradle
4+
**/build/
5+
xcuserdata
6+
!src/**/build/
7+
local.properties
8+
.idea
9+
.DS_Store
10+
captures
11+
.externalNativeBuild
12+
.cxx
13+
*.xcodeproj/*
14+
!*.xcodeproj/project.pbxproj
15+
!*.xcodeproj/xcshareddata/
16+
!*.xcodeproj/project.xcworkspace/
17+
!*.xcworkspace/contents.xcworkspacedata
18+
**/xcshareddata/WorkspaceSettings.xcsettings

README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1-
# get-started-with-kmp
1+
### Source code for the ["Get started with Kotlin Multiplatform" tutorial](https://www.jetbrains.com/help/kotlin-multiplatform-dev/multiplatform-getting-started.html)
22

3-
Source code for the "Get started with Kotlin Multiplatform" tutorial: https://www.jetbrains.com/help/kotlin-multiplatform-dev/multiplatform-getting-started.html
3+
This is a Kotlin Multiplatform project targeting Android, iOS.
4+
5+
* `/composeApp` is for code that will be shared across your Compose Multiplatform applications.
6+
It contains several subfolders:
7+
- `commonMain` is for code that’s common for all targets.
8+
- Other folders are for Kotlin code that will be compiled for only the platform indicated in the folder name.
9+
For example, if you want to use Apple’s CoreCrypto for the iOS part of your Kotlin app,
10+
`iosMain` would be the right folder for such calls.
11+
12+
* `/iosApp` contains iOS applications. Even if you’re sharing your UI with Compose Multiplatform,
13+
you need this entry point for your iOS app. This is also where you should add SwiftUI code for your project.
14+
15+
* `/shared` is for the code that will be shared between all targets in the project.
16+
The most important subfolder is `commonMain`. If preferred, you can add code to the platform-specific folders here
17+
too.
18+
19+
Learn more about [Kotlin Multiplatform](https://www.jetbrains.com/help/kotlin-multiplatform-dev/get-started.html)

step3/build.gradle.kts renamed to build.gradle.kts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ plugins {
33
// in each subproject's classloader
44
alias(libs.plugins.androidApplication) apply false
55
alias(libs.plugins.androidLibrary) apply false
6-
alias(libs.plugins.jetbrainsCompose) apply false
6+
alias(libs.plugins.composeMultiplatform) apply false
7+
alias(libs.plugins.composeCompiler) apply false
78
alias(libs.plugins.kotlinMultiplatform) apply false
8-
alias(libs.plugins.compose.compiler) apply false
9+
id("com.google.devtools.ksp").version("2.1.21-2.0.1").apply(false)
10+
id("com.rickclephas.kmp.nativecoroutines").version("1.0.0-ALPHA-43").apply(false)
911
}
Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import org.jetbrains.compose.ExperimentalComposeLibrary
21
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
32
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
43
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
54

65
plugins {
76
alias(libs.plugins.kotlinMultiplatform)
87
alias(libs.plugins.androidApplication)
9-
alias(libs.plugins.jetbrainsCompose)
10-
alias(libs.plugins.compose.compiler)
8+
alias(libs.plugins.composeMultiplatform)
9+
alias(libs.plugins.composeCompiler)
1110
}
1211

1312
kotlin {
@@ -17,36 +16,39 @@ kotlin {
1716
jvmTarget.set(JvmTarget.JVM_11)
1817
}
1918
}
20-
19+
2120
sourceSets {
22-
21+
2322
androidMain.dependencies {
24-
implementation(libs.compose.ui.tooling.preview)
23+
implementation(compose.preview)
2524
implementation(libs.androidx.activity.compose)
25+
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2")
26+
implementation("androidx.lifecycle:lifecycle-runtime-compose:2.6.2")
27+
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.6.2")
2628
}
2729
commonMain.dependencies {
2830
implementation(compose.runtime)
2931
implementation(compose.foundation)
30-
implementation(compose.material)
32+
implementation(compose.material3)
3133
implementation(compose.ui)
32-
@OptIn(ExperimentalComposeLibrary::class)
3334
implementation(compose.components.resources)
3435
implementation(compose.components.uiToolingPreview)
36+
implementation(libs.androidx.lifecycle.viewmodel)
37+
implementation(libs.androidx.lifecycle.runtimeCompose)
3538
implementation(projects.shared)
3639
}
40+
commonTest.dependencies {
41+
implementation(libs.kotlin.test)
42+
}
3743
}
3844
}
3945

4046
android {
41-
namespace = "com.jetbrains.greeting"
47+
namespace = "com.jetbrains.greeting.greetingkmp"
4248
compileSdk = libs.versions.android.compileSdk.get().toInt()
4349

44-
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
45-
sourceSets["main"].res.srcDirs("src/androidMain/res")
46-
sourceSets["main"].resources.srcDirs("src/commonMain/resources")
47-
4850
defaultConfig {
49-
applicationId = "com.jetbrains.greeting"
51+
applicationId = "com.jetbrains.greeting.greetingkmp"
5052
minSdk = libs.versions.android.minSdk.get().toInt()
5153
targetSdk = libs.versions.android.targetSdk.get().toInt()
5254
versionCode = 1
@@ -66,8 +68,9 @@ android {
6668
sourceCompatibility = JavaVersion.VERSION_11
6769
targetCompatibility = JavaVersion.VERSION_11
6870
}
69-
dependencies {
70-
debugImplementation(libs.compose.ui.tooling)
71-
}
71+
}
72+
73+
dependencies {
74+
debugImplementation(compose.uiTooling)
7275
}
7376

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
<uses-permission android:name="android.permission.INTERNET"/>
4+
<application
5+
android:allowBackup="true"
6+
android:icon="@mipmap/ic_launcher"
7+
android:label="@string/app_name"
8+
android:roundIcon="@mipmap/ic_launcher_round"
9+
android:supportsRtl="true"
10+
android:theme="@android:style/Theme.Material.Light.NoActionBar">
11+
<activity
12+
android:exported="true"
13+
android:name=".MainActivity">
14+
<intent-filter>
15+
<action android:name="android.intent.action.MAIN"/>
16+
17+
<category android:name="android.intent.category.LAUNCHER"/>
18+
</intent-filter>
19+
</activity>
20+
</application>
21+
22+
</manifest>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<vector
2+
xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:aapt="http://schemas.android.com/aapt"
4+
android:width="450dp"
5+
android:height="450dp"
6+
android:viewportWidth="64"
7+
android:viewportHeight="64">
8+
<path
9+
android:pathData="M56.25,18V46L32,60 7.75,46V18L32,4Z"
10+
android:fillColor="#6075f2"/>
11+
<path
12+
android:pathData="m41.5,26.5v11L32,43V60L56.25,46V18Z"
13+
android:fillColor="#6b57ff"/>
14+
<path
15+
android:pathData="m32,43 l-9.5,-5.5v-11L7.75,18V46L32,60Z">
16+
<aapt:attr name="android:fillColor">
17+
<gradient
18+
android:centerX="23.131"
19+
android:centerY="18.441"
20+
android:gradientRadius="42.132"
21+
android:type="radial">
22+
<item android:offset="0" android:color="#FF5383EC"/>
23+
<item android:offset="0.867" android:color="#FF7F52FF"/>
24+
</gradient>
25+
</aapt:attr>
26+
</path>
27+
<path
28+
android:pathData="M22.5,26.5 L32,21 41.5,26.5 56.25,18 32,4 7.75,18Z">
29+
<aapt:attr name="android:fillColor">
30+
<gradient
31+
android:startX="44.172"
32+
android:startY="4.377"
33+
android:endX="17.973"
34+
android:endY="34.035"
35+
android:type="linear">
36+
<item android:offset="0" android:color="#FF33C3FF"/>
37+
<item android:offset="0.878" android:color="#FF5383EC"/>
38+
</gradient>
39+
</aapt:attr>
40+
</path>
41+
<path
42+
android:pathData="m32,21 l9.526,5.5v11L32,43 22.474,37.5v-11z"
43+
android:fillColor="#000000"/>
44+
</vector>

step5/composeApp/src/androidMain/kotlin/App.kt renamed to composeApp/src/androidMain/kotlin/com/jetbrains/greeting/greetingkmp/App.kt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
package com.jetbrains.greeting.greetingkmp
2+
13
import androidx.compose.foundation.layout.Arrangement
24
import androidx.compose.foundation.layout.Column
3-
import androidx.compose.foundation.layout.padding
4-
import androidx.compose.material.Divider
5-
import androidx.compose.material.MaterialTheme
6-
import androidx.compose.material.Text
5+
import androidx.compose.foundation.layout.fillMaxSize
6+
import androidx.compose.foundation.layout.safeContentPadding
7+
import androidx.compose.material3.HorizontalDivider
8+
import androidx.compose.material3.MaterialTheme
9+
import androidx.compose.material3.Text
710
import androidx.compose.runtime.Composable
8-
import androidx.compose.runtime.remember
11+
import androidx.compose.runtime.getValue
912
import androidx.compose.ui.Modifier
1013
import androidx.compose.ui.unit.dp
1114
import androidx.lifecycle.compose.collectAsStateWithLifecycle
12-
import androidx.compose.runtime.getValue
1315
import androidx.lifecycle.viewmodel.compose.viewModel
1416

1517
@Composable
@@ -18,12 +20,14 @@ fun App(mainViewModel: MainViewModel = viewModel()) {
1820
val greetings by mainViewModel.greetingList.collectAsStateWithLifecycle()
1921

2022
Column(
21-
modifier = Modifier.padding(all = 20.dp),
23+
modifier = Modifier
24+
.safeContentPadding()
25+
.fillMaxSize(),
2226
verticalArrangement = Arrangement.spacedBy(8.dp),
2327
) {
2428
greetings.forEach { greeting ->
2529
Text(greeting)
26-
Divider()
30+
HorizontalDivider()
2731
}
2832
}
2933
}

step4/composeApp/src/androidMain/kotlin/com/jetbrains/greeting/MainActivity.kt renamed to composeApp/src/androidMain/kotlin/com/jetbrains/greeting/greetingkmp/MainActivity.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
package com.jetbrains.greeting
1+
package com.jetbrains.greeting.greetingkmp
22

3-
import App
43
import android.os.Bundle
54
import androidx.activity.ComponentActivity
65
import androidx.activity.compose.setContent
6+
import androidx.activity.enableEdgeToEdge
77
import androidx.compose.runtime.Composable
88
import androidx.compose.ui.tooling.preview.Preview
99

1010
class MainActivity : ComponentActivity() {
1111
override fun onCreate(savedInstanceState: Bundle?) {
12+
enableEdgeToEdge()
1213
super.onCreate(savedInstanceState)
1314

1415
setContent {

step5skie/composeApp/src/androidMain/kotlin/MainViewModel.kt renamed to composeApp/src/androidMain/kotlin/com/jetbrains/greeting/greetingkmp/MainViewModel.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
package com.jetbrains.greeting.greetingkmp
2+
13
import androidx.lifecycle.ViewModel
24
import androidx.lifecycle.viewModelScope
35
import kotlinx.coroutines.flow.MutableStateFlow
46
import kotlinx.coroutines.flow.StateFlow
5-
import kotlinx.coroutines.launch
67
import kotlinx.coroutines.flow.update
8+
import kotlinx.coroutines.launch
79

810
class MainViewModel : ViewModel() {
911
private val _greetingList = MutableStateFlow<List<String>>(listOf())
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:aapt="http://schemas.android.com/aapt"
3+
android:width="108dp"
4+
android:height="108dp"
5+
android:viewportWidth="108"
6+
android:viewportHeight="108">
7+
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
8+
<aapt:attr name="android:fillColor">
9+
<gradient
10+
android:endX="85.84757"
11+
android:endY="92.4963"
12+
android:startX="42.9492"
13+
android:startY="49.59793"
14+
android:type="linear">
15+
<item
16+
android:color="#44000000"
17+
android:offset="0.0"/>
18+
<item
19+
android:color="#00000000"
20+
android:offset="1.0"/>
21+
</gradient>
22+
</aapt:attr>
23+
</path>
24+
<path
25+
android:fillColor="#FFFFFF"
26+
android:fillType="nonZero"
27+
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
28+
android:strokeWidth="1"
29+
android:strokeColor="#00000000"/>
30+
</vector>

0 commit comments

Comments
 (0)