@momo-kits/native-kits 0.162.46 → 0.162.47-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 +198 -0
  3. package/compose/build.gradle.kts.backup +198 -0
  4. package/compose/compose.podspec +47 -0
  5. package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +20 -0
  6. package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +6 -0
  7. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/BackGesture.android.kt +12 -0
  8. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +7 -0
  9. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +153 -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 +1071 -0
  14. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +269 -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 +81 -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 +357 -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 +542 -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 +231 -0
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +189 -0
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +478 -0
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +114 -0
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +265 -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 +223 -0
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +265 -0
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +185 -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 +41 -0
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +84 -0
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +40 -0
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +361 -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 +308 -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 +90 -0
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +330 -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 +473 -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 +207 -0
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +92 -0
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +560 -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 +125 -0
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +207 -0
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +501 -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 +236 -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 +17 -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 +287 -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/Item.kt +50 -0
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +314 -0
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +41 -0
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +52 -0
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +66 -0
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +11 -0
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +104 -0
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +48 -0
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +51 -0
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +338 -0
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/HostBackGestureBridge.kt +58 -0
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +137 -0
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +116 -0
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +205 -0
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +399 -0
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +8 -0
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +732 -0
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +148 -0
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +35 -0
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +228 -0
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +217 -0
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +86 -0
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +97 -0
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +377 -0
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +169 -0
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +455 -0
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +103 -0
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderJourney.kt +106 -0
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderLocation.kt +74 -0
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +399 -0
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +39 -0
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +363 -0
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +192 -0
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +133 -0
  110. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +127 -0
  111. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +12 -0
  112. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +91 -0
  113. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +9 -0
  114. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +74 -0
  115. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +13 -0
  116. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +1329 -0
  117. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +55 -0
  118. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +15 -0
  119. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +118 -0
  120. package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +42 -0
  121. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/HostBackGesture.ios.kt +45 -0
  122. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +32 -0
  123. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/BackGesture.ios.kt +38 -0
  124. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +66 -0
  125. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +217 -0
  126. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +94 -0
  127. package/gradle/libs.versions.toml +69 -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/ios-demo/README.md +120 -0
  134. package/package.json +1 -1
  135. package/settings.gradle.kts +64 -0
@@ -0,0 +1,103 @@
1
+ package vn.momo.kits.navigation.component
2
+
3
+ import androidx.compose.animation.core.animateFloatAsState
4
+ import androidx.compose.foundation.background
5
+ import androidx.compose.foundation.layout.Box
6
+ import androidx.compose.foundation.layout.fillMaxHeight
7
+ import androidx.compose.foundation.layout.fillMaxSize
8
+ import androidx.compose.foundation.layout.fillMaxWidth
9
+ import androidx.compose.foundation.layout.height
10
+ import androidx.compose.runtime.Composable
11
+ import androidx.compose.runtime.getValue
12
+ import androidx.compose.ui.Modifier
13
+ import androidx.compose.ui.draw.clipToBounds
14
+ import androidx.compose.ui.graphics.graphicsLayer
15
+ import androidx.compose.ui.graphics.Brush
16
+ import androidx.compose.ui.graphics.Color
17
+ import androidx.compose.ui.platform.LocalDensity
18
+ import androidx.compose.ui.unit.dp
19
+ import vn.momo.kits.components.Image
20
+ import vn.momo.kits.const.AppTheme
21
+ import vn.momo.kits.layout.getScreenLayout
22
+ import vn.momo.kits.modifier.conditional
23
+ import vn.momo.kits.navigation.LocalOptions
24
+ import vn.momo.kits.navigation.LocalScrollState
25
+ import vn.momo.kits.navigation.getInputSearchType
26
+ import vn.momo.kits.navigation.usesDuoGlassHeader
27
+
28
+ enum class AnimatedHeaderRatio(val value: Float){
29
+ RATIO_16_9(16f / 9f),
30
+ RATIO_1_1(1f),
31
+ RATIO_3_2(3f / 2f)
32
+ }
33
+
34
+ internal val HEADER_BACKGROUND_HEIGHT = 154.dp
35
+
36
+ // RN DuoScrollGradient: extended gradient runs this far below the header
37
+ private val DUO_GRADIENT_EXTRA = 52.dp
38
+
39
+ @Suppress("FrequentlyChangingValue")
40
+ @Composable
41
+ internal fun HeaderBackground() {
42
+ val density = LocalDensity.current
43
+ val theme = AppTheme.current
44
+ val options = LocalOptions.current
45
+ val scrollState = LocalScrollState.current
46
+ val backgroundColor = options.backgroundColor ?: AppTheme.current.colors.background.default
47
+
48
+ val layout = getScreenLayout()
49
+ val minHeight = layout.headerHeight
50
+ val maxHeight = HEADER_BACKGROUND_HEIGHT
51
+ val opacity by animateFloatAsState(
52
+ targetValue = (1 - (scrollState.value * 1f / HEADER_HEIGHT * 1f)).coerceIn(0f, 1f),
53
+ )
54
+
55
+ val color = if (opacity == 0f) backgroundColor else Color(0xFFFDCADE)
56
+ val height = when (options.headerType) {
57
+ is HeaderType.Default -> minHeight
58
+ is HeaderType.Extended -> {
59
+ if (AppTheme.current.isHeaderImage()){
60
+ if (opacity == 0f) minHeight else maxHeight
61
+ } else {
62
+ maxHeight
63
+ }
64
+ }
65
+ else -> 0.dp
66
+ }
67
+
68
+ // iPhone Duo glass header: the gradient leaves with the content, as the quick return header does
69
+ val useDuoGlass = options.usesDuoGlassHeader(layout)
70
+ // RN HeaderExtendHeader with search on the side bar layout: the gradient fills the header box,
71
+ // which for extended shrinks from 52pt below the header over the first 100pt of scroll
72
+ val duoSearch = layout.sideBar != null && getInputSearchType(options) != InputSearchType.None
73
+ val fillsBox = useDuoGlass || duoSearch
74
+ val duoModifier = when {
75
+ useDuoGlass -> {
76
+ val extra = if (options.headerType is HeaderType.Extended) DUO_GRADIENT_EXTRA else 0.dp
77
+ Modifier.height(minHeight + extra).graphicsLayer { translationY = -scrollState.value.toFloat() }
78
+ }
79
+ duoSearch && options.headerType is HeaderType.Extended -> {
80
+ val progress = (with(density) { scrollState.value.toDp() } / 100.dp).coerceIn(0f, 1f)
81
+ Modifier.height(minHeight + DUO_GRADIENT_EXTRA * (1 - progress))
82
+ }
83
+ duoSearch -> Modifier.height(minHeight)
84
+ else -> Modifier.height(height)
85
+ }
86
+
87
+ Box(Modifier.fillMaxWidth().then(duoModifier).clipToBounds().background(backgroundColor)) {
88
+ // on Duo the fade spans the gradient box; a banner image keeps its 375:154 shape, clipped
89
+ Box(Modifier
90
+ .fillMaxWidth()
91
+ .then(if (fillsBox && !theme.isHeaderImage()) Modifier.fillMaxHeight() else Modifier.height(maxHeight))
92
+ .conditional(!theme.isHeaderImage()) {
93
+ background(Brush.verticalGradient(colors = listOf(color, backgroundColor)))
94
+ }
95
+ ){
96
+ if (!theme.isHeaderImage()) return@Box
97
+ Image(
98
+ source = theme.assets.headerBackground!!,
99
+ modifier = Modifier.fillMaxSize(),
100
+ )
101
+ }
102
+ }
103
+ }
@@ -0,0 +1,106 @@
1
+ package vn.momo.kits.navigation.component
2
+
3
+ import androidx.compose.foundation.layout.Arrangement
4
+ import androidx.compose.foundation.layout.Box
5
+ import androidx.compose.foundation.layout.Column
6
+ import androidx.compose.foundation.layout.Row
7
+ import androidx.compose.foundation.layout.Spacer
8
+ import androidx.compose.foundation.layout.fillMaxWidth
9
+ import androidx.compose.foundation.layout.height
10
+ import androidx.compose.foundation.layout.width
11
+ import androidx.compose.foundation.layout.widthIn
12
+ import androidx.compose.foundation.shape.RoundedCornerShape
13
+ import androidx.compose.runtime.Composable
14
+ import androidx.compose.ui.Alignment
15
+ import androidx.compose.ui.Modifier
16
+ import androidx.compose.ui.draw.clip
17
+ import androidx.compose.ui.graphics.Color
18
+ import androidx.compose.ui.text.style.TextOverflow
19
+ import androidx.compose.ui.unit.dp
20
+ import vn.momo.kits.components.Icon
21
+ import vn.momo.kits.components.Skeleton
22
+ import vn.momo.kits.components.Text
23
+ import vn.momo.kits.const.Spacing
24
+ import vn.momo.kits.const.Typography
25
+ import vn.momo.kits.modifier.activeOpacityClickable
26
+
27
+ @Composable
28
+ internal fun HeaderJourney(
29
+ data: HeaderTitle,
30
+ tintIconColor: Color,
31
+ ) {
32
+ if (data !is HeaderTitle.Journey) return
33
+ if (data.isLoading) return TitleJourneyShimmer()
34
+
35
+ val maxWidth = headerTitleMaxWidth()
36
+ val tint = parseHeaderTint(data.tintColor) ?: tintIconColor
37
+ val iconTint = parseHeaderTint(data.iconColor) ?: tint
38
+
39
+ Column(
40
+ modifier = Modifier
41
+ .widthIn(max = maxWidth)
42
+ .activeOpacityClickable(enabled = data.onPress != null, onClick = { data.onPress?.invoke() }),
43
+ verticalArrangement = Arrangement.Center,
44
+ ) {
45
+ Row(verticalAlignment = Alignment.CenterVertically) {
46
+ Text(
47
+ text = data.start,
48
+ color = tint,
49
+ style = Typography.actionXsBold,
50
+ maxLines = 1,
51
+ overflow = TextOverflow.Ellipsis,
52
+ modifier = Modifier.weight(1f, fill = false),
53
+ )
54
+ Spacer(Modifier.width(Spacing.S))
55
+ if (data.icon.isNotBlank()) {
56
+ Icon(source = data.icon, size = 16.dp, color = iconTint)
57
+ } else {
58
+ Spacer(Modifier.width(16.dp))
59
+ }
60
+ Spacer(Modifier.width(Spacing.S))
61
+ if (!data.end.isNullOrEmpty()) {
62
+ Text(
63
+ text = data.end,
64
+ color = tint,
65
+ style = Typography.actionXsBold,
66
+ maxLines = 1,
67
+ overflow = TextOverflow.Ellipsis,
68
+ modifier = Modifier.weight(1f, fill = false),
69
+ )
70
+ }
71
+ Spacer(Modifier.width(Spacing.XS))
72
+ Icon(source = "16_arrow_chevron_down_small", size = 16.dp, color = tint)
73
+ }
74
+ if (!data.description.isNullOrEmpty()) {
75
+ Text(
76
+ text = data.description,
77
+ color = tint,
78
+ style = Typography.descriptionXsRegular,
79
+ maxLines = 1,
80
+ overflow = TextOverflow.Ellipsis,
81
+ )
82
+ }
83
+ }
84
+ }
85
+
86
+ @Composable
87
+ private fun TitleJourneyShimmer() {
88
+ Column(modifier = Modifier.fillMaxWidth()) {
89
+ Box(modifier = Modifier.height(18.dp).width(120.dp).clip(RoundedCornerShape(8.dp))) { Skeleton() }
90
+ Spacer(Modifier.height(Spacing.XXS))
91
+ Box(modifier = Modifier.height(12.dp).width(120.dp).clip(RoundedCornerShape(8.dp))) { Skeleton() }
92
+ }
93
+ }
94
+
95
+ internal fun parseHeaderTint(value: String?): Color? {
96
+ val raw = value?.trim()?.removePrefix("#") ?: return null
97
+ val hex = when (raw.length) {
98
+ 3 -> "FF" + raw.map { "$it$it" }.joinToString("")
99
+ 6 -> "FF$raw"
100
+ // CSS #RRGGBBAA, as RN passes it; Compose wants AARRGGBB
101
+ 8 -> raw.substring(6) + raw.substring(0, 6)
102
+ else -> return null
103
+ }
104
+ val v = hex.toLongOrNull(16) ?: return null
105
+ return Color(v)
106
+ }
@@ -0,0 +1,74 @@
1
+ package vn.momo.kits.navigation.component
2
+
3
+ import androidx.compose.foundation.layout.Box
4
+ import androidx.compose.foundation.layout.Column
5
+ import androidx.compose.foundation.layout.Row
6
+ import androidx.compose.foundation.layout.Spacer
7
+ import androidx.compose.foundation.layout.fillMaxWidth
8
+ import androidx.compose.foundation.layout.height
9
+ import androidx.compose.foundation.layout.width
10
+ import androidx.compose.foundation.layout.widthIn
11
+ import androidx.compose.foundation.shape.RoundedCornerShape
12
+ import androidx.compose.runtime.Composable
13
+ import androidx.compose.ui.Alignment
14
+ import androidx.compose.ui.Modifier
15
+ import androidx.compose.ui.draw.clip
16
+ import androidx.compose.ui.graphics.Color
17
+ import androidx.compose.ui.text.style.TextOverflow
18
+ import androidx.compose.ui.unit.dp
19
+ import vn.momo.kits.components.Icon
20
+ import vn.momo.kits.components.Skeleton
21
+ import vn.momo.kits.components.Text
22
+ import vn.momo.kits.const.Spacing
23
+ import vn.momo.kits.const.Typography
24
+ import vn.momo.kits.modifier.activeOpacityClickable
25
+
26
+ @Composable
27
+ internal fun HeaderLocation(
28
+ data: HeaderTitle,
29
+ tintIconColor: Color,
30
+ ) {
31
+ if (data !is HeaderTitle.Location) return
32
+ if (data.isLoading) return TitleLocationShimmer()
33
+
34
+ val maxWidth = headerTitleMaxWidth()
35
+ val tint = parseHeaderTint(data.tintColor) ?: tintIconColor
36
+
37
+ Column(
38
+ modifier = Modifier
39
+ .widthIn(max = maxWidth)
40
+ .activeOpacityClickable(enabled = data.onPress != null, onClick = { data.onPress?.invoke() }),
41
+ horizontalAlignment = Alignment.Start,
42
+ ) {
43
+ if (!data.description.isNullOrEmpty()) {
44
+ Text(
45
+ text = data.description,
46
+ color = tint,
47
+ style = Typography.descriptionXsRegular,
48
+ maxLines = 1,
49
+ overflow = TextOverflow.Ellipsis,
50
+ )
51
+ }
52
+ Row(verticalAlignment = Alignment.CenterVertically) {
53
+ Text(
54
+ text = data.location,
55
+ color = tint,
56
+ style = Typography.actionXsBold,
57
+ maxLines = 1,
58
+ overflow = TextOverflow.Ellipsis,
59
+ modifier = Modifier.weight(1f, fill = false),
60
+ )
61
+ Spacer(Modifier.width(Spacing.XS))
62
+ Icon(source = "16_arrow_chevron_down_small", size = 16.dp, color = tint)
63
+ }
64
+ }
65
+ }
66
+
67
+ @Composable
68
+ private fun TitleLocationShimmer() {
69
+ Column(modifier = Modifier.fillMaxWidth()) {
70
+ Box(modifier = Modifier.height(12.dp).width(120.dp).clip(RoundedCornerShape(8.dp))) { Skeleton() }
71
+ Spacer(Modifier.height(Spacing.XXS))
72
+ Box(modifier = Modifier.height(18.dp).width(120.dp).clip(RoundedCornerShape(8.dp))) { Skeleton() }
73
+ }
74
+ }
@@ -0,0 +1,399 @@
1
+ package vn.momo.kits.navigation.component
2
+
3
+ import vn.momo.kits.modifier.InternalApi
4
+
5
+ import androidx.compose.foundation.background
6
+ import androidx.compose.foundation.border
7
+ import androidx.compose.foundation.layout.Arrangement
8
+ import androidx.compose.foundation.layout.Box
9
+ import androidx.compose.foundation.layout.Column
10
+ import androidx.compose.foundation.layout.Row
11
+ import androidx.compose.foundation.layout.height
12
+ import androidx.compose.foundation.layout.offset
13
+ import androidx.compose.foundation.layout.padding
14
+ import androidx.compose.foundation.layout.size
15
+ import androidx.compose.foundation.layout.width
16
+ import androidx.compose.foundation.shape.CircleShape
17
+ import androidx.compose.foundation.shape.RoundedCornerShape
18
+ import androidx.compose.runtime.Composable
19
+ import androidx.compose.runtime.LaunchedEffect
20
+ import androidx.compose.runtime.derivedStateOf
21
+ import androidx.compose.runtime.getValue
22
+ import androidx.compose.runtime.mutableStateOf
23
+ import androidx.compose.runtime.remember
24
+ import androidx.compose.runtime.setValue
25
+ import androidx.compose.ui.Alignment
26
+ import androidx.compose.ui.Modifier
27
+ import androidx.compose.ui.draw.clip
28
+ import androidx.compose.ui.graphics.Color
29
+ import androidx.compose.ui.unit.Dp
30
+ import androidx.compose.ui.unit.dp
31
+ import vn.momo.kits.layout.DuoMetrics
32
+ import vn.momo.kits.application.LocalContext
33
+ import vn.momo.kits.application.MiniAppContext
34
+ import vn.momo.kits.components.BadgeDot
35
+ import vn.momo.kits.components.DotSize
36
+ import vn.momo.kits.components.Icon
37
+ import vn.momo.kits.const.Colors
38
+ import vn.momo.kits.const.Spacing
39
+ import vn.momo.kits.modifier.activeOpacityClickable
40
+ import vn.momo.kits.navigation.LocalMaxApi
41
+
42
+ @Composable
43
+ @InternalApi
44
+ fun HeaderRight(
45
+ headerRight: HeaderRight,
46
+ tintColor: Color? = null,
47
+ headerColor: HeaderColor
48
+ ) {
49
+ when (headerRight) {
50
+ is HeaderRight.None -> {}
51
+ is HeaderRight.Custom -> {
52
+ headerRight.content()
53
+ }
54
+ is HeaderRight.OnBoarding -> {}
55
+ is HeaderRight.Toolkit -> {
56
+ Toolkit(
57
+ headerRight = headerRight,
58
+ tintColor = tintColor,
59
+ headerColor = headerColor
60
+ )
61
+ }
62
+ }
63
+ }
64
+
65
+ private const val HELP_CENTER_APP_ID = "vn.momo.helpcenter"
66
+
67
+ private fun usesHelpCenter(context: MiniAppContext?): Boolean =
68
+ context != null && context.appId != HELP_CENTER_APP_ID
69
+
70
+ private fun showsShortcut(headerRight: HeaderRight.Toolkit, context: MiniAppContext?): Boolean =
71
+ headerRight.useShortcut && !(headerRight.useMore && context == null)
72
+
73
+ // Height of the vertical toolkit: the optional shortcut, then the help/home capsule.
74
+ @Composable
75
+ internal fun toolkitColumnHeight(headerRight: HeaderRight.Toolkit): Dp {
76
+ val context = LocalContext.current
77
+ val shortcut = if (showsShortcut(headerRight, context)) DuoMetrics.controlSize + Spacing.M else 0.dp
78
+ val groupCount = if (usesHelpCenter(context)) 2 else 1
79
+ return shortcut + if (groupCount > 1) DuoMetrics.itemPitch * groupCount else DuoMetrics.controlSize
80
+ }
81
+
82
+ // SideBarColumn: the iPhone Duo side bar; SideBarRow: the Duo header row on the status bar, same 48pt controls.
83
+ internal enum class ToolkitLayout { Bar, SideBarColumn, SideBarRow }
84
+
85
+ @Composable
86
+ internal fun Toolkit(
87
+ headerRight: HeaderRight.Toolkit,
88
+ tintColor: Color? = null,
89
+ headerColor: HeaderColor,
90
+ layout: ToolkitLayout = ToolkitLayout.Bar,
91
+ ) {
92
+ val api = LocalMaxApi.current
93
+ val context = LocalContext.current
94
+
95
+ var isFavorite by remember { mutableStateOf(false) }
96
+ val isLoading by remember { mutableStateOf(false) }
97
+
98
+ LaunchedEffect(context?.appCode) {
99
+ api?.isFavoriteApp(mapOf("code" to context?.appCode)) { callback ->
100
+ val response = callback?.get("response") as? Boolean
101
+ isFavorite = response == true
102
+ }
103
+ }
104
+
105
+ fun onPressShortcut() {
106
+ api?.onToolAction(mapOf("item" to mapOf("key" to "onFavorite"), "context" to MiniAppContext.toMap(context))) { callback ->
107
+ val response = callback?.get("response") as? Map<*, *>?
108
+ val success = response?.get("success") as? Boolean
109
+ if (success == true){
110
+ isFavorite = !isFavorite
111
+ }
112
+ }
113
+ }
114
+
115
+ fun onPressMore() {
116
+ api?.showTools(
117
+ mapOf(
118
+ "useSystemTools" to headerRight.useSystemTools,
119
+ "tools" to headerRight.tools.map { it.toMap() },
120
+ "context" to MiniAppContext.toMap(context)
121
+ )
122
+ ) { callback ->
123
+ val response = callback?.get("response") as? String
124
+ if (response != null) {
125
+ headerRight.toolCallback?.invoke(response)
126
+ }
127
+ }
128
+ }
129
+
130
+ fun onPressHelpCenter() {
131
+ if (context == null) return
132
+ api?.showHelpCenter(
133
+ mapOf(
134
+ "appId" to context.appId,
135
+ "code" to context.appCode,
136
+ "name" to context.appName,
137
+ "icon" to context.appIcon,
138
+ "description" to context.description
139
+ )
140
+ ) {}
141
+ }
142
+
143
+ fun onPressClose() {
144
+ if (headerRight.useCloseIcon) api?.dismiss { } else api?.dismissAll { }
145
+ }
146
+
147
+ val useHelpCenter = usesHelpCenter(context)
148
+ val closeIcon = if (headerRight.useCloseIcon) "16_navigation_close_circle" else "16_basic_home"
149
+
150
+ val navButtonConfig = getNavigationButtonConfig(
151
+ headerRight,
152
+ ::onPressShortcut,
153
+ ::onPressMore
154
+ )
155
+
156
+ val showBadge = headerRight.tools.any { group ->
157
+ group.items.any { it.showBadge }
158
+ }
159
+
160
+ val isShowShortcut = showsShortcut(headerRight, context)
161
+
162
+ val icon by remember(navButtonConfig.icon, isFavorite) {
163
+ derivedStateOf {
164
+ navButtonConfig.icon.takeUnless { it == "star" }
165
+ ?: if (isFavorite) "pin_star_checked" else "pin_star"
166
+ }
167
+ }
168
+
169
+ if (layout != ToolkitLayout.Bar) {
170
+ val horizontal = layout == ToolkitLayout.SideBarRow
171
+ val controls = @Composable {
172
+ if (isShowShortcut) {
173
+ SideBarButton(
174
+ icon = icon,
175
+ headerColor = headerColor,
176
+ enabled = !isLoading,
177
+ showBadge = showBadge,
178
+ onClick = navButtonConfig.onPress,
179
+ )
180
+ }
181
+ SideBarGroup(headerColor = headerColor, itemCount = if (useHelpCenter) 2 else 1, horizontal = horizontal) { item ->
182
+ if (useHelpCenter) {
183
+ SideBarGroupItem(
184
+ icon = "help_center",
185
+ headerColor = headerColor,
186
+ automationId = "btn_navigation_help_center",
187
+ onClick = ::onPressHelpCenter,
188
+ modifier = item,
189
+ )
190
+ }
191
+ SideBarGroupItem(
192
+ icon = closeIcon,
193
+ headerColor = headerColor,
194
+ automationId = "btn_navigation_close",
195
+ onClick = ::onPressClose,
196
+ modifier = item,
197
+ )
198
+ }
199
+ }
200
+ if (horizontal) {
201
+ Row(horizontalArrangement = Arrangement.spacedBy(Spacing.M), verticalAlignment = Alignment.CenterVertically) {
202
+ controls()
203
+ }
204
+ } else {
205
+ Column(verticalArrangement = Arrangement.spacedBy(Spacing.M)) { controls() }
206
+ }
207
+ return
208
+ }
209
+
210
+ Row(
211
+ verticalAlignment = Alignment.CenterVertically
212
+ ) {
213
+ if (isShowShortcut) {
214
+ NavigationButton(
215
+ disabled = isLoading,
216
+ icon = icon,
217
+ showBadge = showBadge,
218
+ onClick = navButtonConfig.onPress,
219
+ headerColor = headerColor
220
+ )
221
+ }
222
+
223
+ Row(
224
+ verticalAlignment = Alignment.CenterVertically,
225
+ horizontalArrangement = Arrangement.Center,
226
+ modifier = Modifier
227
+ .padding(start = Spacing.S)
228
+ .border(0.2.dp, headerColor.borderColor, shape = RoundedCornerShape(14.dp))
229
+ .height(28.dp)
230
+ .clip(shape = RoundedCornerShape(14.dp))
231
+ .background(headerColor.backgroundButton)
232
+ ) {
233
+ if (useHelpCenter) {
234
+ Icon(
235
+ source = "help_center",
236
+ size = 20.dp,
237
+ color = headerColor.tintIconColor,
238
+ modifier = Modifier.padding(4.dp).activeOpacityClickable(onClick = ::onPressHelpCenter)
239
+ )
240
+ Box(
241
+ modifier = Modifier
242
+ .width(0.5.dp)
243
+ .height(12.dp)
244
+ .background(tintColor ?: Colors.black_20)
245
+ )
246
+ }
247
+ Icon(
248
+ source = closeIcon,
249
+ size = 20.dp,
250
+ color = headerColor.tintIconColor,
251
+ modifier = Modifier.padding(4.dp).activeOpacityClickable(onClick = ::onPressClose)
252
+ )
253
+ }
254
+ }
255
+ }
256
+
257
+
258
+
259
+ // Colors follow the enclosing header, so it fits a `HeaderRight.Custom` next to the toolkit.
260
+ @Composable
261
+ fun NavigationButton(
262
+ icon: String,
263
+ onClick: () -> Unit,
264
+ showBadge: Boolean = false,
265
+ disabled: Boolean = false,
266
+ modifier: Modifier = Modifier,
267
+ ) {
268
+ NavigationButton(
269
+ disabled = disabled,
270
+ icon = icon,
271
+ showBadge = showBadge,
272
+ onClick = onClick,
273
+ headerColor = LocalHeaderColor.current ?: getHeaderColor(HeaderType.Default(), 1f, null, Colors.black_17),
274
+ modifier = modifier,
275
+ )
276
+ }
277
+
278
+ @Composable
279
+ internal fun NavigationButton(
280
+ disabled: Boolean,
281
+ icon: String,
282
+ showBadge: Boolean? = false,
283
+ onClick: () -> Unit,
284
+ headerColor: HeaderColor,
285
+ modifier: Modifier = Modifier,
286
+ ) {
287
+ Box(
288
+ modifier = modifier
289
+ .size(28.dp)
290
+ .activeOpacityClickable(enabled = !disabled, onClick = onClick)
291
+ ) {
292
+ Box(
293
+ modifier = Modifier
294
+ .matchParentSize()
295
+ .clip(CircleShape)
296
+ .background(headerColor.backgroundButton)
297
+ .border(0.2.dp, headerColor.borderColor, CircleShape)
298
+ )
299
+ Box(
300
+ modifier = Modifier.matchParentSize(),
301
+ contentAlignment = Alignment.Center
302
+ ) {
303
+ Icon(
304
+ source = icon,
305
+ size = 20.dp,
306
+ color = headerColor.tintIconColor
307
+ )
308
+ }
309
+
310
+ if (showBadge == true) {
311
+ BadgeDot(
312
+ size = DotSize.Small,
313
+ modifier = Modifier
314
+ .align(Alignment.TopEnd)
315
+ .offset(x = -Spacing.XXS, y = -Spacing.XXS)
316
+ )
317
+ }
318
+ }
319
+ }
320
+
321
+ private fun getNavigationButtonConfig(
322
+ headerRight: HeaderRight.Toolkit,
323
+ onPressShortcut: () -> Unit,
324
+ onPressMore: () -> Unit
325
+ ): NavigationButtonConfig {
326
+ val totalTools = headerRight.tools.sumOf { it.items.size }
327
+ val config = NavigationButtonConfig(icon = "star", onPress = onPressShortcut)
328
+ return if (totalTools > 1 || headerRight.useMore == true) {
329
+ NavigationButtonConfig(
330
+ icon = "navigation_more_icon",
331
+ onPress = onPressMore
332
+ )
333
+ } else if (totalTools == 1 && headerRight.tools.isNotEmpty()) {
334
+ val singleTool = headerRight.tools.first().items.firstOrNull()
335
+ return if (singleTool != null){
336
+ NavigationButtonConfig(
337
+ icon = singleTool.icon,
338
+ onPress = {
339
+ headerRight.toolCallback?.invoke(singleTool.key)
340
+ }
341
+ )
342
+ } else {
343
+ config
344
+ }
345
+ } else {
346
+ config
347
+ }
348
+ }
349
+
350
+ sealed interface HeaderRight {
351
+ data object None : HeaderRight
352
+ data class Custom(
353
+ val content: @Composable () -> Unit
354
+ ) : HeaderRight
355
+ data object OnBoarding : HeaderRight
356
+ data class Toolkit(
357
+ val useShortcut: Boolean = false,
358
+ val useMore: Boolean = false,
359
+ val useSystemTools: Boolean = true,
360
+ val tools: List<ToolGroup> = emptyList(),
361
+ val toolCallback: ((String) -> Unit)? = { _ -> },
362
+ // Close dismisses only this mini app instead of returning home.
363
+ val useCloseIcon: Boolean = false,
364
+ ) : HeaderRight
365
+ }
366
+
367
+ data class ToolGroup(
368
+ val title: Map<String, String> = emptyMap(),
369
+ val items: List<Tool>
370
+ ) {
371
+ fun toMap(): Map<String, Any> {
372
+ return mapOf(
373
+ "title" to title,
374
+ "items" to items.map { it.toMap() }
375
+ )
376
+ }
377
+ }
378
+ data class Tool(
379
+ val key: String,
380
+ val icon: String,
381
+ val showBadge: Boolean = false,
382
+ val name: Map<String, String> = emptyMap(),
383
+ val showRightIcon: Boolean = true,
384
+ ) {
385
+ fun toMap(): Map<String, Any> {
386
+ return mapOf(
387
+ "key" to key,
388
+ "icon" to icon,
389
+ "showBadge" to showBadge,
390
+ "name" to name,
391
+ "showRightIcon" to showRightIcon
392
+ )
393
+ }
394
+ }
395
+
396
+ private data class NavigationButtonConfig(
397
+ val icon: String,
398
+ val onPress: () -> Unit
399
+ )