@momo-kits/native-kits 0.169.8-beta.4 → 0.169.8-beta.4-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 +63 -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 +748 -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 +391 -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 +466 -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 +406 -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 +204 -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,466 @@
1
+ package vn.momo.kits.navigation.component
2
+
3
+ import vn.momo.kits.modifier.InternalApi
4
+
5
+ import androidx.compose.animation.core.animateFloatAsState
6
+ import androidx.compose.foundation.background
7
+ import androidx.compose.foundation.border
8
+ import androidx.compose.foundation.layout.Arrangement
9
+ import androidx.compose.foundation.layout.Box
10
+ import androidx.compose.foundation.layout.Row
11
+ import androidx.compose.foundation.layout.Spacer
12
+ import androidx.compose.foundation.layout.fillMaxWidth
13
+ import androidx.compose.foundation.layout.height
14
+ import androidx.compose.foundation.layout.offset
15
+ import androidx.compose.foundation.layout.padding
16
+ import androidx.compose.foundation.layout.size
17
+ import androidx.compose.foundation.layout.width
18
+ import androidx.compose.foundation.layout.wrapContentHeight
19
+ import androidx.compose.foundation.shape.RoundedCornerShape
20
+ import androidx.compose.runtime.Composable
21
+ import androidx.compose.runtime.CompositionLocalProvider
22
+ import androidx.compose.runtime.compositionLocalOf
23
+ import androidx.compose.runtime.getValue
24
+ import androidx.compose.ui.Alignment
25
+ import androidx.compose.ui.Modifier
26
+ import androidx.compose.ui.draw.clipToBounds
27
+ import androidx.compose.ui.draw.drawBehind
28
+ import androidx.compose.ui.geometry.Offset
29
+ import androidx.compose.ui.graphics.graphicsLayer
30
+ import androidx.compose.ui.graphics.Brush
31
+ import androidx.compose.ui.graphics.Color
32
+ import androidx.compose.ui.layout.onGloballyPositioned
33
+ import androidx.compose.ui.platform.LocalDensity
34
+ import androidx.compose.ui.text.style.TextAlign
35
+ import androidx.compose.ui.unit.Dp
36
+ import androidx.compose.ui.unit.dp
37
+ import vn.momo.kits.components.Icon
38
+ import vn.momo.kits.components.Image
39
+ import vn.momo.kits.components.InputSearchProps
40
+ import vn.momo.kits.const.AppTheme
41
+ import vn.momo.kits.const.Colors
42
+ import vn.momo.kits.components.PopupNotifyProps
43
+ import vn.momo.kits.application.IsShowBaseLineDebug
44
+ import vn.momo.kits.const.Spacing
45
+ import vn.momo.kits.layout.DuoMetrics
46
+ import vn.momo.kits.layout.HEADER_BUTTON_SIZE
47
+ import vn.momo.kits.layout.HEADER_CLUSTER_WIDTH
48
+ import vn.momo.kits.layout.HEADER_ICON_SIZE
49
+ import vn.momo.kits.layout.HEADER_TITLE_GAP
50
+ import vn.momo.kits.layout.getScreenLayout
51
+ import vn.momo.kits.layout.rememberHeaderLayout
52
+ import vn.momo.kits.modifier.activeOpacityClickable
53
+ import vn.momo.kits.modifier.conditional
54
+ import vn.momo.kits.modifier.setAutomationId
55
+ import vn.momo.kits.navigation.LocalHeaderRightWidthPx
56
+ import vn.momo.kits.navigation.LocalNavigator
57
+ import vn.momo.kits.navigation.LocalOptions
58
+ import vn.momo.kits.navigation.LocalScrollState
59
+ import vn.momo.kits.navigation.getInputSearchType
60
+ import vn.momo.kits.navigation.usesDuoGlassHeader
61
+ import vn.momo.kits.utils.horizontalSafeAreaPadding
62
+
63
+ @InternalApi
64
+ const val HEADER_HEIGHT = 52
65
+ internal enum class InputSearchType { None, Header, Animated }
66
+ enum class TitlePosition { LEFT, CENTER }
67
+
68
+ // back, the gaps around the title and the right cluster
69
+ private val HEADER_ACTIONS_WIDTH = HEADER_BUTTON_SIZE + HEADER_TITLE_GAP * 2 + HEADER_CLUSTER_WIDTH
70
+
71
+ // Side padding, 48pt back and toolkit on the iPhone Duo status bar row.
72
+ private val STATUS_BAR_ROW_ACTIONS_WIDTH = 227.dp
73
+
74
+ @Suppress("FrequentlyChangingValue")
75
+ @Composable
76
+ internal fun headerOpacity(): Float {
77
+ val options = LocalOptions.current
78
+ val scrollState = LocalScrollState.current
79
+ val opacityHeight = when (val header = options.headerType) {
80
+ is HeaderType.Animated -> with(LocalDensity.current) { header.layoutOffSet.roundToPx() }
81
+ else -> HEADER_HEIGHT
82
+ }
83
+ val opacity by animateFloatAsState(
84
+ targetValue = when {
85
+ options.headerType is HeaderType.Transparent -> 0f
86
+ opacityHeight <= 0 -> if (scrollState.value > 0) 1f else 0f
87
+ else -> (scrollState.value / opacityHeight.toFloat()).coerceIn(0f, 1f)
88
+ }
89
+ )
90
+ return opacity
91
+ }
92
+
93
+ // Back button and toolkit share the bar with the title unless the iPhone Duo side bar holds them.
94
+ @Composable
95
+ internal fun headerTitleMaxWidth(): Dp {
96
+ val layout = getScreenLayout()
97
+ val clearance = layout.statusBarClearance
98
+ val clearanceWidth = clearance?.let { it.left + it.right } ?: 0.dp
99
+ if (layout.sideBar != null) return layout.contentWidth - Spacing.M * 2 - clearanceWidth
100
+ if (clearance != null) return layout.width - STATUS_BAR_ROW_ACTIONS_WIDTH - clearanceWidth
101
+ return rememberHeaderLayout(LocalOptions.current.contentLayout).frameWidth - HEADER_ACTIONS_WIDTH
102
+ }
103
+
104
+ // Scroll distance over which the Duo glass bar fades in.
105
+ private val DUO_GLASS_FADE_DISTANCE = 16.dp
106
+
107
+ // RN DuoGlassBackground: translucent surface with a hairline once content scrolls under it.
108
+ @Suppress("FrequentlyChangingValue")
109
+ @Composable
110
+ private fun Modifier.duoGlassBar(): Modifier {
111
+ val scrollState = LocalScrollState.current
112
+ val fadePx = with(LocalDensity.current) { DUO_GLASS_FADE_DISTANCE.toPx() }
113
+ val alpha by animateFloatAsState((scrollState.value / fadePx).coerceIn(0f, 1f), label = "DuoGlassAlpha")
114
+ val colors = AppTheme.current.colors
115
+ return background(colors.background.surface.copy(alpha = 0.8f * alpha))
116
+ .drawBehind {
117
+ val stroke = 0.5.dp.toPx()
118
+ drawLine(
119
+ color = colors.border.default.copy(alpha = alpha),
120
+ start = Offset(0f, size.height - stroke / 2),
121
+ end = Offset(size.width, size.height - stroke / 2),
122
+ strokeWidth = stroke,
123
+ )
124
+ }
125
+ }
126
+
127
+ @Composable
128
+ internal fun Header(onBackHandler: (() -> Unit)? = null) {
129
+ val options = LocalOptions.current
130
+ val navigator = LocalNavigator.current
131
+ val headerRightWidthPx = LocalHeaderRightWidthPx.current
132
+ val inputSearchType = getInputSearchType(options)
133
+ val layout = getScreenLayout()
134
+ val headerLayout = rememberHeaderLayout(options.contentLayout)
135
+ val useSideBar = layout.sideBar != null
136
+ // iPhone Duo inner portrait: the row sits on the status bar, between its clusters
137
+ val clearance = layout.statusBarClearance
138
+ val statusBarRow = clearance != null && !useSideBar
139
+ val opacity = headerOpacity()
140
+
141
+ val headerColor = getHeaderColor(options.headerType, opacity, options.tintColor, Colors.black_17)
142
+
143
+ val animatedAlpha by animateFloatAsState(targetValue = opacity, label = "BackgroundAlpha")
144
+
145
+ val background = if (options.headerType is HeaderType.Transparent)
146
+ options.backgroundColor ?: AppTheme.current.colors.background.surface
147
+ else
148
+ AppTheme.current.colors.background.surface
149
+
150
+ if (options.headerType == HeaderType.None) return
151
+
152
+ val titlePosition = options.titlePosition
153
+ val titleColor = headerColor.tintIconColor
154
+ .copy(alpha = if (inputSearchType == InputSearchType.Animated) 1f - animatedAlpha else 1f)
155
+ // Centered title needs a full-width overlay to stay screen-centered, not boxed between back button and header right.
156
+ val centerTitle = titlePosition == TitlePosition.CENTER && options.headerTitle is HeaderTitle.Default
157
+
158
+ val useDuoGlass = options.usesDuoGlassHeader(layout)
159
+ val headerImage = AppTheme.current.assets.headerBackground
160
+ .takeUnless { options.headerType is HeaderType.Transparent || useDuoGlass }
161
+
162
+ Box(
163
+ Modifier.height(layout.headerHeight)
164
+ .fillMaxWidth()
165
+ .then(if (useDuoGlass) Modifier.duoGlassBar() else Modifier)
166
+ .conditional(headerImage.isNullOrEmpty() && !useDuoGlass) {
167
+ background(background.copy(alpha = animatedAlpha))
168
+ }
169
+ .conditional(IsShowBaseLineDebug) {
170
+ border(1.dp, Colors.blue_03)
171
+ },
172
+ contentAlignment = Alignment.BottomCenter
173
+ ) {
174
+ if (!headerImage.isNullOrEmpty()) {
175
+ Box(
176
+ Modifier
177
+ .matchParentSize()
178
+ .clipToBounds()
179
+ .graphicsLayer { alpha = animatedAlpha }
180
+ .background(background)
181
+ ) {
182
+ Image(
183
+ source = headerImage,
184
+ loading = false,
185
+ modifier = Modifier
186
+ .fillMaxWidth()
187
+ .wrapContentHeight(Alignment.Top, unbounded = true)
188
+ .height(HEADER_BACKGROUND_HEIGHT),
189
+ )
190
+ }
191
+ }
192
+ Row(
193
+ modifier = Modifier.height(layout.headerBarHeight)
194
+ .fillMaxWidth()
195
+ .horizontalSafeAreaPadding()
196
+ .padding(
197
+ start = headerLayout.frameInset + (clearance?.left ?: 0.dp),
198
+ end = headerLayout.frameInset + (clearance?.right ?: 0.dp),
199
+ ),
200
+ verticalAlignment = Alignment.CenterVertically,
201
+ horizontalArrangement = Arrangement.SpaceBetween
202
+ ) {
203
+ if (!options.hiddenBack && !useSideBar) {
204
+ if (statusBarRow) {
205
+ SideBarButton(
206
+ icon = "arrow-back",
207
+ headerColor = headerColor,
208
+ automationId = "btn_navigation_back",
209
+ onClick = { navigator.onBackSafe { } },
210
+ )
211
+ } else {
212
+ BackButton(
213
+ borderColor = headerColor.borderColor,
214
+ backgroundButton = headerColor.backgroundButton,
215
+ tintIconColor = headerColor.tintIconColor,
216
+ onBackHandler = {
217
+ navigator.onBackSafe { }
218
+ }
219
+ )
220
+ }
221
+ Spacer(Modifier.width(HEADER_TITLE_GAP))
222
+ }
223
+
224
+ if (centerTitle) {
225
+ Spacer(Modifier.weight(1f))
226
+ } else {
227
+ HeaderContent(
228
+ headerTitle = options.headerTitle,
229
+ tintIconColor = titleColor,
230
+ titlePosition = titlePosition,
231
+ modifier = Modifier.weight(1f)
232
+ )
233
+ }
234
+ Box(Modifier.onGloballyPositioned {
235
+ if(headerRightWidthPx.intValue != it.size.width) headerRightWidthPx.intValue = it.size.width
236
+ }){
237
+ val headerRight = options.headerRight
238
+ when {
239
+ // on Duo the side bar column holds the header right (toolkit or custom), not this row
240
+ useSideBar -> Unit
241
+ statusBarRow && headerRight is HeaderRight.Toolkit -> Toolkit(
242
+ headerRight = headerRight,
243
+ tintColor = options.tintColor,
244
+ headerColor = headerColor,
245
+ layout = ToolkitLayout.SideBarRow,
246
+ )
247
+ else -> CompositionLocalProvider(LocalHeaderColor provides headerColor) {
248
+ HeaderRight(headerRight, options.tintColor, headerColor)
249
+ }
250
+ }
251
+ }
252
+ }
253
+ if (centerTitle) {
254
+ // on the status bar row the clusters are lopsided, so both sides keep the wider one's room
255
+ val centerInset = if (clearance != null) {
256
+ val back = if (options.hiddenBack || useSideBar) 0.dp else DuoMetrics.controlSize + Spacing.S
257
+ val right = with(LocalDensity.current) { headerRightWidthPx.intValue.toDp() }
258
+ maxOf(clearance.left + back, clearance.right + right) + Spacing.S
259
+ } else {
260
+ 0.dp
261
+ }
262
+ Box(
263
+ modifier = Modifier.height(layout.headerBarHeight)
264
+ .fillMaxWidth()
265
+ .horizontalSafeAreaPadding()
266
+ .padding(horizontal = headerLayout.frameInset + centerInset),
267
+ contentAlignment = Alignment.Center
268
+ ) {
269
+ HeaderContent(
270
+ headerTitle = options.headerTitle,
271
+ tintIconColor = titleColor,
272
+ titlePosition = titlePosition,
273
+ centerWidthFraction = if (clearance != null) 1f else 0.5f,
274
+ modifier = Modifier.fillMaxWidth()
275
+ )
276
+ }
277
+ }
278
+ VerticalShadow(opacity)
279
+ }
280
+ }
281
+
282
+ @Composable
283
+ private fun BackButton(borderColor: Color, backgroundButton: Color, tintIconColor: Color, onBackHandler: () -> Unit){
284
+ Box(
285
+ modifier = Modifier
286
+ .size(HEADER_BUTTON_SIZE)
287
+ .background(backgroundButton, RoundedCornerShape(100))
288
+ .border(width = 0.2.dp, color = borderColor, shape = RoundedCornerShape(100))
289
+ .activeOpacityClickable(onClick = onBackHandler)
290
+ .padding(Spacing.XS)
291
+ .setAutomationId("btn_navigation_back"),
292
+ contentAlignment = Alignment.Center
293
+ ) {
294
+ Icon(
295
+ source = "arrow-back",
296
+ color = tintIconColor,
297
+ size = HEADER_ICON_SIZE,
298
+ )
299
+ }
300
+ }
301
+
302
+ @Composable
303
+ internal fun HeaderContent(
304
+ headerTitle: HeaderTitle,
305
+ tintIconColor: Color,
306
+ titlePosition: TitlePosition = TitlePosition.LEFT,
307
+ centerWidthFraction: Float = 0.5f,
308
+ modifier: Modifier = Modifier,
309
+ ){
310
+ Box(
311
+ modifier = modifier,
312
+ contentAlignment = if (titlePosition == TitlePosition.CENTER) Alignment.Center else Alignment.CenterStart
313
+ ) {
314
+ when (headerTitle){
315
+ is HeaderTitle.Default -> {
316
+ HeaderTitle(
317
+ title = headerTitle.title,
318
+ color = tintIconColor,
319
+ modifier = Modifier.fillMaxWidth(fraction = if (titlePosition == TitlePosition.CENTER) centerWidthFraction else 1f),
320
+ textAlign = if (titlePosition == TitlePosition.CENTER) TextAlign.Center else TextAlign.Start
321
+ )
322
+ }
323
+ is HeaderTitle.Journey -> {
324
+ HeaderJourney(
325
+ data = headerTitle,
326
+ tintIconColor = tintIconColor
327
+ )
328
+ }
329
+ is HeaderTitle.Location -> {
330
+ HeaderLocation(
331
+ data = headerTitle,
332
+ tintIconColor = tintIconColor
333
+ )
334
+ }
335
+ is HeaderTitle.User -> {
336
+ HeaderUser(
337
+ data = headerTitle
338
+ )
339
+ }
340
+ }
341
+ }
342
+ }
343
+
344
+ @Composable
345
+ internal fun VerticalShadow(opacity: Float){
346
+ if(opacity == 1f){
347
+ Box(modifier = Modifier
348
+ .fillMaxWidth()
349
+ .height(6.dp)
350
+ .offset(x = 0.dp, y = 6.dp)
351
+ .background(
352
+ brush = Brush.verticalGradient(
353
+ colors = listOf(Color.Black.copy(alpha = 0.05f), Color.Transparent)
354
+ )
355
+ )
356
+ )
357
+ }
358
+ }
359
+
360
+ sealed class HeaderTitle {
361
+ class Default(val title: String) : HeaderTitle()
362
+
363
+ class User(
364
+ val title: String,
365
+ val subTitle: String? = null,
366
+ val image: List<String>? = null,
367
+ val dotColor: Color? = null,
368
+ val tintColor: Color? = null,
369
+ val onPress: (() -> Unit)? = null,
370
+ val icons: List<String> = emptyList(),
371
+ val isLoading: Boolean = false
372
+ ) : HeaderTitle()
373
+
374
+ class Location(
375
+ val description: String? = null,
376
+ val location: String,
377
+ val tintColor: String? = null,
378
+ val onPress: (() -> Unit)? = null,
379
+ val isLoading: Boolean = false
380
+ ) : HeaderTitle()
381
+
382
+ class Journey(
383
+ val start: String,
384
+ val end: String? = null,
385
+ val description: String? = null,
386
+ val icon: String,
387
+ val iconColor: String? = null,
388
+ val tintColor: String? = null,
389
+ val onPress: (() -> Unit)? = null,
390
+ val isLoading: Boolean = false
391
+ ) : HeaderTitle()
392
+ }
393
+
394
+ sealed class HeaderType {
395
+ interface DefaultOrExtended {
396
+ val useAnimated: Boolean
397
+ val inputSearchProps: InputSearchProps?
398
+ }
399
+
400
+ data class Default(
401
+ override val useAnimated: Boolean = false,
402
+ override val inputSearchProps: InputSearchProps? = null
403
+ ) : HeaderType(), DefaultOrExtended
404
+
405
+ data class Extended(
406
+ override val useAnimated: Boolean = false,
407
+ override val inputSearchProps: InputSearchProps? = null
408
+ ) : HeaderType(), DefaultOrExtended
409
+
410
+ data object None : HeaderType()
411
+
412
+ data class Animated(
413
+ val aspectRatio: AnimatedHeaderRatio = AnimatedHeaderRatio.RATIO_16_9,
414
+ val isSurface: Boolean = true,
415
+ val layoutOffSet: Dp = 56.dp,
416
+ val height: Dp? = null,
417
+ val composable: @Composable (scrollState: Int) -> Unit = {},
418
+ // Wide windows: fills the sides of the phone-sized banner, fading out downward.
419
+ val bannerBackgroundColor: Color? = null,
420
+ ) : HeaderType()
421
+
422
+ data class Transparent(
423
+ val isFullScreenContent: Boolean = false
424
+ ) : HeaderType()
425
+ }
426
+
427
+ data class HeaderBackProps(
428
+ val preventBack: PopupNotifyProps? = null,
429
+ )
430
+
431
+ @InternalApi
432
+ data class HeaderColor(val tintIconColor: Color, val backgroundButton: Color, val borderColor: Color)
433
+
434
+ // The enclosing header's colors, so a custom header right follows the bar (SwiftUI `\.headerColor`).
435
+ internal val LocalHeaderColor = compositionLocalOf<HeaderColor?> { null }
436
+
437
+ internal fun getHeaderColor(headerType: HeaderType, opacity: Float, tintColor: Color?, defaultColor: Color): HeaderColor{
438
+ return if(headerType is HeaderType.Animated) {
439
+ if (opacity == 1f || !headerType.isSurface)
440
+ HeaderColor(
441
+ tintIconColor = Colors.black_17,
442
+ backgroundButton = Colors.black_01.copy(alpha = 0.6f),
443
+ borderColor = Colors.black_20.copy(alpha = 0.2f)
444
+ )
445
+ else
446
+ HeaderColor(
447
+ tintIconColor = Colors.black_01,
448
+ backgroundButton = Colors.black_20.copy(alpha = 0.6f),
449
+ borderColor = Color.Transparent
450
+ )
451
+ }
452
+ else {
453
+ if (tintColor == Colors.black_01)
454
+ HeaderColor(
455
+ tintIconColor = tintColor,
456
+ backgroundButton = Colors.black_20.copy(alpha = 0.6f),
457
+ borderColor = Colors.black_01.copy(alpha = 0.2f)
458
+ )
459
+ else
460
+ HeaderColor(
461
+ tintIconColor = tintColor ?: defaultColor,
462
+ backgroundButton = Colors.black_01.copy(alpha = 0.6f),
463
+ borderColor = Colors.black_20.copy(alpha = 0.2f)
464
+ )
465
+ }
466
+ }
@@ -0,0 +1,105 @@
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
+ // RN spans the gradient over 375:154 and clips it, so a default header shows only its top
94
+ val endY = if (fillsBox) Float.POSITIVE_INFINITY else with(density) { maxHeight.toPx() }
95
+ background(Brush.verticalGradient(colors = listOf(color, backgroundColor), endY = endY))
96
+ }
97
+ ){
98
+ if (!theme.isHeaderImage()) return@Box
99
+ Image(
100
+ source = theme.assets.headerBackground!!,
101
+ modifier = Modifier.fillMaxSize(),
102
+ )
103
+ }
104
+ }
105
+ }
@@ -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
+ }