diff --git a/docs/images/multiplatform-mobile/create-first-app/first-multiplatform-project-3.png b/docs/images/multiplatform-mobile/create-first-app/first-multiplatform-project-3.png index fb441c07dd0..1f96b57eeb5 100644 Binary files a/docs/images/multiplatform-mobile/create-first-app/first-multiplatform-project-3.png and b/docs/images/multiplatform-mobile/create-first-app/first-multiplatform-project-3.png differ diff --git a/docs/images/multiplatform-mobile/create-first-app/multiplatform-mobile-upgrade.png b/docs/images/multiplatform-mobile/create-first-app/multiplatform-mobile-upgrade.png index c5e5de33bfa..4f6141a6cac 100644 Binary files a/docs/images/multiplatform-mobile/create-first-app/multiplatform-mobile-upgrade.png and b/docs/images/multiplatform-mobile/create-first-app/multiplatform-mobile-upgrade.png differ diff --git a/docs/topics/multiplatform-mobile/multiplatform-mobile-create-first-app.md b/docs/topics/multiplatform-mobile/multiplatform-mobile-create-first-app.md index 272beeeec16..b11d169d8bf 100644 --- a/docs/topics/multiplatform-mobile/multiplatform-mobile-create-first-app.md +++ b/docs/topics/multiplatform-mobile/multiplatform-mobile-create-first-app.md @@ -82,14 +82,19 @@ IDE will show a warning: 1. Open the `Greeting.kt` file and try to access one of the Java classes, `java.util.Random().nextBoolean()`, inside the `greet()` function: ```kotlin + import java.util.Random + fun greet(): String { val firstWord = if (Random().nextBoolean()) "Hi!" else "Hello!" } ``` Android Studio highlights that `Random` class is unresolved because you can't call specific Java functions from the common Kotlin code. -2. Follow IDE's suggestions and replace it with `kotlin.random.Random` from the Kotlin standard library. The code now compiles successfully. -3. Add a bit of unpredictability to the greeting: +2. Follow IDE's suggestions and replace it with `kotlin.random.Random` from the Kotlin standard library. + This is a multiplatform library that works on all platforms and is included automatically as a dependency. + The code should now compile successfully. +3. Add a bit of unpredictability to the greeting. Update the shared code with the `reversed()` function + from the Kotlin standard library for reversing the text: ```kotlin import kotlin.random.Random @@ -100,8 +105,7 @@ IDE will show a warning: fun greet(): String { val firstWord = if (Random.nextBoolean()) "Hi!" else "Hello!" - return firstWord + "\n" + - "Guess what it is! > ${platform.name.reversed()}!" + return "$firstWord\nGuess what it is! > ${platform.name.reversed()}!" } } ``` @@ -115,8 +119,8 @@ The common source set can define an interface or an expected declaration. Then e in this case `androidMain` and `iosMain`, has to provide actual platform-specific implementations for the expected declarations from the common source set. -While building the code for a specific target, -the Kotlin compiler will automatically substitute the expected declarations with the actual ones for this target. +While building the code for a specific target, the Kotlin compiler will automatically substitute +the invocation of the expected declarations with the invocation of the actual implementation for this target. 1. When creating a project in Android Studio, you get a template with the `Platform.kt` file in the `commonMain` module: @@ -169,9 +173,9 @@ the Kotlin compiler will automatically substitute the expected declarations with actual fun getPlatform(): Platform = IOSPlatform() ``` -During compilation, the Kotlin compiler automatically substitutes the expected declaration of the `getPlatform()` function -with its correct actual implementations. -The Android app uses the `AndroidPlatform` implementation, while the iOS app uses the `IOSPlatform` implementation. +During compilation, Kotlin automatically substitutes the invocation of the `getPlatform()` expected declaration +with the invocation of its correct actual implementation. +The Android app uses the `AndroidPlatform()` implementation, while the iOS app uses the `IOSPlatform()` implementation. Now you can run the apps to ensure everything works. @@ -216,8 +220,7 @@ such as properties and classes. Let's implement an expected property: fun greet(): String { val firstWord = if (Random.nextBoolean()) "Hi!" else "Hello!" - return firstWord + " [$num]\n" + - "Guess what it is! > ${platform.name.reversed()}!" + return "$firstWord [$num]\nGuess what it is! > ${platform.name.reversed()}!" } ``` diff --git a/docs/topics/multiplatform-mobile/multiplatform-mobile-dependencies.md b/docs/topics/multiplatform-mobile/multiplatform-mobile-dependencies.md index 17ba596dc0f..89db3f80d95 100644 --- a/docs/topics/multiplatform-mobile/multiplatform-mobile-dependencies.md +++ b/docs/topics/multiplatform-mobile/multiplatform-mobile-dependencies.md @@ -80,13 +80,11 @@ multiplatform support, is the most convenient way to work with dates in your sha ```kotlin class Greeting { private val platform: Platform = getPlatform() - + fun greet(): List = buildList { add(if (Random.nextBoolean()) "Hi!" else "Hello!") - add( - "Guess what it is! > ${platform.name.reversed()}!" + - "\nThere are only ${daysUntilNewYear()} days left until New Year! 🎆" - ) + add("Guess what it is! > ${platform.name.reversed()}!") + add("\nThere are only ${daysUntilNewYear()} days left until New Year! 🎆") } } ``` diff --git a/docs/topics/multiplatform-mobile/multiplatform-mobile-update-ui.md b/docs/topics/multiplatform-mobile/multiplatform-mobile-update-ui.md index 0eb324412a8..f30a4333836 100644 --- a/docs/topics/multiplatform-mobile/multiplatform-mobile-update-ui.md +++ b/docs/topics/multiplatform-mobile/multiplatform-mobile-update-ui.md @@ -54,7 +54,8 @@ Make some changes and see how it is reflected in the UI: } ``` - Here the `LazyColumn` composable shows the list of `Text` items. + Here the `LazyColumn` composable shows the list of `Text` items, adds padding around the content and a space between the list items. + 5. Follow Android Studio's suggestions to import the missing dependencies. 6. Update the preview as well, passing a list as an argument: diff --git a/docs/topics/multiplatform-mobile/multiplatform-mobile-upgrade-app.md b/docs/topics/multiplatform-mobile/multiplatform-mobile-upgrade-app.md index 7e3719aeeee..eecad0febd5 100644 --- a/docs/topics/multiplatform-mobile/multiplatform-mobile-upgrade-app.md +++ b/docs/topics/multiplatform-mobile/multiplatform-mobile-upgrade-app.md @@ -186,16 +186,14 @@ data class RocketLaunch ( class Greeting { // ... @Throws(Exception::class) - suspend fun greet(): String { + suspend fun greet(): List = buildList { val rockets: List = httpClient.get("https://api.spacexdata.com/v4/launches").body() val lastSuccessLaunch = rockets.last { it.launchSuccess == true } add(if (Random.nextBoolean()) "Hi!" else "Hello!") - add( - "Guess what it is! > ${platform.name.reversed()}!" + - "\nThere are only ${daysUntilNewYear()} days left until New Year! 🎆" + - "\nThe last successful launch was ${lastSuccessLaunch.launchDateUTC} 🚀" - ) + add("Guess what it is! > ${platform.name.reversed()}!") + add("\nThere are only ${daysUntilNewYear()} days left until New Year! 🎆") + add("\nThe last successful launch was ${lastSuccessLaunch.launchDateUTC} 🚀") } } ```