@momo-kits/native-kits 0.167.1-duo.4 → 0.167.1-duo.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 (143) hide show
  1. package/build.gradle.kts +11 -0
  2. package/compose/build.gradle.kts +190 -0
  3. package/compose/build.gradle.kts.backup +190 -0
  4. package/compose/compose.podspec +47 -0
  5. package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +19 -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 +151 -0
  10. package/compose/src/commonMain/kotlin/vn/momo/kits/application/AnimationSearchInput.kt +52 -0
  11. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +124 -0
  12. package/compose/src/commonMain/kotlin/vn/momo/kits/application/FloatingButton.kt +183 -0
  13. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Header.kt +207 -0
  14. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderAnimated.kt +39 -0
  15. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderBackground.kt +86 -0
  16. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderDefault.kt +76 -0
  17. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderExtended.kt +76 -0
  18. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderRight.kt +293 -0
  19. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderTitle.kt +33 -0
  20. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +831 -0
  21. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +269 -0
  22. package/compose/src/commonMain/kotlin/vn/momo/kits/application/NavigationContainer.kt +110 -0
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Screen.kt +378 -0
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +56 -0
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/application/useHeaderSearchAnimation.kt +69 -0
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +157 -0
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +82 -0
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +32 -0
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +338 -0
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +175 -0
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +356 -0
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +113 -0
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +89 -0
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +128 -0
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +209 -0
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +542 -0
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +49 -0
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +76 -0
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +125 -0
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +231 -0
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +189 -0
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +475 -0
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +114 -0
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +266 -0
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +240 -0
  46. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +223 -0
  47. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +264 -0
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +185 -0
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +343 -0
  50. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +108 -0
  51. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +56 -0
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +41 -0
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +84 -0
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +40 -0
  55. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +334 -0
  56. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +98 -0
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +310 -0
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +59 -0
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +87 -0
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +21 -0
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +90 -0
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +323 -0
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +220 -0
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +473 -0
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +122 -0
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +199 -0
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +91 -0
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +552 -0
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +88 -0
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +125 -0
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +207 -0
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +498 -0
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +176 -0
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +182 -0
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +193 -0
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +29 -0
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +234 -0
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +188 -0
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +325 -0
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +16 -0
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/const/KitDesignSystem.kt +18 -0
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/const/KitFontScale.kt +22 -0
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +12 -0
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +16 -0
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +188 -0
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +297 -0
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +54 -0
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +50 -0
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +157 -0
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +41 -0
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +52 -0
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +66 -0
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +11 -0
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +104 -0
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +48 -0
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +51 -0
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +299 -0
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/HostBackGestureBridge.kt +58 -0
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +129 -0
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +106 -0
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +205 -0
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +393 -0
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +8 -0
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +622 -0
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +148 -0
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +35 -0
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +175 -0
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +232 -0
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +86 -0
  110. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +169 -0
  111. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +381 -0
  112. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +83 -0
  113. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderJourney.kt +105 -0
  114. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderLocation.kt +74 -0
  115. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +347 -0
  116. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +37 -0
  117. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +363 -0
  118. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +169 -0
  119. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +132 -0
  120. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +127 -0
  121. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +12 -0
  122. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +91 -0
  123. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +9 -0
  124. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +71 -0
  125. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +1329 -0
  126. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +55 -0
  127. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +15 -0
  128. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +118 -0
  129. package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +40 -0
  130. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/HostBackGesture.ios.kt +45 -0
  131. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +32 -0
  132. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/BackGesture.ios.kt +38 -0
  133. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +66 -0
  134. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +213 -0
  135. package/gradle/libs.versions.toml +69 -0
  136. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  137. package/gradle/wrapper/gradle-wrapper.properties +8 -0
  138. package/gradle.properties +26 -0
  139. package/gradlew +252 -0
  140. package/gradlew.bat +94 -0
  141. package/ios-demo/README.md +120 -0
  142. package/package.json +1 -1
  143. package/settings.gradle.kts +64 -0
@@ -0,0 +1,169 @@
1
+ package vn.momo.kits.navigation.component
2
+
3
+ import androidx.compose.animation.*
4
+ import androidx.compose.animation.core.CubicBezierEasing
5
+ import androidx.compose.animation.core.LinearEasing
6
+ import androidx.compose.animation.core.animateDpAsState
7
+ import androidx.compose.animation.core.tween
8
+ import androidx.compose.foundation.ScrollState
9
+ import androidx.compose.foundation.background
10
+ import androidx.compose.foundation.border
11
+ import androidx.compose.foundation.interaction.MutableInteractionSource
12
+ import androidx.compose.foundation.layout.*
13
+ import androidx.compose.material3.AlertDialogDefaults
14
+ import androidx.compose.material3.FloatingActionButton
15
+ import androidx.compose.material3.FloatingActionButtonDefaults
16
+ import androidx.compose.material3.FloatingActionButtonElevation
17
+ import androidx.compose.runtime.*
18
+ import androidx.compose.runtime.saveable.rememberSaveable
19
+ import androidx.compose.ui.Alignment
20
+ import androidx.compose.ui.Modifier
21
+ import androidx.compose.ui.graphics.Color
22
+ import androidx.compose.ui.unit.Dp
23
+ import androidx.compose.ui.unit.dp
24
+ import kotlinx.coroutines.delay
25
+ import kotlinx.coroutines.flow.MutableStateFlow
26
+ import kotlinx.coroutines.flow.collectLatest
27
+ import kotlinx.coroutines.launch
28
+ import vn.momo.kits.application.IsShowBaseLineDebug
29
+ import vn.momo.kits.components.Icon
30
+ import vn.momo.kits.components.Text
31
+ import vn.momo.kits.const.Colors
32
+ import vn.momo.kits.const.Typography
33
+ import vn.momo.kits.modifier.conditional
34
+ import kotlin.time.Duration.Companion.milliseconds
35
+
36
+ enum class FABSize { SMALL, DEFAULT }
37
+ enum class FABPosition { END, CENTER }
38
+
39
+ data class FloatingButtonProps(
40
+ val icon: String,
41
+ val iconColor: Color? = null,
42
+ val label: String? = null,
43
+ val onClick: () -> Unit,
44
+ val size: FABSize = FABSize.DEFAULT,
45
+ val bottom: Dp? = null,
46
+ val scrollState: ScrollState? = null,
47
+ val position: FABPosition? = FABPosition.END,
48
+ )
49
+
50
+ private val FabSmallSize = 36.dp
51
+ private val FabDefaultSize = 48.dp
52
+ private val FabExpandedWidth = 80.dp
53
+ private val FabIconSizeSmall = 12.dp
54
+ private val FabIconSizeDefault = 24.dp
55
+ private val FabPaddingHorizontal = 12.dp
56
+
57
+ @Composable
58
+ internal fun FloatingButton(
59
+ scrollPosition: Int,
60
+ bottom: Dp,
61
+ onClick: () -> Unit,
62
+ containerColor: Color,
63
+ contentColor: Color = containerColor,
64
+ icon: String,
65
+ iconColor: Color? = null,
66
+ text: String? = null,
67
+ elevation: FloatingActionButtonElevation = FloatingActionButtonDefaults.elevation(4.dp),
68
+ size: FABSize = FABSize.DEFAULT,
69
+ position: FABPosition = FABPosition.END,
70
+ keyboardSize: Dp = 0.dp,
71
+ ) {
72
+ val scrollStateFlow = remember { MutableStateFlow(scrollPosition) }
73
+ var lastScrollPosition by rememberSaveable { mutableStateOf(0) }
74
+ var isExpanded by rememberSaveable { mutableStateOf(false) }
75
+
76
+ val coroutineScope = rememberCoroutineScope()
77
+
78
+ // Animations
79
+ val baseSize = if (size == FABSize.SMALL) FabSmallSize else FabDefaultSize
80
+ val width by animateDpAsState(
81
+ targetValue = if (isExpanded && text != null) FabExpandedWidth else baseSize,
82
+ animationSpec = tween(100, easing = CubicBezierEasing(0.2f, 0.2f, 0.2f, 0.2f))
83
+ )
84
+
85
+ // Scroll listener
86
+ LaunchedEffect(text) {
87
+ if (text != null) {
88
+ coroutineScope.launch {
89
+ scrollStateFlow.collectLatest { newScroll ->
90
+ isExpanded = newScroll <= lastScrollPosition
91
+ delay(100.milliseconds)
92
+ lastScrollPosition = newScroll
93
+ }
94
+ }
95
+ }
96
+ }
97
+
98
+ LaunchedEffect(scrollPosition) {
99
+ scrollStateFlow.value = scrollPosition
100
+ }
101
+
102
+ Box(
103
+ modifier = Modifier
104
+ .fillMaxSize()
105
+ .padding(end = 12.dp, bottom = bottom)
106
+ .offset(y = -keyboardSize)
107
+ .background(Color.Transparent),
108
+ contentAlignment = if (position == FABPosition.END) Alignment.BottomEnd else Alignment.BottomCenter,
109
+ ) {
110
+ FloatingActionButton(
111
+ onClick = onClick,
112
+ shape = AlertDialogDefaults.shape,
113
+ containerColor = containerColor,
114
+ contentColor = contentColor,
115
+ elevation = elevation,
116
+ interactionSource = remember { MutableInteractionSource() },
117
+ modifier = Modifier
118
+ .sizeIn(minWidth = width)
119
+ .height(baseSize)
120
+ .conditional(IsShowBaseLineDebug) {
121
+ border(1.dp, Colors.blue_03)
122
+ }
123
+ ) {
124
+ Row(
125
+ modifier = Modifier.padding(
126
+ start = if (isExpanded) FabPaddingHorizontal else 0.dp,
127
+ end = if (isExpanded) FabPaddingHorizontal else 0.dp,
128
+ ),
129
+ verticalAlignment = Alignment.CenterVertically,
130
+ horizontalArrangement = if (isExpanded) Arrangement.Start else Arrangement.Center
131
+ ) {
132
+ Icon(
133
+ source = icon,
134
+ size = if (size == FABSize.SMALL) FabIconSizeSmall else FabIconSizeDefault,
135
+ color = iconColor ?: Color.White
136
+ )
137
+
138
+ AnimatedVisibility(
139
+ visible = isExpanded,
140
+ enter = fadeInExpandAnimation,
141
+ exit = fadeOutShrinkAnimation,
142
+ ) {
143
+ Row {
144
+ Spacer(Modifier.width(12.dp))
145
+ Text(
146
+ text = text ?: "",
147
+ color = Color.White,
148
+ style = Typography.actionDefaultBold
149
+ )
150
+ }
151
+ }
152
+ }
153
+ }
154
+ }
155
+ }
156
+
157
+ private val fadeOutShrinkAnimation = fadeOut(
158
+ animationSpec = tween(100, easing = LinearEasing)
159
+ ) + shrinkHorizontally(
160
+ animationSpec = tween(100, easing = LinearEasing),
161
+ shrinkTowards = Alignment.Start
162
+ )
163
+
164
+ private val fadeInExpandAnimation = fadeIn(
165
+ animationSpec = tween(100, easing = LinearEasing)
166
+ ) + expandHorizontally(
167
+ animationSpec = tween(100, easing = LinearEasing),
168
+ expandFrom = Alignment.Start
169
+ )
@@ -0,0 +1,381 @@
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.getValue
22
+ import androidx.compose.ui.Alignment
23
+ import androidx.compose.ui.Modifier
24
+ import androidx.compose.ui.draw.clipToBounds
25
+ import androidx.compose.ui.graphics.graphicsLayer
26
+ import androidx.compose.ui.graphics.Brush
27
+ import androidx.compose.ui.graphics.Color
28
+ import androidx.compose.ui.layout.onGloballyPositioned
29
+ import androidx.compose.ui.platform.LocalDensity
30
+ import androidx.compose.ui.text.style.TextAlign
31
+ import androidx.compose.ui.unit.Dp
32
+ import androidx.compose.ui.unit.dp
33
+ import vn.momo.kits.components.Icon
34
+ import vn.momo.kits.components.Image
35
+ import vn.momo.kits.components.InputSearchProps
36
+ import vn.momo.kits.const.AppTheme
37
+ import vn.momo.kits.const.Colors
38
+ import vn.momo.kits.components.PopupNotifyProps
39
+ import vn.momo.kits.application.IsShowBaseLineDebug
40
+ import vn.momo.kits.const.Spacing
41
+ import vn.momo.kits.layout.getScreenLayout
42
+ import vn.momo.kits.modifier.activeOpacityClickable
43
+ import vn.momo.kits.modifier.conditional
44
+ import vn.momo.kits.modifier.setAutomationId
45
+ import vn.momo.kits.navigation.LocalHeaderRightWidthPx
46
+ import vn.momo.kits.navigation.LocalNavigator
47
+ import vn.momo.kits.navigation.LocalOptions
48
+ import vn.momo.kits.navigation.LocalScrollState
49
+ import vn.momo.kits.navigation.getInputSearchType
50
+ import vn.momo.kits.platform.getScreenDimensions
51
+ import vn.momo.kits.utils.horizontalSafeAreaPadding
52
+
53
+ @InternalApi
54
+ const val HEADER_HEIGHT = 52
55
+ internal enum class InputSearchType { None, Header, Animated }
56
+ enum class TitlePosition { LEFT, CENTER }
57
+
58
+ private val HEADER_ACTIONS_WIDTH = 172.dp
59
+
60
+ @Suppress("FrequentlyChangingValue")
61
+ @Composable
62
+ internal fun headerOpacity(): Float {
63
+ val options = LocalOptions.current
64
+ val scrollState = LocalScrollState.current
65
+ val opacityHeight = when (val header = options.headerType) {
66
+ is HeaderType.Animated -> with(LocalDensity.current) { header.layoutOffSet.roundToPx() }
67
+ else -> HEADER_HEIGHT
68
+ }
69
+ val opacity by animateFloatAsState(
70
+ targetValue = when {
71
+ options.headerType is HeaderType.Transparent -> 0f
72
+ opacityHeight <= 0 -> if (scrollState.value > 0) 1f else 0f
73
+ else -> (scrollState.value / opacityHeight.toFloat()).coerceIn(0f, 1f)
74
+ }
75
+ )
76
+ return opacity
77
+ }
78
+
79
+ // Back button and toolkit share the bar with the title unless the iPhone Duo side bar holds them.
80
+ @Composable
81
+ internal fun headerTitleMaxWidth(): Dp {
82
+ val layout = getScreenLayout()
83
+ if (layout.sideBar != null) return layout.contentWidth - Spacing.M * 2
84
+ return getScreenDimensions().width.dp - HEADER_ACTIONS_WIDTH
85
+ }
86
+
87
+ @Composable
88
+ internal fun Header(onBackHandler: (() -> Unit)? = null) {
89
+ val options = LocalOptions.current
90
+ val navigator = LocalNavigator.current
91
+ val headerRightWidthPx = LocalHeaderRightWidthPx.current
92
+ val inputSearchType = getInputSearchType(options)
93
+ val layout = getScreenLayout()
94
+ val useSideBar = layout.sideBar != null
95
+ val opacity = headerOpacity()
96
+
97
+ val headerColor = getHeaderColor(options.headerType, opacity, options.tintColor, Colors.black_17)
98
+
99
+ val animatedAlpha by animateFloatAsState(targetValue = opacity, label = "BackgroundAlpha")
100
+
101
+ val background = if (options.headerType is HeaderType.Transparent)
102
+ options.backgroundColor ?: AppTheme.current.colors.background.surface
103
+ else
104
+ AppTheme.current.colors.background.surface
105
+
106
+ if (options.headerType == HeaderType.None) return
107
+
108
+ val titlePosition = options.titlePosition
109
+ val titleColor = headerColor.tintIconColor
110
+ .copy(alpha = if (inputSearchType == InputSearchType.Animated) 1f - animatedAlpha else 1f)
111
+ // Centered title needs a full-width overlay to stay screen-centered, not boxed between back button and header right.
112
+ val centerTitle = titlePosition == TitlePosition.CENTER && options.headerTitle is HeaderTitle.Default
113
+
114
+ val headerImage = AppTheme.current.assets.headerBackground
115
+ .takeUnless { options.headerType is HeaderType.Transparent }
116
+
117
+ Box(
118
+ Modifier.height(layout.headerHeight)
119
+ .fillMaxWidth()
120
+ .conditional(headerImage.isNullOrEmpty()) {
121
+ background(background.copy(alpha = animatedAlpha))
122
+ }
123
+ .conditional(IsShowBaseLineDebug) {
124
+ border(1.dp, Colors.blue_03)
125
+ },
126
+ contentAlignment = Alignment.BottomCenter
127
+ ) {
128
+ if (!headerImage.isNullOrEmpty()) {
129
+ Box(
130
+ Modifier
131
+ .matchParentSize()
132
+ .clipToBounds()
133
+ .graphicsLayer { alpha = animatedAlpha }
134
+ .background(background)
135
+ ) {
136
+ Image(
137
+ source = headerImage,
138
+ loading = false,
139
+ modifier = Modifier
140
+ .fillMaxWidth()
141
+ .wrapContentHeight(Alignment.Top, unbounded = true)
142
+ .height(HEADER_BACKGROUND_HEIGHT),
143
+ )
144
+ }
145
+ }
146
+ Row(
147
+ modifier = Modifier.height(layout.headerBarHeight)
148
+ .fillMaxWidth()
149
+ .horizontalSafeAreaPadding()
150
+ .padding(horizontal = Spacing.M),
151
+ verticalAlignment = Alignment.CenterVertically,
152
+ horizontalArrangement = Arrangement.SpaceBetween
153
+ ) {
154
+ if (!options.hiddenBack && !useSideBar) {
155
+ BackButton(
156
+ borderColor = headerColor.borderColor,
157
+ backgroundButton = headerColor.backgroundButton,
158
+ tintIconColor = headerColor.tintIconColor,
159
+ onBackHandler = {
160
+ navigator.onBackSafe { }
161
+ }
162
+ )
163
+ Spacer(Modifier.width(Spacing.S))
164
+ }
165
+
166
+ if (centerTitle) {
167
+ Spacer(Modifier.weight(1f))
168
+ } else {
169
+ HeaderContent(
170
+ headerTitle = options.headerTitle,
171
+ tintIconColor = titleColor,
172
+ titlePosition = titlePosition,
173
+ modifier = Modifier.weight(1f)
174
+ )
175
+ }
176
+ Box(Modifier.onGloballyPositioned {
177
+ if(headerRightWidthPx.intValue != it.size.width) headerRightWidthPx.intValue = it.size.width
178
+ }){
179
+ if (!(useSideBar && options.headerRight is HeaderRight.Toolkit)) {
180
+ HeaderRight(options.headerRight, options.tintColor, headerColor)
181
+ }
182
+ }
183
+ }
184
+ if (centerTitle) {
185
+ Box(
186
+ modifier = Modifier.height(layout.headerBarHeight)
187
+ .fillMaxWidth()
188
+ .horizontalSafeAreaPadding()
189
+ .padding(horizontal = Spacing.M),
190
+ contentAlignment = Alignment.Center
191
+ ) {
192
+ HeaderContent(
193
+ headerTitle = options.headerTitle,
194
+ tintIconColor = titleColor,
195
+ titlePosition = titlePosition,
196
+ modifier = Modifier.fillMaxWidth()
197
+ )
198
+ }
199
+ }
200
+ VerticalShadow(opacity)
201
+ }
202
+ }
203
+
204
+ @Composable
205
+ private fun BackButton(borderColor: Color, backgroundButton: Color, tintIconColor: Color, onBackHandler: () -> Unit){
206
+ Box(
207
+ modifier = Modifier
208
+ .size(28.dp)
209
+ .background(backgroundButton, RoundedCornerShape(100))
210
+ .border(width = 0.2.dp, color = borderColor, shape = RoundedCornerShape(100))
211
+ .activeOpacityClickable(onClick = onBackHandler)
212
+ .padding(Spacing.XS)
213
+ .setAutomationId("btn_navigation_back"),
214
+ contentAlignment = Alignment.Center
215
+ ) {
216
+ Icon(
217
+ source = "arrow-back",
218
+ color = tintIconColor,
219
+ size = 20.dp,
220
+ )
221
+ }
222
+ }
223
+
224
+ @Composable
225
+ internal fun HeaderContent(
226
+ headerTitle: HeaderTitle,
227
+ tintIconColor: Color,
228
+ titlePosition: TitlePosition = TitlePosition.LEFT,
229
+ modifier: Modifier = Modifier,
230
+ ){
231
+ Box(
232
+ modifier = modifier,
233
+ contentAlignment = if (titlePosition == TitlePosition.CENTER) Alignment.Center else Alignment.CenterStart
234
+ ) {
235
+ when (headerTitle){
236
+ is HeaderTitle.Default -> {
237
+ HeaderTitle(
238
+ title = headerTitle.title,
239
+ color = tintIconColor,
240
+ modifier = Modifier.fillMaxWidth(fraction = if (titlePosition == TitlePosition.CENTER) 0.5f else 1f),
241
+ textAlign = if (titlePosition == TitlePosition.CENTER) TextAlign.Center else TextAlign.Start
242
+ )
243
+ }
244
+ is HeaderTitle.Journey -> {
245
+ HeaderJourney(
246
+ data = headerTitle,
247
+ tintIconColor = tintIconColor
248
+ )
249
+ }
250
+ is HeaderTitle.Location -> {
251
+ HeaderLocation(
252
+ data = headerTitle,
253
+ tintIconColor = tintIconColor
254
+ )
255
+ }
256
+ is HeaderTitle.User -> {
257
+ HeaderUser(
258
+ data = headerTitle
259
+ )
260
+ }
261
+ }
262
+ }
263
+ }
264
+
265
+ @Composable
266
+ internal fun VerticalShadow(opacity: Float){
267
+ if(opacity == 1f){
268
+ Box(modifier = Modifier
269
+ .fillMaxWidth()
270
+ .height(6.dp)
271
+ .offset(x = 0.dp, y = 6.dp)
272
+ .background(
273
+ brush = Brush.verticalGradient(
274
+ colors = listOf(Color.Black.copy(alpha = 0.05f), Color.Transparent)
275
+ )
276
+ )
277
+ )
278
+ }
279
+ }
280
+
281
+ sealed class HeaderTitle {
282
+ class Default(val title: String) : HeaderTitle()
283
+
284
+ class User(
285
+ val title: String,
286
+ val subTitle: String? = null,
287
+ val image: List<String>? = null,
288
+ val dotColor: Color? = null,
289
+ val tintColor: Color? = null,
290
+ val onPress: (() -> Unit)? = null,
291
+ val icons: List<String> = emptyList(),
292
+ val isLoading: Boolean = false
293
+ ) : HeaderTitle()
294
+
295
+ class Location(
296
+ val description: String? = null,
297
+ val location: String,
298
+ val tintColor: String? = null,
299
+ val onPress: (() -> Unit)? = null,
300
+ val isLoading: Boolean = false
301
+ ) : HeaderTitle()
302
+
303
+ class Journey(
304
+ val start: String,
305
+ val end: String? = null,
306
+ val description: String? = null,
307
+ val icon: String,
308
+ val iconColor: String? = null,
309
+ val tintColor: String? = null,
310
+ val onPress: (() -> Unit)? = null,
311
+ val isLoading: Boolean = false
312
+ ) : HeaderTitle()
313
+ }
314
+
315
+ sealed class HeaderType {
316
+ interface DefaultOrExtended {
317
+ val useAnimated: Boolean
318
+ val inputSearchProps: InputSearchProps?
319
+ }
320
+
321
+ data class Default(
322
+ override val useAnimated: Boolean = false,
323
+ override val inputSearchProps: InputSearchProps? = null
324
+ ) : HeaderType(), DefaultOrExtended
325
+
326
+ data class Extended(
327
+ override val useAnimated: Boolean = false,
328
+ override val inputSearchProps: InputSearchProps? = null
329
+ ) : HeaderType(), DefaultOrExtended
330
+
331
+ data object None : HeaderType()
332
+
333
+ data class Animated(
334
+ val aspectRatio: AnimatedHeaderRatio = AnimatedHeaderRatio.RATIO_16_9,
335
+ val isSurface: Boolean = true,
336
+ val layoutOffSet: Dp = 56.dp,
337
+ val height: Dp? = null,
338
+ val composable: @Composable (scrollState: Int) -> Unit = {}
339
+ ) : HeaderType()
340
+
341
+ data class Transparent(
342
+ val isFullScreenContent: Boolean = false
343
+ ) : HeaderType()
344
+ }
345
+
346
+ data class HeaderBackProps(
347
+ val preventBack: PopupNotifyProps? = null,
348
+ )
349
+
350
+ @InternalApi
351
+ data class HeaderColor(val tintIconColor: Color, val backgroundButton: Color, val borderColor: Color)
352
+ internal fun getHeaderColor(headerType: HeaderType, opacity: Float, tintColor: Color?, defaultColor: Color): HeaderColor{
353
+ return if(headerType is HeaderType.Animated) {
354
+ if (opacity == 1f || !headerType.isSurface)
355
+ HeaderColor(
356
+ tintIconColor = Colors.black_17,
357
+ backgroundButton = Colors.black_01.copy(alpha = 0.6f),
358
+ borderColor = Colors.black_20.copy(alpha = 0.2f)
359
+ )
360
+ else
361
+ HeaderColor(
362
+ tintIconColor = Colors.black_01,
363
+ backgroundButton = Colors.black_20.copy(alpha = 0.6f),
364
+ borderColor = Color.Transparent
365
+ )
366
+ }
367
+ else {
368
+ if (tintColor == Colors.black_01)
369
+ HeaderColor(
370
+ tintIconColor = tintColor,
371
+ backgroundButton = Colors.black_20.copy(alpha = 0.6f),
372
+ borderColor = Colors.black_01.copy(alpha = 0.2f)
373
+ )
374
+ else
375
+ HeaderColor(
376
+ tintIconColor = tintColor ?: defaultColor,
377
+ backgroundButton = Colors.black_01.copy(alpha = 0.6f),
378
+ borderColor = Colors.black_20.copy(alpha = 0.2f)
379
+ )
380
+ }
381
+ }
@@ -0,0 +1,83 @@
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.fillMaxSize
7
+ import androidx.compose.foundation.layout.fillMaxWidth
8
+ import androidx.compose.foundation.layout.height
9
+ import androidx.compose.runtime.Composable
10
+ import androidx.compose.runtime.getValue
11
+ import androidx.compose.ui.Modifier
12
+ import androidx.compose.ui.geometry.Offset
13
+ import androidx.compose.ui.graphics.Brush
14
+ import androidx.compose.ui.graphics.Color
15
+ import androidx.compose.ui.platform.LocalDensity
16
+ import androidx.compose.ui.unit.dp
17
+ import vn.momo.kits.components.Image
18
+ import vn.momo.kits.const.AppTheme
19
+ import vn.momo.kits.layout.getScreenLayout
20
+ import vn.momo.kits.modifier.conditional
21
+ import vn.momo.kits.navigation.LocalOptions
22
+ import vn.momo.kits.navigation.LocalScrollState
23
+
24
+ enum class AnimatedHeaderRatio(val value: Float){
25
+ RATIO_16_9(16f / 9f),
26
+ RATIO_1_1(1f),
27
+ RATIO_3_2(3f / 2f)
28
+ }
29
+
30
+ internal val HEADER_BACKGROUND_HEIGHT = 154.dp
31
+
32
+ @Suppress("FrequentlyChangingValue")
33
+ @Composable
34
+ internal fun HeaderBackground() {
35
+ val density = LocalDensity.current
36
+ val theme = AppTheme.current
37
+ val options = LocalOptions.current
38
+ val scrollState = LocalScrollState.current
39
+ val backgroundColor = options.backgroundColor ?: AppTheme.current.colors.background.default
40
+
41
+ val minHeight = getScreenLayout().headerHeight
42
+ val maxHeight = HEADER_BACKGROUND_HEIGHT
43
+ val opacity by animateFloatAsState(
44
+ targetValue = (1 - (scrollState.value * 1f / HEADER_HEIGHT * 1f)).coerceIn(0f, 1f),
45
+ )
46
+
47
+ val color = if (opacity == 0f) backgroundColor else Color(0xFFFDCADE)
48
+ val height = when (options.headerType) {
49
+ is HeaderType.Default -> minHeight
50
+ is HeaderType.Extended -> {
51
+ if (AppTheme.current.isHeaderImage()){
52
+ if (opacity == 0f) minHeight else maxHeight
53
+ } else {
54
+ maxHeight
55
+ }
56
+ }
57
+ else -> 0.dp
58
+ }
59
+
60
+ Box(Modifier.fillMaxWidth().height(height).background(backgroundColor)) {
61
+ Box(Modifier
62
+ .height(maxHeight)
63
+ .fillMaxWidth()
64
+ .conditional(!theme.isHeaderImage()) {
65
+ background(Brush.linearGradient(
66
+ colors = listOf(
67
+ color,
68
+ backgroundColor
69
+ ),
70
+ start = Offset(0f, 0f),
71
+ end = Offset(0f, with(density) { maxHeight.toPx() })
72
+ )
73
+ )
74
+ }
75
+ ){
76
+ if (!theme.isHeaderImage()) return@Box
77
+ Image(
78
+ source = theme.assets.headerBackground!!,
79
+ modifier = Modifier.fillMaxSize(),
80
+ )
81
+ }
82
+ }
83
+ }