@momo-kits/native-kits 0.162.1-beta.6 → 0.162.1-beta.7-debug

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/build.gradle.kts +11 -0
  2. package/compose/build.gradle.kts +193 -0
  3. package/compose/build.gradle.kts.backup +193 -0
  4. package/compose/compose.podspec +47 -0
  5. package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +6 -0
  6. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +123 -0
  7. package/compose/src/commonMain/composeResources/font/momosignature.otf +0 -0
  8. package/compose/src/commonMain/composeResources/font/momotrustdisplay.otf +0 -0
  9. package/compose/src/commonMain/composeResources/font/sfprotext_black.otf +0 -0
  10. package/compose/src/commonMain/composeResources/font/sfprotext_black.ttf +0 -0
  11. package/compose/src/commonMain/composeResources/font/sfprotext_bold.ttf +0 -0
  12. package/compose/src/commonMain/composeResources/font/sfprotext_heavy.ttf +0 -0
  13. package/compose/src/commonMain/composeResources/font/sfprotext_light.ttf +0 -0
  14. package/compose/src/commonMain/composeResources/font/sfprotext_medium.ttf +0 -0
  15. package/compose/src/commonMain/composeResources/font/sfprotext_regular.ttf +0 -0
  16. package/compose/src/commonMain/composeResources/font/sfprotext_semibold.ttf +0 -0
  17. package/compose/src/commonMain/composeResources/font/sfprotext_thin.otf +0 -0
  18. package/compose/src/commonMain/composeResources/font/sfprotext_thin.ttf +0 -0
  19. package/compose/src/commonMain/composeResources/font/sfprotext_ultralight.otf +0 -0
  20. package/compose/src/commonMain/composeResources/font/sfprotext_ultralight.ttf +0 -0
  21. package/compose/src/commonMain/kotlin/vn/momo/kits/application/AnimationSearchInput.kt +52 -0
  22. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +109 -0
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/application/FloatingButton.kt +183 -0
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Header.kt +207 -0
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderAnimated.kt +39 -0
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderBackground.kt +86 -0
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderDefault.kt +76 -0
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderExtended.kt +76 -0
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderRight.kt +294 -0
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderTitle.kt +33 -0
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +826 -0
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/application/NavigationContainer.kt +109 -0
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Screen.kt +378 -0
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/application/useHeaderSearchAnimation.kt +69 -0
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +157 -0
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +80 -0
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +32 -0
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +338 -0
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +175 -0
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +354 -0
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +113 -0
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +89 -0
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +128 -0
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +209 -0
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +543 -0
  46. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +23 -0
  47. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +76 -0
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +140 -0
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +204 -0
  50. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +112 -0
  51. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +477 -0
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +114 -0
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +214 -0
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +240 -0
  55. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +216 -0
  56. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +259 -0
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +180 -0
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +343 -0
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +108 -0
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +56 -0
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +41 -0
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +84 -0
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +40 -0
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +331 -0
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +97 -0
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +310 -0
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +59 -0
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +87 -0
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +90 -0
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +323 -0
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +217 -0
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +473 -0
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +122 -0
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +199 -0
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +91 -0
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +470 -0
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +88 -0
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +131 -0
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +203 -0
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +498 -0
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +177 -0
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +182 -0
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +193 -0
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +29 -0
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +234 -0
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +188 -0
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +306 -0
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +12 -0
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +16 -0
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +188 -0
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +270 -0
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +2 -0
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +35 -0
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +2 -0
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +52 -0
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +66 -0
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +11 -0
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +104 -0
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +48 -0
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +51 -0
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +253 -0
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +129 -0
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +94 -0
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +147 -0
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +360 -0
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +8 -0
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +557 -0
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +164 -0
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +223 -0
  110. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +86 -0
  111. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +169 -0
  112. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +319 -0
  113. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +81 -0
  114. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +309 -0
  115. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +34 -0
  116. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +360 -0
  117. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +132 -0
  118. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +128 -0
  119. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +70 -0
  120. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +58 -0
  121. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +1329 -0
  122. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +55 -0
  123. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +15 -0
  124. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +105 -0
  125. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +32 -0
  126. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +184 -0
  127. package/gradle/libs.versions.toml +72 -0
  128. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  129. package/gradle/wrapper/gradle-wrapper.properties +8 -0
  130. package/gradle.properties +26 -0
  131. package/gradlew +252 -0
  132. package/gradlew.bat +94 -0
  133. package/local.properties +8 -0
  134. package/package.json +1 -1
  135. package/settings.gradle.kts +64 -0
@@ -0,0 +1,140 @@
1
+ package vn.momo.kits.components
2
+
3
+ import androidx.compose.foundation.background
4
+ import androidx.compose.foundation.border
5
+ import androidx.compose.foundation.clickable
6
+ import androidx.compose.foundation.layout.Box
7
+ import androidx.compose.foundation.layout.size
8
+ import androidx.compose.foundation.shape.RoundedCornerShape
9
+ import androidx.compose.runtime.Composable
10
+ import androidx.compose.runtime.remember
11
+ import androidx.compose.ui.Alignment
12
+ import androidx.compose.ui.Modifier
13
+ import androidx.compose.ui.draw.clip
14
+ import androidx.compose.ui.graphics.Color
15
+ import androidx.compose.ui.unit.Dp
16
+ import androidx.compose.ui.unit.dp
17
+ import vn.momo.kits.application.IsShowBaseLineDebug
18
+ import vn.momo.kits.const.AppTheme
19
+ import vn.momo.kits.const.Colors
20
+ import vn.momo.kits.const.Radius
21
+ import vn.momo.kits.modifier.conditional
22
+
23
+ data class IconSpecs(
24
+ val width: Dp,
25
+ val height: Dp,
26
+ val radius: Dp,
27
+ val size: Dp
28
+ )
29
+
30
+ enum class IconSize(val value: IconSpecs) {
31
+ LARGE(
32
+ IconSpecs(
33
+ height = 48.dp,
34
+ radius = Radius.XL,
35
+ width = 48.dp,
36
+ size = 48.dp
37
+ )
38
+ ),
39
+ SMALL(
40
+ IconSpecs(
41
+ height = 40.dp,
42
+ radius = Radius.XL,
43
+ width = 40.dp,
44
+ size = 40.dp
45
+ )
46
+ )
47
+ }
48
+
49
+ // Pre-computed shape to avoid repeated creation
50
+ private val iconButtonShape = RoundedCornerShape(Radius.XL)
51
+
52
+ // Cache for icon sizes to avoid repeated calculations
53
+ private val iconSizeMap = mapOf(
54
+ IconSize.SMALL to 16.dp,
55
+ IconSize.LARGE to 24.dp
56
+ )
57
+
58
+ @Composable
59
+ internal fun getIconStyle(type: ButtonType, color: Color? = null): Modifier {
60
+ val theme = AppTheme.current
61
+
62
+ return remember(type, color, theme) {
63
+ when (type) {
64
+ ButtonType.DISABLED -> Modifier
65
+ .background(theme.colors.background.disable, iconButtonShape)
66
+ .border(0.dp, Color.Unspecified, iconButtonShape)
67
+
68
+ ButtonType.PRIMARY -> Modifier
69
+ .background(theme.colors.primary, iconButtonShape)
70
+ .border(0.dp, Color.Unspecified, iconButtonShape)
71
+
72
+ ButtonType.SECONDARY -> Modifier
73
+ .background(theme.colors.background.surface, iconButtonShape)
74
+ .border(1.dp, theme.colors.border.default, iconButtonShape)
75
+
76
+ ButtonType.OUTLINE -> Modifier
77
+ .background(theme.colors.background.surface, iconButtonShape)
78
+ .border(1.dp, color ?: theme.colors.primary, iconButtonShape)
79
+
80
+ ButtonType.TONAL -> Modifier
81
+ .background(theme.colors.background.tonal, iconButtonShape)
82
+ .border(0.dp, Color.Unspecified, iconButtonShape)
83
+
84
+ ButtonType.DANGER -> Modifier
85
+ .background(theme.colors.error.primary, iconButtonShape)
86
+ .border(0.dp, Color.Unspecified, iconButtonShape)
87
+
88
+ ButtonType.TEXT -> Modifier
89
+ }
90
+ }
91
+ }
92
+
93
+ @Composable
94
+ internal fun getIconColor(type: ButtonType): Color {
95
+ val theme = AppTheme.current
96
+ return remember(type, theme) {
97
+ getButtonColor(type, theme)
98
+ }
99
+ }
100
+
101
+ @Composable
102
+ fun IconButton(
103
+ onClick: () -> Unit,
104
+ type: ButtonType = ButtonType.PRIMARY,
105
+ size: IconSize = IconSize.SMALL,
106
+ icon: String = "",
107
+ ) {
108
+ // Memoize icon size calculation
109
+ val iconSize = remember(size) {
110
+ iconSizeMap[size] ?: 16.dp
111
+ }
112
+
113
+ // Memoize enabled state
114
+ val isEnabled = remember(type) {
115
+ type != ButtonType.DISABLED
116
+ }
117
+
118
+ // Memoize radius for clipping
119
+ val radius = remember(size) {
120
+ size.value.radius
121
+ }
122
+
123
+ Box(
124
+ modifier = Modifier
125
+ .size(size.value.size)
126
+ .then(getIconStyle(type))
127
+ .conditional(IsShowBaseLineDebug) {
128
+ border(1.dp, Colors.blue_03)
129
+ }
130
+ .clip(RoundedCornerShape(radius))
131
+ .clickable(enabled = isEnabled, onClick = onClick),
132
+ contentAlignment = Alignment.Center
133
+ ) {
134
+ Icon(
135
+ source = icon,
136
+ color = getIconColor(type),
137
+ size = iconSize,
138
+ )
139
+ }
140
+ }
@@ -0,0 +1,204 @@
1
+ package vn.momo.kits.components
2
+
3
+ import androidx.compose.foundation.border
4
+ import androidx.compose.foundation.layout.BoxWithConstraints
5
+ import androidx.compose.runtime.Composable
6
+ import androidx.compose.runtime.LaunchedEffect
7
+ import androidx.compose.runtime.remember
8
+ import androidx.compose.runtime.rememberUpdatedState
9
+ import androidx.compose.ui.Alignment
10
+ import androidx.compose.ui.Modifier
11
+ import androidx.compose.ui.graphics.ColorFilter
12
+ import androidx.compose.ui.graphics.DefaultAlpha
13
+ import androidx.compose.ui.graphics.painter.Painter
14
+ import androidx.compose.ui.layout.ContentScale
15
+ import androidx.compose.ui.semantics.contentDescription
16
+ import androidx.compose.ui.semantics.semantics
17
+ import androidx.compose.ui.platform.LocalDensity
18
+ import androidx.compose.ui.unit.dp
19
+ import com.github.panpf.sketch.AsyncImage as SketchAsyncImage
20
+ import com.github.panpf.sketch.PainterState
21
+ import com.github.panpf.sketch.rememberAsyncImageState
22
+ import vn.momo.kits.application.IsShowBaseLineDebug
23
+ import vn.momo.kits.const.AppTheme
24
+ import vn.momo.kits.const.Colors
25
+ import vn.momo.kits.modifier.conditional
26
+
27
+ data class Options(
28
+ val alignment: Alignment = Alignment.TopStart,
29
+ val contentScale: ContentScale = ContentScale.Crop,
30
+ val colorFilter: ColorFilter? = null,
31
+ val alpha: Float = DefaultAlpha,
32
+ )
33
+
34
+ enum class ImageState {
35
+ Loading, Success, Error
36
+ }
37
+
38
+ // Cached domain set for better performance
39
+ private val supportedDomains = setOf(
40
+ "static.momocdn.net",
41
+ "img.mservice.com.vn",
42
+ "cdn.mservice.com.vn",
43
+ "img.mservice.io",
44
+ "image.momocdn.net"
45
+ )
46
+
47
+ // Pre-computed size chart for optimal image sizing
48
+ private val sizeChart = mapOf(
49
+ 64 to "XXS",
50
+ 128 to "XS",
51
+ 256 to "S",
52
+ 512 to "M",
53
+ 768 to "L",
54
+ 1024 to "XL",
55
+ 2048 to "XXL"
56
+ )
57
+
58
+ // Optimized size selection using binary search approach
59
+ private fun closestSizeForWidth(width: Float): String {
60
+ val targetWidth = width.toInt()
61
+ return sizeChart.entries
62
+ .minByOrNull { kotlin.math.abs(it.key - targetWidth) }
63
+ ?.value ?: "M"
64
+ }
65
+
66
+ // Cached regex for better URL parsing performance
67
+ private val urlHostRegex = Regex("^(?:https?://)?([^:/\\s]+)")
68
+
69
+ private fun getHostFromUrl(url: String): String? {
70
+ return try {
71
+ urlHostRegex.find(url)?.groupValues?.get(1)
72
+ } catch (_: Exception) {
73
+ null
74
+ }
75
+ }
76
+
77
+ private fun isGifUrl(url: String): Boolean {
78
+ val path = url.substringBefore('#').substringBefore('?')
79
+ return path.endsWith(".gif", ignoreCase = true)
80
+ }
81
+
82
+ // Optimized query parameter appending
83
+ private fun appendSizeQueryParam(url: String, value: String): String {
84
+ val fragmentIndex = url.indexOf('#')
85
+ val (baseUrl, fragment) = if (fragmentIndex != -1) {
86
+ url.take(fragmentIndex) to url.substring(fragmentIndex)
87
+ } else {
88
+ url to ""
89
+ }
90
+
91
+ val separator = if (baseUrl.contains('?')) "&" else "?"
92
+ return "${baseUrl}${separator}size=$value$fragment"
93
+ }
94
+
95
+ // Cache for processed URLs to avoid repeated calculations
96
+ private val urlCache = mutableMapOf<String, String>()
97
+
98
+ @Composable
99
+ fun Image(
100
+ source: Any,
101
+ modifier: Modifier = Modifier,
102
+ options: Options? = null,
103
+ loading: Boolean = true,
104
+ onLoadingChanged: (Boolean) -> Unit = {},
105
+ ) {
106
+ val imageOptions = remember(options) {
107
+ options ?: Options()
108
+ }
109
+
110
+ val asyncImageState = rememberAsyncImageState()
111
+ val currentOnLoadingChanged = rememberUpdatedState(onLoadingChanged)
112
+ val density = LocalDensity.current
113
+
114
+ BoxWithConstraints(
115
+ modifier = modifier
116
+ .conditional(IsShowBaseLineDebug) {
117
+ border(1.dp, Colors.blue_03)
118
+ }
119
+ .semantics { contentDescription = "img|$source" },
120
+ ) {
121
+ val urlToLoad = remember(source, maxWidth, maxHeight, density) {
122
+ when (source) {
123
+ is String -> {
124
+ // Check cache first
125
+ val cacheKey = "$source|${maxWidth}|${density.density}"
126
+ urlCache[cacheKey] ?: run {
127
+ val processedUrl = processImageUrl(source, maxWidth, density)
128
+ urlCache[cacheKey] = processedUrl
129
+ processedUrl
130
+ }
131
+ }
132
+ else -> source.toString()
133
+ }
134
+ }
135
+
136
+ SketchAsyncImage(
137
+ modifier = Modifier.matchParentSize(),
138
+ uri = urlToLoad,
139
+ state = asyncImageState,
140
+ contentDescription = null,
141
+ contentScale = imageOptions.contentScale,
142
+ alignment = imageOptions.alignment,
143
+ colorFilter = imageOptions.colorFilter,
144
+ alpha = imageOptions.alpha,
145
+ )
146
+
147
+ val isLoading = when (asyncImageState.painterState) {
148
+ is PainterState.Success,
149
+ is PainterState.Error -> false
150
+ else -> true
151
+ }
152
+
153
+ LaunchedEffect(isLoading) {
154
+ currentOnLoadingChanged.value(isLoading)
155
+ }
156
+
157
+ when (asyncImageState.painterState) {
158
+ is PainterState.Success -> {}
159
+ is PainterState.Error -> {
160
+ val theme = AppTheme.current
161
+ Icon(
162
+ source = "media_fail",
163
+ color = theme.colors.text.disable,
164
+ modifier = Modifier.align(Alignment.Center)
165
+ )
166
+ }
167
+ else -> if (loading) Skeleton()
168
+ }
169
+ }
170
+ }
171
+
172
+ // Extracted URL processing logic for better performance
173
+ private fun processImageUrl(url: String, maxWidth: androidx.compose.ui.unit.Dp, density: androidx.compose.ui.unit.Density): String {
174
+ val host = getHostFromUrl(url)
175
+ return if (!isGifUrl(url) && host != null && supportedDomains.contains(host)) {
176
+ val widthPx = with(density) { maxWidth.roundToPx() }
177
+ val pixelRatio = density.density
178
+ val pixelFitForWidth = widthPx * pixelRatio
179
+ val sizeKey = closestSizeForWidth(pixelFitForWidth)
180
+ appendSizeQueryParam(url, sizeKey)
181
+ } else {
182
+ url
183
+ }
184
+ }
185
+
186
+ @Composable
187
+ fun Image(
188
+ source: Painter,
189
+ modifier: Modifier = Modifier,
190
+ colorFilter: ColorFilter? = null,
191
+ alpha: Float = DefaultAlpha,
192
+ contentScale: ContentScale = ContentScale.Crop,
193
+ alignment: Alignment = Alignment.Center,
194
+ ) {
195
+ androidx.compose.foundation.Image(
196
+ modifier = modifier,
197
+ painter = source,
198
+ contentDescription = null,
199
+ contentScale = contentScale,
200
+ alignment = alignment,
201
+ colorFilter = colorFilter,
202
+ alpha = alpha,
203
+ )
204
+ }
@@ -0,0 +1,112 @@
1
+ package vn.momo.kits.components
2
+
3
+ import androidx.compose.foundation.background
4
+ import androidx.compose.foundation.border
5
+ import androidx.compose.foundation.clickable
6
+ import androidx.compose.foundation.layout.*
7
+ import androidx.compose.foundation.shape.RoundedCornerShape
8
+ import androidx.compose.runtime.Composable
9
+ import androidx.compose.ui.Modifier
10
+ import androidx.compose.ui.draw.clip
11
+ import androidx.compose.ui.text.style.TextAlign
12
+ import androidx.compose.ui.unit.dp
13
+ import vn.momo.kits.application.IsShowBaseLineDebug
14
+ import vn.momo.kits.const.Colors
15
+ import vn.momo.kits.const.Radius
16
+ import vn.momo.kits.const.Spacing
17
+ import vn.momo.kits.const.Typography
18
+ import vn.momo.kits.modifier.conditional
19
+
20
+ enum class InformationState {
21
+ DEFAULT,
22
+ WARNING,
23
+ ERROR
24
+ }
25
+
26
+ @Composable
27
+ fun Information(
28
+ title: String? = null,
29
+ description: String = "Description",
30
+ state: InformationState = InformationState.DEFAULT,
31
+ image: String? = null,
32
+ onPressAction: (() -> Unit)? = null,
33
+ showIcon: Boolean = true,
34
+ action: String? = null,
35
+ showIconClose: Boolean = true,
36
+ onPressClose: (() -> Unit)? = null,
37
+ ) {
38
+ var borderColor = Colors.blue_07
39
+ var backgroundColor = Colors.blue_10
40
+ var color = Colors.blue_03
41
+ var iconSource = "notifications_info"
42
+
43
+ if (state === InformationState.WARNING) {
44
+ borderColor = Colors.yellow_06
45
+ backgroundColor = Colors.yellow_09
46
+ color = Colors.orange_03
47
+ iconSource = "24_notifications_alert_triangle"
48
+ }
49
+
50
+ if (state === InformationState.ERROR) {
51
+ borderColor = Colors.red_07
52
+ backgroundColor = Colors.red_10
53
+ color = Colors.red_03
54
+ iconSource = "24_notifications_alert_octagon"
55
+ }
56
+
57
+ Column(
58
+ modifier = Modifier.border(
59
+ width = 0.5.dp,
60
+ shape = RoundedCornerShape(Radius.S),
61
+ color = borderColor
62
+ ).background(color = backgroundColor)
63
+ .conditional(IsShowBaseLineDebug) {
64
+ border(1.dp, Colors.blue_03)
65
+ }
66
+ .padding(Spacing.M)
67
+ ) {
68
+ Row {
69
+ if (image != null) {
70
+ Image(
71
+ source = image,
72
+ modifier = Modifier.padding(end = Spacing.S).width(40.dp).height(40.dp).clip(
73
+ RoundedCornerShape(Radius.S)
74
+ )
75
+ )
76
+ }
77
+ if (image == null && showIcon) {
78
+ Icon(
79
+ source = iconSource,
80
+ size = 16.dp,
81
+ color = color,
82
+ modifier = Modifier.padding(end = Spacing.S)
83
+ )
84
+ }
85
+ Column(modifier = Modifier.weight(1f)) {
86
+ if (title != null) {
87
+ Text(title, style = Typography.labelDefaultMedium)
88
+ }
89
+ Text(description, style = Typography.descriptionDefaultRegular)
90
+ }
91
+ if (onPressClose != null && showIconClose) {
92
+ Icon(
93
+ source = "navigation_close",
94
+ size = 16.dp,
95
+ modifier = Modifier.clickable(onClick = onPressClose)
96
+ )
97
+ }
98
+ }
99
+ if (action != null && onPressAction != null) {
100
+ Row(modifier = Modifier.padding(top = Spacing.S)) {
101
+ Text(
102
+ action,
103
+ modifier = Modifier.weight(1f).clickable(onClick = onPressAction),
104
+ textAlign = TextAlign.End,
105
+ style = Typography.actionXsBold,
106
+ color = color
107
+ )
108
+ }
109
+ }
110
+ }
111
+
112
+ }