@momo-kits/native-kits 0.169.10-beta.1 → 0.169.10-beta.1-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 (140) hide show
  1. package/build.gradle.kts +11 -0
  2. package/compose/build.gradle.kts +198 -0
  3. package/compose/compose.podspec +47 -0
  4. package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +19 -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/BackGesture.android.kt +12 -0
  7. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +7 -0
  8. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +154 -0
  9. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +17 -0
  10. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReservedRegions.android.kt +6 -0
  11. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +110 -0
  12. package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +62 -0
  13. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +1067 -0
  14. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +267 -0
  15. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +56 -0
  16. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +157 -0
  17. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +82 -0
  18. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +32 -0
  19. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +338 -0
  20. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +175 -0
  21. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +356 -0
  22. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +115 -0
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +89 -0
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +128 -0
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +209 -0
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +482 -0
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +49 -0
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +86 -0
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +125 -0
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +224 -0
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +195 -0
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +473 -0
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +113 -0
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +263 -0
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +235 -0
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +228 -0
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +280 -0
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +183 -0
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +343 -0
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +108 -0
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +56 -0
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +40 -0
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +82 -0
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +39 -0
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +363 -0
  46. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +108 -0
  47. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +307 -0
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +59 -0
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +87 -0
  50. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +21 -0
  51. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +88 -0
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +306 -0
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +220 -0
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +457 -0
  55. package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +122 -0
  56. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +205 -0
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +89 -0
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +542 -0
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +86 -0
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +120 -0
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +201 -0
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +498 -0
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +176 -0
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +182 -0
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +193 -0
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +29 -0
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +210 -0
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +180 -0
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +325 -0
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +12 -0
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +12 -0
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +16 -0
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +194 -0
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +292 -0
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +54 -0
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/HeaderLayout.kt +67 -0
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +50 -0
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +184 -0
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +316 -0
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +41 -0
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +52 -0
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +66 -0
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +11 -0
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +104 -0
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +48 -0
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +51 -0
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +397 -0
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/HostBackGestureBridge.kt +58 -0
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +153 -0
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +118 -0
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +205 -0
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +422 -0
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +8 -0
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +747 -0
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +148 -0
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +35 -0
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +242 -0
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +400 -0
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +100 -0
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +97 -0
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +207 -0
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +132 -0
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +167 -0
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +446 -0
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +105 -0
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderJourney.kt +106 -0
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderLocation.kt +74 -0
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +398 -0
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +39 -0
  110. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +363 -0
  111. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +197 -0
  112. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +133 -0
  113. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +127 -0
  114. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +12 -0
  115. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +114 -0
  116. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +9 -0
  117. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +76 -0
  118. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +7 -0
  119. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +22 -0
  120. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +1329 -0
  121. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +55 -0
  122. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +15 -0
  123. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +118 -0
  124. package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +42 -0
  125. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/HostBackGesture.ios.kt +45 -0
  126. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +32 -0
  127. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/BackGesture.ios.kt +38 -0
  128. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +66 -0
  129. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +218 -0
  130. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +48 -0
  131. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +144 -0
  132. package/gradle/libs.versions.toml +67 -0
  133. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  134. package/gradle/wrapper/gradle-wrapper.properties +8 -0
  135. package/gradle.properties +24 -0
  136. package/gradlew +252 -0
  137. package/gradlew.bat +94 -0
  138. package/ios-demo/README.md +120 -0
  139. package/package.json +1 -1
  140. package/settings.gradle.kts +64 -0
@@ -0,0 +1,363 @@
1
+ package vn.momo.kits.components
2
+
3
+ import androidx.compose.foundation.background
4
+ import androidx.compose.foundation.border
5
+ import androidx.compose.foundation.rememberScrollState
6
+ import androidx.compose.foundation.verticalScroll
7
+ import androidx.compose.foundation.layout.*
8
+ import androidx.compose.foundation.lazy.LazyColumn
9
+ import androidx.compose.foundation.shape.RoundedCornerShape
10
+ import androidx.compose.runtime.*
11
+ import androidx.compose.ui.Alignment
12
+ import androidx.compose.ui.Modifier
13
+ import androidx.compose.ui.draw.clip
14
+ import androidx.compose.ui.platform.LocalDensity
15
+ import androidx.compose.ui.text.TextLayoutResult
16
+ import androidx.compose.ui.unit.Dp
17
+ import androidx.compose.ui.unit.dp
18
+ import vn.momo.kits.application.IsShowBaseLineDebug
19
+ import vn.momo.kits.application.LocalLocalize
20
+ import vn.momo.kits.const.*
21
+ import vn.momo.kits.modifier.conditional
22
+ import vn.momo.kits.modifier.setAutomationId
23
+ import vn.momo.kits.layout.MODAL_ICON_BUTTON_SIZE
24
+ import vn.momo.kits.layout.ModalIconButton
25
+ import vn.momo.kits.layout.rememberModalLayout
26
+ import kotlin.math.min
27
+
28
+ data class PopupAction(
29
+ val title: String,
30
+ val onPress: (() -> Unit)?,
31
+ )
32
+
33
+ enum class PopupActionDirection {
34
+ ROW,
35
+ COLUMN,
36
+ AUTO
37
+ }
38
+
39
+ // Card width on foldables (ModalLayout, RN Popup/utils.ts); unbounded on phones, where each popup's padding sets it.
40
+ @Composable
41
+ internal fun popupMaxWidth(): Dp {
42
+ val modal = rememberModalLayout()
43
+ return if (modal.isFoldable) modal.popup.maxWidth else Dp.Unspecified
44
+ }
45
+
46
+ // The placement already keeps foldable popups off the edges, so their own side padding goes.
47
+ @Composable
48
+ internal fun popupHorizontalPadding(padding: Dp): Dp =
49
+ if (rememberModalLayout().isFoldable) 0.dp else padding
50
+
51
+ // Tallest a popup gets on foldables; null on phones.
52
+ @Composable
53
+ internal fun popupMaxHeight(): Dp? = rememberModalLayout().popup.maxHeight
54
+
55
+ @Composable
56
+ internal fun popupRadius(): Dp = rememberModalLayout().popup.radius
57
+
58
+ private fun heightForLines(
59
+ layout: TextLayoutResult,
60
+ ): Float {
61
+ val clampedLines = (8.5f).coerceAtLeast(1f)
62
+ val wholeLines = kotlin.math.floor(clampedLines).toInt()
63
+ val fractionalPart = clampedLines - wholeLines
64
+
65
+ val baseLineIndex = (wholeLines - 1)
66
+ .coerceAtLeast(0)
67
+ .coerceAtMost(layout.lineCount - 1)
68
+
69
+ var heightPx = layout.getLineBottom(baseLineIndex)
70
+
71
+ if (fractionalPart > 0f) {
72
+ val nextLineIndex = (baseLineIndex + 1)
73
+ .coerceAtMost(layout.lineCount - 1)
74
+ val nextBottomPx = layout.getLineBottom(nextLineIndex)
75
+ heightPx += (nextBottomPx - heightPx) * fractionalPart
76
+ }
77
+ return heightPx
78
+ }
79
+
80
+ data class PopupNotifyProps(
81
+ val image: String = "",
82
+ val title: String = "Title",
83
+ val description: String = "Description",
84
+ val error: String = "",
85
+ val primary: PopupAction? = null,
86
+ val secondary: PopupAction? = null,
87
+ val buttonDirection: PopupActionDirection = PopupActionDirection.ROW,
88
+ val onIconClose: () -> Unit,
89
+ val isShowCloseIcon: Boolean = true,
90
+ val highlightText: List<String> = emptyList(),
91
+ )
92
+
93
+ @Composable
94
+ fun PopupNotify(
95
+ props: PopupNotifyProps,
96
+ ) {
97
+ var isScroll by remember { mutableStateOf(false) }
98
+ val layoutResult = remember { mutableStateOf<TextLayoutResult?>(null) }
99
+
100
+ val density = LocalDensity.current
101
+ var scrollHeight: Dp by remember { mutableStateOf(0.dp) }
102
+ val description = rememberHighlightDescription(props.description, props.highlightText)
103
+
104
+ LaunchedEffect(layoutResult.value) {
105
+ if ((layoutResult.value?.lineCount ?: 0) > 3) {
106
+ isScroll = true
107
+ }
108
+ }
109
+
110
+ LaunchedEffect(layoutResult.value) {
111
+ layoutResult.value?.let { v ->
112
+ // cap visible height at ~8.5 lines
113
+ val textPx = v.size.height.toFloat()
114
+ val capPx = heightForLines(v)
115
+
116
+ isScroll = textPx >= capPx
117
+ scrollHeight = with(density) { min(textPx, capPx).toDp() }
118
+ }
119
+ }
120
+
121
+ val content: @Composable (Modifier) -> Unit = if (isScroll) {
122
+ { modifier ->
123
+ LazyColumn(
124
+ modifier = modifier.height(scrollHeight)
125
+ ) {
126
+ item {
127
+ Text(
128
+ text = description,
129
+ onTextLayout = { layoutResult.value = it },
130
+ style = Typography.bodyDefaultRegular
131
+ )
132
+ }
133
+ }
134
+ }
135
+ } else {
136
+ { modifier ->
137
+ Box(modifier = modifier) {
138
+ Text(
139
+ text = description,
140
+ onTextLayout = { layoutResult.value = it },
141
+ style = Typography.bodyDefaultRegular
142
+ )
143
+ }
144
+ }
145
+ }
146
+
147
+ fun onClose(callback: (() -> Unit)?) {
148
+ callback?.invoke()
149
+ }
150
+
151
+ val popup = rememberModalLayout().popup
152
+ val maxHeight = popup.maxHeight
153
+ val descriptionScrollState = rememberScrollState()
154
+ val shape = RoundedCornerShape(popup.radius)
155
+
156
+ Box(
157
+ Modifier
158
+ .widthIn(min = popup.minWidth, max = popup.maxWidth)
159
+ .fillMaxWidth()
160
+ .setAutomationId("popup_notify"),
161
+ contentAlignment = Alignment.TopEnd
162
+ ) {
163
+ Column(
164
+ modifier = Modifier
165
+ .fillMaxWidth()
166
+ .clip(shape)
167
+ .background(AppTheme.current.colors.background.surface, shape)
168
+ .conditional(IsShowBaseLineDebug) {
169
+ border(1.dp, Colors.blue_03)
170
+ }
171
+ .conditional(maxHeight != null) {
172
+ heightIn(max = maxHeight ?: Dp.Unspecified)
173
+ }
174
+ ) {
175
+ if(props.image.isNotEmpty()) {
176
+ Image(
177
+ source = props.image,
178
+ modifier = Modifier.fillMaxWidth().aspectRatio(1.777f),
179
+ options = Options(alignment = Alignment.Center)
180
+ )
181
+ }
182
+
183
+ // with a max height only the description scrolls; image, title and actions stay
184
+ Column(
185
+ modifier = Modifier
186
+ .conditional(maxHeight != null) { weight(1f, fill = false) }
187
+ .padding(Spacing.XL)
188
+ ) {
189
+ Text(
190
+ style = Typography.headerDefaultBold,
191
+ maxLines = 2,
192
+ text = props.title,
193
+ modifier = Modifier
194
+ .conditional(props.isShowCloseIcon && props.image.isEmpty()) {
195
+ padding(end = MODAL_ICON_BUTTON_SIZE + Spacing.M - Spacing.XL)
196
+ }
197
+ .setAutomationId("title_popup_permission")
198
+ )
199
+ if (maxHeight != null) {
200
+ // still capped at ~8.5 lines, then shrinks further when the popup reaches its max height
201
+ Box(
202
+ Modifier
203
+ .padding(top = Spacing.S)
204
+ .weight(1f, fill = false)
205
+ .conditional(isScroll) { heightIn(max = scrollHeight) }
206
+ .verticalScroll(descriptionScrollState)
207
+ ) {
208
+ Text(
209
+ text = description,
210
+ onTextLayout = { layoutResult.value = it },
211
+ style = Typography.bodyDefaultRegular
212
+ )
213
+ }
214
+ } else {
215
+ content(Modifier.padding(top = Spacing.S))
216
+ }
217
+ if (props.error.isNotEmpty()) {
218
+ Text(
219
+ text = LocalLocalize.current.translate("errorCode") + props.error,
220
+ style = Typography.descriptionXsRegular,
221
+ color = AppTheme.current.colors.text.hint,
222
+ maxLines = 1,
223
+ modifier = Modifier.padding(top = Spacing.S)
224
+ )
225
+ }
226
+ }
227
+
228
+ Box(
229
+ modifier = Modifier.padding(horizontal = Spacing.XL)
230
+ .padding(bottom = Spacing.XL)
231
+ ) {
232
+ BuildAction(props.primary, props.secondary, props.buttonDirection, onAction = { callback ->
233
+ onClose(callback)
234
+ })
235
+ }
236
+ }
237
+
238
+ if (props.isShowCloseIcon) {
239
+ ModalIconButton(
240
+ icon = "navigation_close",
241
+ automationId = "ic_popup_close",
242
+ onClick = { onClose { props.onIconClose() } },
243
+ modifier = Modifier.padding(top = Spacing.M, end = Spacing.M),
244
+ )
245
+ }
246
+ }
247
+ }
248
+
249
+ @Composable
250
+ internal fun BuildAction(
251
+ primary: PopupAction?,
252
+ secondary: PopupAction?,
253
+ buttonDirection: PopupActionDirection = PopupActionDirection.ROW,
254
+ onAction: (onPress: (() -> Unit)?) -> Unit,
255
+ ) {
256
+ val closeAction = remember { mutableStateOf("button_action") }
257
+ when (buttonDirection) {
258
+ PopupActionDirection.AUTO -> {
259
+ if (secondary != null && (secondary.title.length > 12 || (primary?.title?.length ?: 0) > 12)) {
260
+ RenderColumn(
261
+ secondary = secondary,
262
+ onAction = onAction,
263
+ closeAction = closeAction,
264
+ primary = primary
265
+ )
266
+ } else {
267
+ RenderRow(
268
+ secondary = secondary,
269
+ onAction = onAction,
270
+ closeAction = closeAction,
271
+ primary = primary
272
+ )
273
+ }
274
+ }
275
+
276
+ PopupActionDirection.ROW -> RenderRow(
277
+ secondary = secondary,
278
+ onAction = onAction,
279
+ closeAction = closeAction,
280
+ primary = primary
281
+ )
282
+
283
+ else -> RenderColumn(
284
+ secondary = secondary,
285
+ onAction = onAction,
286
+ closeAction = closeAction,
287
+ primary = primary
288
+ )
289
+ }
290
+ }
291
+
292
+ @Composable
293
+ internal fun RenderRow(
294
+ secondary: PopupAction?,
295
+ closeAction: MutableState<String>,
296
+ primary: PopupAction?,
297
+ onAction: (onPress: (() -> Unit)?) -> Unit,
298
+ ) {
299
+ Row(horizontalArrangement = Arrangement.Center) {
300
+ secondary?.let {
301
+ Box(Modifier.weight(1f)) {
302
+ Button(
303
+ size = Size.MEDIUM,
304
+ onClick = {
305
+ closeAction.value = "button_action"
306
+ onAction(it.onPress)
307
+ },
308
+ title = it.title,
309
+ type = ButtonType.TEXT,
310
+ modifier = Modifier.setAutomationId("btn_popup_cancel")
311
+ )
312
+ }
313
+ Spacer(modifier = Modifier.width(Spacing.S))
314
+ }
315
+ Box(Modifier.weight(1f)) {
316
+ Button(
317
+ size = Size.MEDIUM,
318
+ onClick = {
319
+ closeAction.value = "button_action"
320
+ onAction(primary?.onPress)
321
+ },
322
+ title = primary?.title ?: "",
323
+ modifier = Modifier.setAutomationId("btn_popup_allow")
324
+ )
325
+ }
326
+ }
327
+ }
328
+
329
+ @Composable
330
+ internal fun RenderColumn(
331
+ secondary: PopupAction?,
332
+ closeAction: MutableState<String>,
333
+ primary: PopupAction?,
334
+ onAction: (onPress: (() -> Unit)?) -> Unit,
335
+ ) {
336
+ Column(horizontalAlignment = Alignment.CenterHorizontally) {
337
+ Button(
338
+ size = Size.MEDIUM,
339
+ onClick = {
340
+ closeAction.value = "button_action"
341
+ onAction(primary?.onPress)
342
+ },
343
+ title = primary?.title ?: "",
344
+ modifier = Modifier.setAutomationId("btn_popup_allow")
345
+ )
346
+ secondary?.let {
347
+ Spacer(modifier = Modifier.height(Spacing.S))
348
+ secondary.let {
349
+ Button(
350
+ size = Size.MEDIUM,
351
+ onClick = {
352
+ closeAction.value = "button_action"
353
+ onAction(it.onPress)
354
+ },
355
+ title = it.title,
356
+ type = ButtonType.TEXT,
357
+ modifier = Modifier.setAutomationId("btn_popup_cancel")
358
+ )
359
+ }
360
+ }
361
+ }
362
+ }
363
+
@@ -0,0 +1,108 @@
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.interaction.MutableInteractionSource
7
+ import androidx.compose.foundation.layout.*
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.layout.ContentScale
15
+ import androidx.compose.ui.unit.dp
16
+ import vn.momo.kits.application.IsShowBaseLineDebug
17
+ import vn.momo.kits.const.AppTheme
18
+ import vn.momo.kits.const.Colors
19
+ import vn.momo.kits.const.Radius
20
+ import vn.momo.kits.const.Spacing
21
+ import vn.momo.kits.modifier.conditional
22
+ import vn.momo.kits.modifier.setAutomationId
23
+ import vn.momo.kits.utils.ifNotNull
24
+
25
+ private const val ASPECT_RATIO = 0.72f
26
+ private val CLOSE_ROW_HEIGHT = Spacing.S + 40.dp
27
+
28
+ @Composable
29
+ fun PopupPromotion(
30
+ source: String = "",
31
+ onPress: (() -> Unit) = {},
32
+ onClose: (() -> Unit) = {},
33
+ ) {
34
+ val maxHeight = popupMaxHeight()
35
+ var maxWidth = popupMaxWidth()
36
+ if (maxHeight != null) {
37
+ // fit the portrait image by height when iPhone Duo leaves too little room
38
+ maxWidth = minOf(maxWidth, (maxHeight - CLOSE_ROW_HEIGHT) * ASPECT_RATIO)
39
+ }
40
+
41
+ Column(Modifier
42
+ .widthIn(max = maxWidth)
43
+ .padding(horizontal = popupHorizontalPadding(Spacing.M))
44
+ .conditional(IsShowBaseLineDebug) {
45
+ border(1.dp, Colors.blue_03)
46
+ }
47
+ .setAutomationId("popup_notify")) {
48
+ source.ifNotNull(
49
+ Image(
50
+ source = source,
51
+ modifier = Modifier.fillMaxWidth()
52
+ .aspectRatio(ASPECT_RATIO)
53
+ .clickable(
54
+ interactionSource = remember { MutableInteractionSource() },
55
+ indication = null,
56
+ onClick = onPress
57
+ ),
58
+ options = Options(alignment = Alignment.Center, contentScale = ContentScale.FillBounds)
59
+ ), null
60
+ )
61
+ Box(
62
+ modifier = Modifier
63
+ .padding(top = Spacing.S)
64
+ .fillMaxWidth()
65
+ .width(40.dp)
66
+ .height(40.dp),
67
+ contentAlignment = Alignment.Center
68
+ ) {
69
+ Box(
70
+ modifier = Modifier
71
+ .width(40.dp)
72
+ .height(40.dp)
73
+ .clickable(
74
+ interactionSource = remember { MutableInteractionSource() },
75
+ indication = null,
76
+ onClick = onClose
77
+ ),
78
+ contentAlignment = Alignment.Center
79
+ ) {
80
+ Box(
81
+ Modifier
82
+ .width(22.dp)
83
+ .height(22.dp)
84
+ .background(
85
+ color = AppTheme.current.colors.text.default,
86
+ shape = RoundedCornerShape(Radius.M)
87
+ )
88
+ .border(
89
+ width = 2.dp,
90
+ color = AppTheme.current.colors.background.surface,
91
+ shape = RoundedCornerShape(Radius.M)
92
+ )
93
+ .clip(RoundedCornerShape(100))
94
+ ,
95
+ contentAlignment = Alignment.Center
96
+ ) {
97
+ Icon(
98
+ source = "navigation_close",
99
+ color = AppTheme.current.colors.background.surface,
100
+ size = 16.dp,
101
+ modifier = Modifier.setAutomationId("ic_popup_close")
102
+ )
103
+ }
104
+ }
105
+
106
+ }
107
+ }
108
+ }