Skip to content

Commit a78c8b5

Browse files
[issue-59] - update doc kmp
1 parent b64b79a commit a78c8b5

File tree

3 files changed

+56
-74
lines changed

3 files changed

+56
-74
lines changed

docs/how-to-use/compose.md

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,50 @@
1-
# Jetpack Compose
1+
# Jetpack Compose / CMP
22

3-
- Create your ComponentPropertyClass with properties that you need. In this example, I used checkbox component:
3+
- Create your `ComponentPropertyClass` with all the properties your component needs.
4+
In this example, we’re using a **checkbox component**.
45

56
!!! warning "Immutable and Stable annotations"
6-
Here we have some points to consider To avoid unnecessary recompositions at your component. We recommend use the `@Immutable` and `@Stable` annotations in your properties.
7+
To avoid unnecessary recompositions in your component,
8+
we recommend using the `@Immutable` and `@Stable` annotations in your properties.
9+
10+
---
11+
12+
### 1. Enable Kotlin Serialization
13+
In your **root build.gradle.kts**, add the Kotlin serialization plugin (version **2.2.21** or higher):
14+
15+
```gradle
16+
id("org.jetbrains.kotlin.plugin.serialization") version "2.2.21"
17+
```
18+
19+
In your **module build.gradle.kts** add
20+
21+
```gradle
22+
implementation(libs.kotlinx.serialization.json)
23+
```
24+
25+
2. Create your owner object that has the same field in your json like: (This class must match the structure of the JSON that will be parsed:)
726

827
```kotlin
9-
@JsonIgnoreProperties(ignoreUnknown = true)
10-
@Immutable
1128
@Stable
29+
@Immutable
30+
@Serializable
1231
data class CheckBoxProperties(
13-
@JsonProperty("text") val text: String? = null,
32+
@SerialName("text") val text: String? = null,
1433
... define your properties here
1534
)
1635
```
1736

18-
- Add your Component json object in `Dymanic.json`:
37+
!!! tip "Note"
38+
39+
You can use your component object in dynamic.json inside the sample project [app-sample-android](https://github.com/CodandoTV/CraftD/tree/issue-59/convert-to-kmp/android_kmp/app-sample-android) or [KMP-sample](https://github.com/CodandoTV/CraftD/tree/issue-59/convert-to-kmp/android_kmp/KMP-Sample):
1940

2041
```json
2142
{
22-
"key": "CraftDCheckBox",
23-
"value": {
24-
... define your properties here
25-
}
26-
}
43+
"key": "CraftDCheckBox",
44+
"value": {
45+
... define your properties here
46+
}
47+
}
2748
```
2849

2950
- Create your Component
@@ -53,7 +74,7 @@ class CraftDCheckBoxBuilder(
5374

5475
!!! tip "Note"
5576

56-
This Builder must extend CraftBuilder Class and override craft method.
77+
This Builder must extend CraftBuilder Class and override craft method.
5778

5879
```kotlin
5980
class CraftDCheckBoxBuilder(
@@ -80,7 +101,7 @@ fun InitialScreen(
80101
val properties by vm.properties.collectAsStateWithLifecycle()
81102
val dynamicBuilder = remember {
82103
CraftDBuilderManager().add(
83-
CraftDCheckBoxBuilder()
104+
CraftDCheckBoxBuilder()
84105
)
85106
}
86107
LaunchedEffect(Unit) {

docs/index.md

Lines changed: 14 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4,66 +4,28 @@
44

55
### 🔗 Compatibility
66

7-
| Tech | Support |
8-
|----------------------------|------------------|
9-
| View System - Android | ✅ Supported |
10-
| Jetpack Compose - Android | ✅ Supported |
11-
| Widgets Flutter | ✅ Supported |
12-
| SwiftUI - iOS | ✅ Supported |
13-
| Compose Multiplatform | ⚒️ In Progress |
7+
| Tech | Support |
8+
|----------------------------|-----------------|
9+
| View System - Android | ✅ Supported |
10+
| Jetpack Compose - Android | ✅ Supported |
11+
| Widgets Flutter | ✅ Supported |
12+
| SwiftUI - iOS | ✅ Supported |
13+
| Compose Multiplatform | ✅ Supported |
1414

1515
### Components that already exist in the library
1616

17-
| Component | Android Compose | Android View | Flutter | SwiftUI |
18-
|-------------------|-----------------|--------------|---------|---------|
19-
| Button | X | X | X | - |
20-
| Text | X | X | X | X |
21-
| Checkbox | X | - | - | - |
22-
23-
### How to create a custom component?
24-
25-
- Create a data structure to represent your component:
26-
27-
```kotlin
28-
@JsonIgnoreProperties(ignoreUnknown = true)
29-
@Immutable
30-
@Stable
31-
data class CheckBoxProperties(
32-
@JsonProperty("text") val text: String? = null,
33-
... rest of your properties
34-
)
35-
```
36-
37-
- Add your Component json object in _Dymanic.json_
38-
39-
```json
40-
{
41-
"key": "CraftDCheckBox",
42-
"value": {
43-
... rest of your properties
44-
}
45-
}
46-
```
47-
48-
- Create your component:
49-
50-
```kotlin
51-
@Composable
52-
fun CraftDCheckBox(
53-
checkboxProperties: CheckBoxProperties,
54-
modifier: Modifier = Modifier,
55-
onChecked: (Boolean) -> Unit
56-
) {
57-
... Rest of your code
58-
}
59-
```
17+
| Component | Jetpack Compose / CMP | Android View | Flutter | SwiftUI |
18+
|-------------------|-----------------------|--------------|---------|---------|
19+
| Button | X | X | X | - |
20+
| Text | X | X | X | X |
21+
| Checkbox | X | - | - | - |
6022

6123
### Screen recordings
6224

6325
<div class="grid cards" markdown>
6426
<figure markdown="span">
6527
![Compose Android](./assets/video/compose-android.gif){ width="300" }
66-
<figcaption>Compose Android</figcaption>
28+
<figcaption>JetPack Compose / CMP</figcaption>
6729
</figure>
6830

6931
<figure markdown="span">
@@ -86,5 +48,4 @@ fun CraftDCheckBox(
8648
!!! info "Credits"
8749

8850
A Server Driven UI library for Android.
89-
Inspired by the [_DynamicView_](https://github.com/rviannaoliveira/DynamicView).
90-
51+
Inspired by the [_DynamicView_](https://github.com/rviannaoliveira/DynamicView).

docs/setup.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Setup
22

3-
## Android
3+
## Android / CMP
44

55
- Add in your settings.gradle mavenCetral:
66

@@ -29,7 +29,7 @@ dependencyResolutionManagement {
2929
```
3030

3131
!!! example "Core"
32-
Core - Is meant to be used for you to customize even the craftD mechanism
32+
Core - Is meant to be used for you to customize even the craftD mechanism
3333

3434
```kotlin
3535
implementation("io.github.codandotv:craftd-core:${last_version}")
@@ -40,7 +40,7 @@ dependencyResolutionManagement {
4040
- Add your pod ‘CraftDSwiftUI’
4141

4242
!!! warning "In Progress"
43-
This section is in progress...
43+
This section is in progress...
4444

4545
## Flutter
4646

@@ -53,7 +53,7 @@ flutter pub add craftd_widget
5353
This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get):
5454

5555
!!! example "pubspec.yml"
56-
```yaml
57-
dependencies:
58-
craftd_widget: $last_version
59-
```
56+
```yaml
57+
dependencies:
58+
craftd_widget: $last_version
59+
```

0 commit comments

Comments
 (0)