Skip to content

Commit 5d2083e

Browse files
committed
update: done with the bulk of instructions
1 parent d174de4 commit 5d2083e

File tree

3 files changed

+596
-205
lines changed

3 files changed

+596
-205
lines changed

topics/compose-onboard/compose-multiplatform-modify-project.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ To use the `kotlinx-datetime` library:
6969
1. Open the `composeApp/src/commonMain/kotlin/App.kt` file and add the following function which returns a string containing the current date:
7070
7171
```kotlin
72+
@OptIn(ExperimentalTime::class)
7273
fun todaysDate(): String {
7374
fun LocalDateTime.format() = toString().substringBefore('T')
7475

topics/compose-onboard/compose-multiplatform-new-project.md

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ To get started, implement a new `App` composable:
6868

6969
When you run your application and click the button, the hardcoded time is displayed.
7070

71-
3. Run the application on the desktop. It works, but the window is clearly too large for the UI:
71+
3. Run the application on the desktop (with the **composeApp [jvm]** run configuration).
72+
It works, but the window is clearly too large for the UI:
7273

7374
![New Compose Multiplatform app on desktop](first-compose-project-on-desktop-3.png){width=400}
7475

@@ -77,7 +78,7 @@ To get started, implement a new `App` composable:
7778
```kotlin
7879
fun main() = application {
7980
val state = rememberWindowState(
80-
size = DpSize(400.dp, 250.dp),
81+
size = DpSize(400.dp, 350.dp),
8182
position = WindowPosition(300.dp, 300.dp)
8283
)
8384
Window(
@@ -94,22 +95,22 @@ To get started, implement a new `App` composable:
9495
Here, you set the title of the window and use the `WindowState` type to give the window an initial size and position on
9596
the screen.
9697

97-
> To see your changes in real time in the desktop app, use [Compose Hot Reload](compose-hot-reload.md):
98-
> 1. In the `main.kt` file, click the **Run** icon in the gutter.
99-
> 2. Select **Run 'composeApp [hotRunJvm]' with Compose Hot Reload (Beta)**.
100-
> ![Run Compose Hot Reload from gutter](compose-hot-reload-gutter-run.png){width=350}
101-
>
102-
> To see the app automatically update, save any modified files (<shortcut>S</shortcut> / <shortcut>Ctrl+S</shortcut>).
103-
>
104-
> Compose Hot Reload is currently in [Beta](https://kotlinlang.org/components-stability.html#stability-levels-explained) so its functionality is subject to change.
105-
>
106-
{style="tip"}
107-
10898
5. Follow the IDE's instructions to import the missing dependencies.
10999
6. Run the desktop application again. Its appearance should improve:
110100
111101
![Improved appearance of the Compose Multiplatform app on desktop](first-compose-project-on-desktop-4.png){width=350}
112102
103+
> To see your changes in real time in the desktop app, use [Compose Hot Reload](compose-hot-reload.md):
104+
> 1. In the `main.kt` file, click the **Run** icon in the gutter.
105+
> 2. Select **Run 'composeApp [hotRunJvm]' with Compose Hot Reload (Beta)**.
106+
> ![Run Compose Hot Reload from gutter](compose-hot-reload-gutter-run.png){width=350}
107+
>
108+
> To see the app automatically update, save any modified files (<shortcut>⌘ S</shortcut> / <shortcut>Ctrl+S</shortcut>).
109+
>
110+
> Compose Hot Reload is currently in [Beta](https://kotlinlang.org/components-stability.html#stability-levels-explained) so its functionality is subject to change.
111+
>
112+
{style="tip"}
113+
113114
<!--
114115
### Compose Hot Reload demo {initial-collapse-state="collapsed" collapsible="true"}
115116
@@ -121,7 +122,7 @@ To get started, implement a new `App` composable:
121122
Now let users enter the name of a city to see the time at that location. The simplest way to achieve this is by adding
122123
a `TextField` composable:
123124
124-
1. Replace the current implementation of `App` with the one below:
125+
1. Replace the current implementation of `App()` in `commonMain/kotlin/compose.project.demo/App.kt` with the one below:
125126
126127
```kotlin
127128
@Composable
@@ -168,7 +169,8 @@ The next step is to use the given input to calculate time. To do this, create a
168169
1. Return to the `App.kt` file and add the following function:
169170
170171
```kotlin
171-
fun currentTimeAt(location: String): String? {
172+
@OptIn(ExperimentalTime::class)
173+
fun currentTimeAt(location: String): String? {
172174
fun LocalTime.formatted() = "$hour:$minute:$second"
173175
174176
return try {
@@ -300,6 +302,7 @@ list.
300302
```kotlin
301303
data class Country(val name: String, val zone: TimeZone)
302304
305+
@OptIn(ExperimentalTime::class)
303306
fun currentTimeAt(location: String, zone: TimeZone): String {
304307
fun LocalTime.formatted() = "$hour:$minute:$second"
305308
@@ -405,7 +408,7 @@ modify the build file.
405408
To support images in your project, you'll need to download image files, store them in the correct directory, and add
406409
code to load and display them:
407410

408-
1. Using an external resource, such as [Flag CDN](https://flagcdn.com/), download flags to match the list of countries
411+
1. Download flag images from [Flag CDN](https://flagcdn.com/) to match the list of countries
409412
you have already created. In this case, these
410413
are [Japan](https://flagcdn.com/w320/jp.png), [France](https://flagcdn.com/w320/fr.png), [Mexico](https://flagcdn.com/w320/mx.png), [Indonesia](https://flagcdn.com/w320/id.png),
411414
and [Egypt](https://flagcdn.com/w320/eg.png).
@@ -419,14 +422,15 @@ code to load and display them:
419422
4. Update the code in the `commonMain/kotlin/.../App.kt` file to support images:
420423

421424
```kotlin
422-
import compose.project.demo.generated.resources.eg
423-
import compose.project.demo.generated.resources.fr
424-
import compose.project.demo.generated.resources.id
425-
import compose.project.demo.generated.resources.jp
426-
import compose.project.demo.generated.resources.mx
425+
import demo.composeapp.generated.resources.jp
426+
import demo.composeapp.generated.resources.mx
427+
import demo.composeapp.generated.resources.eg
428+
import demo.composeapp.generated.resources.fr
429+
import demo.composeapp.generated.resources.id
427430

428-
data class Country(val name: String, val zone: TimeZone, val image: DrawableResource)
431+
data class Country(val name: String, val zone: TimeZone, val image: DrawableResource)
429432

433+
@OptIn(ExperimentalTime::class)
430434
fun currentTimeAt(location: String, zone: TimeZone): String {
431435
fun LocalTime.formatted() = "$hour:$minute:$second"
432436

0 commit comments

Comments
 (0)