Skip to content

Commit 682c0c7

Browse files
committed
Migrate theme-contract to KMP
1 parent b56a5b7 commit 682c0c7

64 files changed

Lines changed: 143 additions & 34 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/src/main/java/com/orange/ouds/app/ui/ChangeThemeSettingsDialog.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fun ChangeThemeSettingsDialog(themeState: ThemeState, onThemeSettingsChange: (Ou
5151

5252
@Composable
5353
private fun ChangeThemeSettingsDialogContent(themeState: ThemeState, onThemeSettingsChange: (OudsThemeSettings) -> Unit) {
54-
var themeSettings by rememberSaveable { mutableStateOf(themeState.settings) }
54+
var themeSettings by rememberSaveable(stateSaver = OudsThemeSettings.Saver) { mutableStateOf(themeState.settings) }
5555
DialogContent(
5656
title = stringResource(R.string.app_themeSettingsDialog_label)
5757
) {

app/src/main/java/com/orange/ouds/app/ui/ThemeState.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,18 @@ class ThemeState(
6464
save = { state ->
6565
with(state) {
6666
listOf(
67-
settings,
67+
with(OudsThemeSettings.Saver) { save(settings) },
6868
themeNames,
6969
currentThemeName,
7070
areDownloadableOrangeFontFamilyPreloaded
7171
)
7272
}
7373
},
74-
restore = { list ->
74+
restore = { list: List<Any?> ->
75+
val settings = list[0]?.let { OudsThemeSettings.Saver.restore(it) }
7576
@Suppress("UNCHECKED_CAST")
7677
ThemeState(
77-
list[0] as OudsThemeSettings,
78+
settings as OudsThemeSettings,
7879
list[1] as List<String>,
7980
list[2] as String,
8081
list[3] as Boolean
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../../../../../../../../theme-contract/src/main/java/com/orange/ouds/theme/OudsVersion.kt
1+
../../../../../../../../theme-contract/src/commonMain/kotlin/com/orange/ouds/theme/OudsVersion.kt

core/src/main/java/com/orange/ouds/core/theme/OudsBorders.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import androidx.compose.ui.unit.isSpecified
3737
import com.orange.ouds.foundation.InternalOudsApi
3838
import com.orange.ouds.theme.tokens.OudsBorderKeyToken
3939
import com.orange.ouds.theme.tokens.semantic.OudsBorderSemanticTokens
40-
import java.util.Locale
4140

4241
/**
4342
* Holds all the border-related properties defined in the OUDS theme.
@@ -217,7 +216,7 @@ enum class OudsBorderStyle {
217216
*/
218217
fun fromString(string: String): OudsBorderStyle {
219218
return try {
220-
OudsBorderStyle.valueOf(string.lowercase().replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() })
219+
OudsBorderStyle.valueOf(string.lowercase().replaceFirstChar { it.uppercase() })
221220
} catch (exception: IllegalArgumentException) {
222221
// If the provided border style value is unknown, return the default border style
223222
None

theme-contract/build.gradle.kts

Lines changed: 105 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,119 @@
1111
*/
1212

1313
plugins {
14-
id("dokka")
15-
id("library")
14+
//id("dokka")
1615
alias(libs.plugins.compose.compiler)
17-
id(libs.plugins.kotlin.parcelize.get().pluginId) // https://github.com/gradle/gradle/issues/20084#issuecomment-1060822638
16+
alias(libs.plugins.compose.multiplatform)
17+
id(libs.plugins.kotlin.multiplatform.get().pluginId)
18+
id(libs.plugins.android.kotlin.multiplatform.library.get().pluginId)
1819
}
1920

2021
// Temporary workaround for https://issuetracker.google.com/issues/476936389
21-
val dokkaKotlinAdapter = objects.newInstance(org.jetbrains.dokka.gradle.adapters.KotlinAdapter::class)
22-
dokkaKotlinAdapter.apply(project)
22+
//val dokkaKotlinAdapter = objects.newInstance(org.jetbrains.dokka.gradle.adapters.KotlinAdapter::class)
23+
//dokkaKotlinAdapter.apply(project)
2324

24-
android {
25-
namespace = "com.orange.ouds.theme"
25+
kotlin {
26+
jvmToolchain(17)
2627

27-
buildFeatures {
28-
compose = true
28+
compilerOptions {
29+
freeCompilerArgs.addAll(
30+
"-opt-in=com.orange.ouds.foundation.RestrictedOudsApi",
31+
"-opt-in=com.orange.ouds.foundation.ExperimentalOudsApi",
32+
"-opt-in=com.orange.ouds.foundation.InternalOudsApi"
33+
)
2934
}
3035

31-
kotlin {
32-
compilerOptions {
33-
freeCompilerArgs.addAll(
34-
"-opt-in=com.orange.ouds.foundation.RestrictedOudsApi",
35-
"-opt-in=com.orange.ouds.foundation.ExperimentalOudsApi",
36-
"-opt-in=com.orange.ouds.foundation.InternalOudsApi"
37-
)
36+
// Target declarations - add or remove as needed below. These define
37+
// which platforms this KMP module supports.
38+
// See: https://kotlinlang.org/docs/multiplatform-discover-project.html#targets
39+
android {
40+
namespace = "com.orange.ouds.theme"
41+
compileSdk = libs.versions.androidCompileSdk.get().toInt()
42+
minSdk = libs.versions.androidMinSdk.get().toInt()
43+
44+
withHostTestBuilder {
45+
}
46+
47+
withDeviceTestBuilder {
48+
sourceSetTreeName = "test"
49+
}.configure {
50+
instrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
3851
}
3952
}
40-
}
4153

42-
dependencies {
43-
implementation(project(":foundation"))
44-
implementation(project(":global-raw-tokens"))
45-
api(platform(libs.androidx.compose.bom))
46-
api(libs.androidx.compose.material3)
47-
}
54+
// For iOS targets, this is also where you should
55+
// configure native binary output. For more information, see:
56+
// https://kotlinlang.org/docs/multiplatform-build-native-binaries.html#build-xcframeworks
57+
58+
// A step-by-step guide on how to include this library in an XCode
59+
// project can be found here:
60+
// https://developer.android.com/kotlin/multiplatform/migrate
61+
val xcfName = "oudsThemeContract"
62+
63+
// iosX64 {
64+
// binaries.framework {
65+
// baseName = xcfName
66+
// }
67+
// }
68+
69+
iosArm64 {
70+
binaries.framework {
71+
baseName = xcfName
72+
}
73+
}
74+
75+
iosSimulatorArm64 {
76+
binaries.framework {
77+
baseName = xcfName
78+
}
79+
}
80+
81+
// Source set declarations.
82+
// Declaring a target automatically creates a source set with the same name. By default, the
83+
// Kotlin Gradle Plugin creates additional source sets that depend on each other, since it is
84+
// common to share sources between related targets.
85+
// See: https://kotlinlang.org/docs/multiplatform-hierarchy.html
86+
sourceSets {
87+
commonMain {
88+
dependencies {
89+
implementation(libs.kotlin.stdlib)
90+
// Add KMP dependencies here
91+
implementation(project(":foundation"))
92+
implementation(project(":global-raw-tokens"))
93+
api(libs.compose.material3)
94+
}
95+
}
96+
97+
commonTest {
98+
dependencies {
99+
implementation(libs.kotlin.test)
100+
}
101+
}
102+
103+
androidMain {
104+
dependencies {
105+
// Add Android-specific dependencies here. Note that this source set depends on
106+
// commonMain by default and will correctly pull the Android artifacts of any KMP
107+
// dependencies declared in commonMain.
108+
}
109+
}
110+
111+
getByName("androidDeviceTest") {
112+
dependencies {
113+
implementation(libs.androidx.junit)
114+
implementation(libs.androidx.runner)
115+
implementation(libs.core)
116+
}
117+
}
118+
119+
iosMain {
120+
dependencies {
121+
// Add iOS-specific dependencies here. This a source set created by Kotlin Gradle
122+
// Plugin (KGP) that each specific iOS target (e.g., iosX64) depends on as
123+
// part of KMP’s default source set hierarchy. Note that this source set depends
124+
// on common by default and will correctly pull the iOS artifacts of any
125+
// KMP dependencies declared in commonMain.
126+
}
127+
}
128+
}
129+
}
File renamed without changes.

theme-contract/src/main/java/com/orange/ouds/theme/OudsDrawableResources.kt renamed to theme-contract/src/commonMain/kotlin/com/orange/ouds/theme/OudsDrawableResources.kt

File renamed without changes.

theme-contract/src/main/java/com/orange/ouds/theme/OudsThemeContract.kt renamed to theme-contract/src/commonMain/kotlin/com/orange/ouds/theme/OudsThemeContract.kt

File renamed without changes.

theme-contract/src/main/java/com/orange/ouds/theme/OudsThemeSettings.kt renamed to theme-contract/src/commonMain/kotlin/com/orange/ouds/theme/OudsThemeSettings.kt

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212

1313
package com.orange.ouds.theme
1414

15-
import android.os.Parcelable
16-
import kotlinx.parcelize.Parcelize
15+
import androidx.compose.runtime.saveable.listSaver
16+
import com.orange.ouds.theme.OudsThemeSettings.Companion.Saver
17+
import kotlin.jvm.JvmOverloads
1718

1819
/**
1920
* Theme settings.
@@ -45,10 +46,36 @@ import kotlinx.parcelize.Parcelize
4546
*
4647
* @constructor Creates an instance of [OudsThemeSettings].
4748
*/
48-
@Parcelize
4949
data class OudsThemeSettings @JvmOverloads constructor(
5050
val roundedCornerButtons: Boolean? = null,
5151
val roundedCornerTextInputs: Boolean? = null,
5252
val roundedCornerAlertMessages: Boolean? = null,
5353
val roundedCornerProgressIndicators: Boolean? = null
54-
) : Parcelable
54+
) {
55+
companion object {
56+
57+
/**
58+
* [Saver] implementation for [OudsThemeSettings] to support saving/restoring state in Compose.
59+
*/
60+
val Saver = listSaver(
61+
save = { settings ->
62+
with(settings) {
63+
listOf(
64+
roundedCornerButtons,
65+
roundedCornerTextInputs,
66+
roundedCornerAlertMessages,
67+
roundedCornerProgressIndicators
68+
)
69+
}
70+
},
71+
restore = { list ->
72+
OudsThemeSettings(
73+
roundedCornerButtons = list[0] as Boolean,
74+
roundedCornerTextInputs = list[1] as Boolean,
75+
roundedCornerAlertMessages = list[2] as Boolean,
76+
roundedCornerProgressIndicators = list[3] as Boolean
77+
)
78+
}
79+
)
80+
}
81+
}

theme-contract/src/main/java/com/orange/ouds/theme/OudsVersion.kt renamed to theme-contract/src/commonMain/kotlin/com/orange/ouds/theme/OudsVersion.kt

File renamed without changes.

0 commit comments

Comments
 (0)