Skip to content

Commit

Permalink
update: review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
danil-pavlov committed Sep 15, 2023
1 parent 1fc00ad commit b964b79
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<p>This is the second part of the <strong>Getting started with Kotlin Multiplatform for mobile</strong> tutorial. Before proceeding, make sure you've completed the previous step.</p>
<p><img src="icon-1-done.svg" width="20" alt="First step"/> <a href="multiplatform-mobile-setup.md">Set up an environment</a><br/>
<img src="icon-2.svg" width="20" alt="Second step"/> <strong>Create your first cross-platform app</strong><br/>
<img src="icon-3-todo.svg" width="20" alt="Third step"/> Update UI<br/>
<img src="icon-3-todo.svg" width="20" alt="Third step"/> Update the user interface<br/>
<img src="icon-4-todo.svg" width="20" alt="Fourth step"/> Add dependencies<br/>
<img src="icon-5-todo.svg" width="20" alt="Fifth step"/> Share more logic<br/>
<img src="icon-6-todo.svg" width="20" alt="Sixth step"/> Wrap up your project</p>
Expand Down Expand Up @@ -73,7 +73,7 @@ When it is built into an iOS framework, common Kotlin gets treated as Kotlin/Nat

![Common Kotlin, Kotlin/JVM, and Kotlin/Native](modules-structure.png)

### Writing common declarations
### Write common declarations

The common source set contains shared code that can be used across multiple target platforms.
It's designed to contain code that is platform-independent. If you try to use platform-specific APIs in the common source set,
Expand Down Expand Up @@ -113,7 +113,7 @@ IDE will show a warning:
Writing the code only in common Kotlin has obvious limitations because it can't use any platform specifics.
Using interfaces and the [expect/actual](multiplatform-connect-to-apis.md) mechanism solves this.

### Adding platform-specific implementations
### Add platform-specific implementations

The common source set can define an interface or an expected declaration. Then each platform source sets,
in this case `androidMain` and `iosMain`, has to provide actual platform-specific implementations for the expected
Expand Down Expand Up @@ -142,7 +142,9 @@ and generates a single declaration with actual implementations.
override val name: String =
"Android ${Build.VERSION.SDK_INT}"
}

```

```kotlin
// Platform.kt in the iosMain module:
import platform.UIKit.UIDevice

Expand All @@ -151,7 +153,6 @@ and generates a single declaration with actual implementations.
UIDevice.currentDevice.systemName() + " " + UIDevice.currentDevice.systemVersion
}
```
{validate="false"}

* The `name` property implementation from `AndroidPlatform` uses the Android platform code, namely the `android.os.Build`
dependency. This code is written in Kotlin/JVM. If you try to access `java.util.Random` here, this code will compile.
Expand All @@ -165,10 +166,14 @@ and generates a single declaration with actual implementations.
```kotlin
// Platform.kt in commonMain module:
expect fun getPlatform(): Platform

```

```kotlin
// Platform.kt in androidMain module:
actual fun getPlatform(): Platform = AndroidPlatform()

```

```kotlin
// Platform.kt in iosMain module:
actual fun getPlatform(): Platform = IOSPlatform()
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<p>This is the fourth part of the <strong>Getting started with Kotlin Multiplatform for mobile</strong> tutorial. Before proceeding, make sure you've completed previous steps.</p>
<p><img src="icon-1-done.svg" width="20" alt="First step"/> <a href="multiplatform-mobile-setup.md">Set up an environment</a><br/>
<img src="icon-2-done.svg" width="20" alt="Second step"/> <a href="multiplatform-mobile-create-first-app.md">Create your first cross-platform app</a><br/>
<img src="icon-3-done.svg" width="20" alt="Third step"/> <a href="multiplatform-mobile-update-ui.md">Update UI</a><br/>
<img src="icon-3-done.svg" width="20" alt="Third step"/> <a href="multiplatform-mobile-update-ui.md">Update the user interface</a><br/>
<img src="icon-4.svg" width="20" alt="Fourth step"/> <strong>Add dependencies</strong><br/>
<img src="icon-5-todo.svg" width="20" alt="Fifth step"/> Share more logic<br/>
<img src="icon-6-todo.svg" width="20" alt="Sixth step"/> Wrap up your project</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Get to know Kotlin Multiplatform and create a mobile app that works on both Andr

![Second step](icon-2.svg){width=25}{type="joined"} [Create your first app that works both on Android and iOS with the IDE](multiplatform-mobile-create-first-app.md)

![Third step](icon-3.svg){width=25}{type="joined"} [Update UI](multiplatform-mobile-update-ui.md)
![Third step](icon-3.svg){width=25}{type="joined"} [Update the user interface](multiplatform-mobile-update-ui.md)

![Fourth step](icon-4.svg){width=25}{type="joined"} [Add dependencies to your project](multiplatform-mobile-dependencies.md)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<p>This is the first part of the <strong>Getting started with Kotlin Multiplatform for mobile</strong> tutorial:</p>
<p><img src="icon-1.svg" width="20" alt="First step"/> <strong>Set up an environment</strong><br/>
<img src="icon-2-todo.svg" width="20" alt="Second step"/> Create your first cross-platform app<br/>
<img src="icon-3-todo.svg" width="20" alt="Third step"/> Update UI<br/>
<img src="icon-3-todo.svg" width="20" alt="Third step"/> Update the user interface<br/>
<img src="icon-4-todo.svg" width="20" alt="Fourth step"/> Add dependencies<br/>
<img src="icon-5-todo.svg" width="20" alt="Fifth step"/> Share more logic<br/>
<img src="icon-6-todo.svg" width="20" alt="Sixth step"/> Wrap up your project</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[//]: # (title: Update UI)
[//]: # (title: Update the user interface)

<microformat>
<p>This is the third part of the <strong>Getting started with Kotlin Multiplatform for mobile</strong> tutorial. Before proceeding, make sure you've completed previous steps.</p>
<p><img src="icon-1-done.svg" width="20" alt="First step"/> <a href="multiplatform-mobile-setup.md">Set up an environment</a><br/>
<img src="icon-2-done.svg" width="20" alt="Second step"/> <a href="multiplatform-mobile-create-first-app.md">Create your first cross-platform app</a><br/>
<img src="icon-3.svg" width="20" alt="Third step"/> <strong>Update UI</strong><br/>
<img src="icon-3.svg" width="20" alt="Third step"/> <strong>Update the user interface</strong><br/>
<img src="icon-4-todo.svg" width="20" alt="Fourth step"/> Add dependencies<br/>
<img src="icon-5-todo.svg" width="20" alt="Fifth step"/> Share more logic<br/>
<img src="icon-6-todo.svg" width="20" alt="Sixth step"/> Wrap up your project</p>
Expand All @@ -15,7 +15,7 @@ for the Android part of your project and [SwiftUI](https://developer.apple.com/x
These are both declarative UI frameworks, and you'll see similarities in the UI implementations. In both cases,
you store the data in the `phrases` variable and later iterate over it to produce a list of `Text` items.

### The Android module
### Update the Android module

The `androidApp` module contains an Android application, defines its main activity and the UI views, and uses the
`shared` module as a regular Android library. The UI of the application uses the Jetpack Compose framework.
Expand Down Expand Up @@ -73,7 +73,7 @@ Make some changes and see how it is reflected in the UI:

![Updated UI of Android multiplatform app](first-multiplatform-project-on-android-2.png){width=300}

### The iOS module
### Work with the iOS module in Xcode

`iosApp` is an Xcode project that builds into an iOS application. It depends on and uses the `shared` module as an iOS
framework. The UI of the app is written in Swift.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[//]: # (title: Share the logic)
[//]: # (title: Share more logic between iOS and Android)

<microformat>
<p>This is the fifth part of the <strong>Getting started with Kotlin Multiplatform for mobile</strong> tutorial. Before proceeding, make sure you've completed previous steps.</p>
<p><img src="icon-1-done.svg" width="20" alt="First step"/> <a href="multiplatform-mobile-setup.md">Set up an environment</a><br/>
<img src="icon-2-done.svg" width="20" alt="Second step"/> <a href="multiplatform-mobile-create-first-app.md">Create your first cross-platform app</a><br/>
<img src="icon-3-done.svg" width="20" alt="Third step"/> <a href="multiplatform-mobile-update-ui.md">Update UI</a><br/>
<img src="icon-3-done.svg" width="20" alt="Third step"/> <a href="multiplatform-mobile-update-ui.md">Update the user interface</a><br/>
<img src="icon-4-done.svg" width="20" alt="Fourth step"/> <a href="multiplatform-mobile-dependencies.md">Add dependencies</a><br/>
<img src="icon-5.svg" width="20" alt="Fifth step"/> <strong>Share more logic</strong><br/>
<img src="icon-6-todo.svg" width="20" alt="Sixth step"/> Wrap up your project</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<p>This is final part of the <strong>Getting started with Kotlin Multiplatform for mobile</strong> tutorial. Before proceeding, make sure you've completed previous steps.</p>
<p><img src="icon-1-done.svg" width="20" alt="First step"/> <a href="multiplatform-mobile-setup.md">Set up an environment</a><br/>
<img src="icon-2-done.svg" width="20" alt="Second step"/> <a href="multiplatform-mobile-create-first-app.md">Create your first cross-platform app</a><br/>
<img src="icon-3-done.svg" width="20" alt="Third step"/> <a href="multiplatform-mobile-update-ui.md">Update UI</a><br/>
<img src="icon-3-done.svg" width="20" alt="Third step"/> <a href="multiplatform-mobile-update-ui.md">Update the user interface</a><br/>
<img src="icon-4-done.svg" width="20" alt="Fourth step"/> <a href="multiplatform-mobile-dependencies.md">Add dependencies</a><br/>
<img src="icon-5-done.svg" width="20" alt="Fifth step"/> <a href="multiplatform-mobile-upgrade-app.md">Share more logic</a><br/>
<img src="icon-6.svg" width="20" alt="Sixth step"/> <strong>Wrap up your project</strong></p>
Expand Down

0 comments on commit b964b79

Please sign in to comment.