Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
cl3m committed Nov 18, 2022
1 parent 763888c commit 3db0a9a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 119 deletions.
138 changes: 19 additions & 119 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,156 +9,56 @@ I've started to experiment with Compose Native, you can have a look at https://g

# Multiplatform Compose

A Kotlin library to use Jetpack Compose in Android and iOS. Allow to write UI for both in Kotlin. Still experimental as many compose features are not yet available.
A demo to show usage of Jetpack Compose in Android and iOS. Originally a Jetpack Compose implementation with native view and yoga.

## Table of contents

- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
- [Known issues](#known-issues)
- [Libraries](#libraries)
- [Demos](#demos)
- [Troubleshooting](#troubleshooting)
- [Roadmap](#roadmap)
- [Contributing](#contributing)
- [Sponsors](#sponsors)
- [License](#license)

## Requirements

- Android Studio Canary
- Android Studio
- Xcode
- cocoapods (gem install cocoapods)
- cocoapods-generate (gem install cocoapods-generate)

## Installation
## Libraries

The library is not yet published to Maven Central as it is still experimental.
- kotlinx coroutines
- kotlinx serialization
- ktor
- jetbrain compose (uikit experimental)
- [Precompose](https://github.com/Tlaster/PreCompose) (for navigation)

## Usage
## Demos

The simpliest code is :
Run the app to see a demo of compose on ios.

```kotlin
@Composable
fun Content(resources: Resources) {
Text("Hello world!")
}
```

A better start would be :

```kotlin
@Composable
fun Content(resources: Resources) {
HelloPlatform()
}

@Composable
fun HelloPlatform() {
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally) {
Text("Hello, ${Platform().platform}!")
}
}
```
![Hello Platform Screenshot](https://github.com/cl3m/multiplatform-compose/blob/develop/screenshots/HelloPlatform.png?raw=true)
![Demos](https://github.com/cl3m/multiplatform-compose/blob/compose-jb/screenshots/Demos.png?raw=true)

More advance sample are in the [demos](https://github.com/cl3m/multiplatform-compose/tree/develop/test/src/commonMain/kotlin/com/rouge41/kmm/compose/test/demos) directory of the test library.

#### Image
#### AsyncImage

The image composable allow url loading

```kotlin
Image(url = "https://loremflickr.com/320/240/ocean", modifier = Modifier.preferredSize(200.dp))
```

### iOS Composables

#### HumanAppearance

Allow iOS styling such as font or global tintColor.

```kotlin
HumanAppearance(tintColor: Color, backgroundColor: Color?, style: TextStyle) {
// ...
}
AsyncImage(url = "https://loremflickr.com/320/240/ocean", modifier = Modifier.preferredSize(200.dp))
```

#### SafeArea

Add safe area insets to the view, works in root, TabView and NavigationView

```kotlin
SafeArea {
// ...
}
```

![Safe Area Screenshot](https://github.com/cl3m/multiplatform-compose/blob/develop/screenshots/Layout.png?raw=true)
*Layout without the safe area, with the safe area and on android*

#### TabView

UITabBarController for Compose

```kotlin
TabView {
Tab(title = "First", image = UIImage.systemImageNamed("a.circle.fill")) {
// ...
}
Tab(title = "Second", image = UIImage.systemImageNamed("a.circle.fill")) {
// ...
}
}
```

#### NavigationView
SafeArea.current context with PaddingValues.

UINavigationController for Compose, renamed to NavHost but as additional parameter title, leadingButton and trailingButton in composable

```kotlin
val navController = rememberNavController()
NavHost(navController = navController, startDestination = "first") {
composable("first", title = "First", trailingButton = Button(onClick = {}) { Text ("Edit") }) {
SafeArea {
Button(onClick = { navController.navigate("second") }) {
// ...
}
}
}
composable("second", title = "Second") {
SafeArea {
// ...
}
}
}
```

## Known issues

- Jetpack Compose require Android Studio Canary and an alpha build of Gradle. There is some workaround in _build.gradle.kts_ to make it work (testApi).
- Jetpack Compose is not supported in Kotlin Multiplatform Mobile library ([KT-38694](https://youtrack.jetbrains.com/issue/KT-38694)). Unfortunatly, the workaround was messing with actual/expect function and prevent the use of expect function with default value. The library now use @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") to workaround this problem. If you use an expect function with default value and without the suppress, you will get an error function not found or _java.lang.IllegalStateException: 2. expected value parameter count to be higher_.
- Jetpack Compose dependencies can not be used in commonMain because they have a dependency on kotlinx-coroutines-android.
- Android Studio does not autocomplete cocoapods imported library in iosMain. Thus it is in iosx64Main and symlinked to iosArm64Main.
- Images needs currently to be included in the android and ios resources separately.
- Navigation is currently not shared in the library
- Latest Android Studio Canary shows many undefined error but everthing compile fine. It was not the case before.

## Troubleshooting

### cinteropYogaKitIosArm64 FAILED YogaKit module not found

You did not read the requirements. Install cocoapods-generate "gem install cocoapods-generate", invalid cache and restart Android Studio

## Roadmap
### e: java.lang.IllegalStateException: No file for ***

- More Jetpack Compose feature support
- Better images/resources support
- UI Test with Github Actions
- Performance improvement/optimisation
- Use Compose compiler and runtime on iOS
Compose function and context has to be internal and not exposed to iOS module.

## Sponsors

Expand Down
Binary file modified screenshots/Demos.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3db0a9a

Please sign in to comment.