Skip to content

Commit d5b7c52

Browse files
authored
Feat: [:core:designsystem] - Migrated to KMP with CMP Library (#1774)
1 parent 278da28 commit d5b7c52

28 files changed

+83
-149
lines changed

core/designsystem/build.gradle.kts

+9
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,19 @@ kotlin {
7474
implementation(compose.uiUtil)
7575
implementation(compose.components.resources)
7676
implementation(compose.components.uiToolingPreview)
77+
implementation(libs.back.handler)
78+
implementation(libs.moko.permission)
79+
implementation(libs.moko.permission.compose)
7780
}
7881
}
7982
}
8083

84+
compose.resources {
85+
publicResClass = true
86+
packageOfResClass = "org.mifospay.core.designsystem.resources"
87+
generateResClass = always
88+
}
89+
8190
dependencies {
8291
lintPublish(projects.lint)
8392
}

core/designsystem/src/main/kotlin/org/mifospay/core/designsystem/component/PermissionBox.kt core/designsystem/src/androidMain/kotlin/org/mifospay/core/designsystem/component/PermissionBox.kt

+5-4
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@ import androidx.core.content.ContextCompat
3030
import androidx.lifecycle.Lifecycle
3131
import androidx.lifecycle.LifecycleEventObserver
3232

33+
// TODO:: Support for compose multiplatform
3334
@Suppress("LongMethod", "CyclomaticComplexMethod")
3435
@Composable
3536
fun PermissionBox(
37+
title: String,
38+
confirmButtonText: String,
39+
dismissButtonText: String,
3640
requiredPermissions: List<String>,
37-
title: Int,
38-
confirmButtonText: Int,
39-
dismissButtonText: Int,
4041
modifier: Modifier = Modifier,
41-
description: Int? = null,
42+
description: String? = null,
4243
onGranted: @Composable (() -> Unit)? = null,
4344
) {
4445
val context = LocalContext.current

core/designsystem/src/main/kotlin/org/mifospay/core/designsystem/component/AlertDialog.kt core/designsystem/src/commonMain/kotlin/org/mifospay/core/designsystem/component/AlertDialog.kt

+9-10
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,26 @@ import androidx.compose.material3.Text
1616
import androidx.compose.material3.TextButton
1717
import androidx.compose.runtime.Composable
1818
import androidx.compose.ui.Modifier
19-
import androidx.compose.ui.res.stringResource
2019

2120
@Composable
2221
fun MifosDialogBox(
22+
title: String,
2323
showDialogState: Boolean,
24-
onDismiss: () -> Unit,
25-
title: Int,
26-
confirmButtonText: Int,
24+
confirmButtonText: String,
25+
dismissButtonText: String,
2726
onConfirm: () -> Unit,
28-
dismissButtonText: Int,
27+
onDismiss: () -> Unit,
2928
modifier: Modifier = Modifier,
30-
message: Int? = null,
29+
message: String? = null,
3130
) {
3231
if (showDialogState) {
3332
AlertDialog(
3433
modifier = modifier,
3534
onDismissRequest = onDismiss,
36-
title = { Text(text = stringResource(id = title)) },
35+
title = { Text(text = title) },
3736
text = {
3837
if (message != null) {
39-
Text(text = stringResource(id = message))
38+
Text(text = message)
4039
}
4140
},
4241
confirmButton = {
@@ -45,12 +44,12 @@ fun MifosDialogBox(
4544
onConfirm()
4645
},
4746
) {
48-
Text(stringResource(id = confirmButtonText))
47+
Text(text = confirmButtonText)
4948
}
5049
},
5150
dismissButton = {
5251
TextButton(onClick = onDismiss) {
53-
Text(stringResource(id = dismissButtonText))
52+
Text(text = dismissButtonText)
5453
}
5554
},
5655
)

core/designsystem/src/main/kotlin/org/mifospay/core/designsystem/component/Background.kt core/designsystem/src/commonMain/kotlin/org/mifospay/core/designsystem/component/Background.kt

+4-54
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,22 @@
99
*/
1010
package org.mifospay.core.designsystem.component
1111

12-
import android.content.res.Configuration
1312
import androidx.compose.foundation.layout.Box
1413
import androidx.compose.foundation.layout.fillMaxSize
1514
import androidx.compose.foundation.layout.size
1615
import androidx.compose.material3.LocalAbsoluteTonalElevation
1716
import androidx.compose.material3.Surface
1817
import androidx.compose.runtime.Composable
1918
import androidx.compose.runtime.CompositionLocalProvider
20-
import androidx.compose.runtime.getValue
21-
import androidx.compose.runtime.rememberUpdatedState
2219
import androidx.compose.ui.Modifier
23-
import androidx.compose.ui.draw.drawWithCache
24-
import androidx.compose.ui.geometry.Offset
25-
import androidx.compose.ui.graphics.Brush
2620
import androidx.compose.ui.graphics.Color
27-
import androidx.compose.ui.tooling.preview.Preview
2821
import androidx.compose.ui.unit.Dp
2922
import androidx.compose.ui.unit.dp
23+
import org.jetbrains.compose.ui.tooling.preview.Preview
3024
import org.mifospay.core.designsystem.theme.GradientColors
3125
import org.mifospay.core.designsystem.theme.LocalBackgroundTheme
3226
import org.mifospay.core.designsystem.theme.LocalGradientColors
3327
import org.mifospay.core.designsystem.theme.MifosTheme
34-
import kotlin.math.tan
3528

3629
/**
3730
* The main background for the app.
@@ -66,14 +59,13 @@ fun MifosBackground(
6659
* @param gradientColors The gradient colors to be rendered.
6760
* @param content The background content.
6861
*/
62+
// TODO:: Fix the gradient background based on NewUI
6963
@Composable
7064
fun MifosGradientBackground(
7165
modifier: Modifier = Modifier,
7266
gradientColors: GradientColors = LocalGradientColors.current,
7367
content: @Composable () -> Unit,
7468
) {
75-
val currentTopColor by rememberUpdatedState(gradientColors.top)
76-
val currentBottomColor by rememberUpdatedState(gradientColors.bottom)
7769
Surface(
7870
color = if (gradientColors.container == Color.Unspecified) {
7971
Color.Transparent
@@ -84,48 +76,7 @@ fun MifosGradientBackground(
8476
) {
8577
Box(
8678
Modifier
87-
.fillMaxSize()
88-
.drawWithCache {
89-
// Compute the start and end coordinates such that the gradients are angled 11.06
90-
// degrees off the vertical axis
91-
val offset = size.height * tan(
92-
Math
93-
.toRadians(11.06)
94-
.toFloat(),
95-
)
96-
97-
val start = Offset(size.width / 2 + offset / 2, 0f)
98-
val end = Offset(size.width / 2 - offset / 2, size.height)
99-
100-
// Create the top gradient that fades out after the halfway point vertically
101-
val topGradient = Brush.linearGradient(
102-
0f to if (currentTopColor == Color.Unspecified) {
103-
Color.Transparent
104-
} else {
105-
currentTopColor
106-
},
107-
0.724f to Color.Transparent,
108-
start = start,
109-
end = end,
110-
)
111-
// Create the bottom gradient that fades in before the halfway point vertically
112-
val bottomGradient = Brush.linearGradient(
113-
0.2552f to Color.Transparent,
114-
1f to if (currentBottomColor == Color.Unspecified) {
115-
Color.Transparent
116-
} else {
117-
currentBottomColor
118-
},
119-
start = start,
120-
end = end,
121-
)
122-
123-
onDrawBehind {
124-
// There is overlap here, so order is important
125-
drawRect(topGradient)
126-
drawRect(bottomGradient)
127-
}
128-
},
79+
.fillMaxSize(),
12980
) {
13081
content()
13182
}
@@ -136,8 +87,7 @@ fun MifosGradientBackground(
13687
* Multipreview annotation that represents light and dark themes. Add this annotation to a
13788
* composable to render the both themes.
13889
*/
139-
@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO, name = "Light theme")
140-
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES, name = "Dark theme")
90+
@Preview
14191
annotation class ThemePreviews
14292

14393
@ThemePreviews

core/designsystem/src/main/kotlin/org/mifospay/core/designsystem/component/BottomSheet.kt core/designsystem/src/commonMain/kotlin/org/mifospay/core/designsystem/component/BottomSheet.kt

+11-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
*/
1010
package org.mifospay.core.designsystem.component
1111

12-
import androidx.activity.compose.BackHandler
1312
import androidx.compose.animation.AnimatedVisibility
1413
import androidx.compose.foundation.layout.Box
1514
import androidx.compose.foundation.layout.height
@@ -24,9 +23,10 @@ import androidx.compose.runtime.rememberCoroutineScope
2423
import androidx.compose.runtime.setValue
2524
import androidx.compose.ui.Modifier
2625
import androidx.compose.ui.graphics.Color
27-
import androidx.compose.ui.tooling.preview.Preview
2826
import androidx.compose.ui.unit.dp
27+
import com.arkivanov.essenty.backhandler.BackCallback
2928
import kotlinx.coroutines.launch
29+
import org.jetbrains.compose.ui.tooling.preview.Preview
3030

3131
@OptIn(ExperimentalMaterial3Api::class)
3232
@Composable
@@ -48,7 +48,7 @@ fun MifosBottomSheet(
4848
onDismiss.invoke()
4949
}
5050

51-
BackHandler(modalSheetState.isVisible) {
51+
BackCallback(modalSheetState.isVisible) {
5252
dismissSheet()
5353
}
5454

@@ -70,9 +70,12 @@ fun MifosBottomSheet(
7070
@Preview
7171
@Composable
7272
fun MifosBottomSheetPreview() {
73-
MifosBottomSheet({
74-
Box {
75-
Modifier.height(100.dp)
76-
}
77-
}, {})
73+
MifosBottomSheet(
74+
content = {
75+
Box {
76+
Modifier.height(100.dp)
77+
}
78+
},
79+
onDismiss = {},
80+
)
7881
}

core/designsystem/src/main/kotlin/org/mifospay/core/designsystem/component/LoadingWheel.kt core/designsystem/src/commonMain/kotlin/org/mifospay/core/designsystem/component/LoadingWheel.kt

+2-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ import androidx.compose.ui.platform.LocalInspectionMode
4646
import androidx.compose.ui.platform.testTag
4747
import androidx.compose.ui.semantics.contentDescription
4848
import androidx.compose.ui.semantics.semantics
49-
import androidx.compose.ui.tooling.preview.Preview
5049
import androidx.compose.ui.unit.dp
5150
import kotlinx.coroutines.launch
5251
import org.mifospay.core.designsystem.theme.MifosTheme
@@ -189,7 +188,7 @@ fun MfLoadingWheel(
189188
}
190189
}
191190

192-
@Preview
191+
@ThemePreviews
193192
@Composable
194193
fun MifosLoadingWheelPreview() {
195194
MifosTheme {
@@ -199,7 +198,7 @@ fun MifosLoadingWheelPreview() {
199198
}
200199
}
201200

202-
@Preview
201+
@ThemePreviews
203202
@Composable
204203
fun NiaOverlayLoadingWheelPreview() {
205204
MifosTheme {

core/designsystem/src/main/kotlin/org/mifospay/core/designsystem/component/MifosScaffold.kt core/designsystem/src/commonMain/kotlin/org/mifospay/core/designsystem/component/MifosScaffold.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import androidx.compose.ui.graphics.Color
2121
fun MifosScaffold(
2222
backPress: () -> Unit,
2323
modifier: Modifier = Modifier,
24-
topBarTitle: Int? = null,
24+
topBarTitle: String? = null,
2525
floatingActionButtonContent: FloatingActionButtonContent? = null,
2626
snackbarHost: @Composable () -> Unit = {},
2727
scaffoldContent: @Composable (PaddingValues) -> Unit = {},

core/designsystem/src/main/kotlin/org/mifospay/core/designsystem/component/MifosTopBar.kt core/designsystem/src/commonMain/kotlin/org/mifospay/core/designsystem/component/MifosTopBar.kt

+3-4
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,20 @@ import androidx.compose.material3.TopAppBar
1919
import androidx.compose.material3.TopAppBarDefaults
2020
import androidx.compose.runtime.Composable
2121
import androidx.compose.ui.Modifier
22-
import androidx.compose.ui.res.stringResource
2322
import org.mifospay.core.designsystem.icon.MifosIcons
2423

2524
@OptIn(ExperimentalMaterial3Api::class)
2625
@Composable
2726
fun MifosTopBar(
28-
topBarTitle: Int,
27+
topBarTitle: String,
2928
backPress: () -> Unit,
3029
modifier: Modifier = Modifier,
3130
actions: @Composable RowScope.() -> Unit = {},
3231
) {
3332
TopAppBar(
3433
title = {
3534
Text(
36-
text = stringResource(id = topBarTitle),
35+
text = topBarTitle,
3736
style = MaterialTheme.typography.titleLarge,
3837
color = MaterialTheme.colorScheme.onSurface,
3938
)
@@ -54,4 +53,4 @@ fun MifosTopBar(
5453
actions = actions,
5554
modifier = modifier,
5655
)
57-
}
56+
}

core/designsystem/src/main/kotlin/org/mifospay/core/designsystem/component/OutlineTextField.kt core/designsystem/src/commonMain/kotlin/org/mifospay/core/designsystem/component/OutlineTextField.kt

+11-20
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,30 @@
99
*/
1010
package org.mifospay.core.designsystem.component
1111

12-
import androidx.compose.foundation.Image
1312
import androidx.compose.foundation.text.KeyboardOptions
13+
import androidx.compose.material3.Icon
1414
import androidx.compose.material3.MaterialTheme
1515
import androidx.compose.material3.OutlinedTextField
1616
import androidx.compose.material3.OutlinedTextFieldDefaults
1717
import androidx.compose.material3.Text
1818
import androidx.compose.runtime.Composable
1919
import androidx.compose.ui.Modifier
20-
import androidx.compose.ui.graphics.ColorFilter
20+
import androidx.compose.ui.graphics.vector.ImageVector
2121
import androidx.compose.ui.platform.LocalDensity
22-
import androidx.compose.ui.res.painterResource
23-
import androidx.compose.ui.res.stringResource
2422
import androidx.compose.ui.text.TextStyle
2523
import androidx.compose.ui.text.input.ImeAction
2624
import androidx.compose.ui.text.input.VisualTransformation
2725
import androidx.compose.ui.unit.sp
2826

2927
@Composable
3028
fun MifosOutlinedTextField(
31-
label: Int,
29+
label: String,
3230
value: String,
3331
onValueChange: (String) -> Unit,
3432
modifier: Modifier = Modifier,
3533
maxLines: Int = 1,
3634
singleLine: Boolean = true,
37-
icon: Int? = null,
35+
icon: ImageVector? = null,
3836
error: Boolean = false,
3937
visualTransformation: VisualTransformation = VisualTransformation.None,
4038
trailingIcon: @Composable (() -> Unit)? = null,
@@ -43,18 +41,13 @@ fun MifosOutlinedTextField(
4341
OutlinedTextField(
4442
value = value,
4543
onValueChange = onValueChange,
46-
label = { Text(stringResource(id = label)) },
44+
label = { Text(label) },
4745
modifier = modifier,
48-
leadingIcon =
49-
if (icon != null) {
46+
leadingIcon = if (icon != null) {
5047
{
51-
Image(
52-
painter = painterResource(id = icon),
53-
contentDescription = null,
54-
colorFilter =
55-
ColorFilter.tint(
56-
MaterialTheme.colorScheme.onSurface,
57-
),
48+
Icon(
49+
imageVector = icon,
50+
contentDescription = icon.name,
5851
)
5952
}
6053
} else {
@@ -63,13 +56,11 @@ fun MifosOutlinedTextField(
6356
trailingIcon = trailingIcon,
6457
maxLines = maxLines,
6558
singleLine = singleLine,
66-
colors =
67-
OutlinedTextFieldDefaults.colors(
59+
colors = OutlinedTextFieldDefaults.colors(
6860
focusedBorderColor = MaterialTheme.colorScheme.onSurface,
6961
focusedLabelColor = MaterialTheme.colorScheme.onSurface,
7062
),
71-
textStyle =
72-
LocalDensity.current.run {
63+
textStyle = LocalDensity.current.run {
7364
TextStyle(fontSize = 18.sp, color = MaterialTheme.colorScheme.onSurface)
7465
},
7566
keyboardOptions = keyboardOptions,

0 commit comments

Comments
 (0)