@momo-kits/native-kits 0.162.1-beta.2 → 0.162.1-beta.3-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 (136) hide show
  1. package/build.gradle.kts +11 -0
  2. package/compose/build.gradle.kts +189 -0
  3. package/compose/build.gradle.kts.backup +189 -0
  4. package/compose/compose.podspec +47 -0
  5. package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +6 -0
  6. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +123 -0
  7. package/compose/src/commonMain/composeResources/font/momosignature.otf +0 -0
  8. package/compose/src/commonMain/composeResources/font/momotrustdisplay.otf +0 -0
  9. package/compose/src/commonMain/composeResources/font/sfprotext_black.otf +0 -0
  10. package/compose/src/commonMain/composeResources/font/sfprotext_black.ttf +0 -0
  11. package/compose/src/commonMain/composeResources/font/sfprotext_bold.ttf +0 -0
  12. package/compose/src/commonMain/composeResources/font/sfprotext_heavy.ttf +0 -0
  13. package/compose/src/commonMain/composeResources/font/sfprotext_light.ttf +0 -0
  14. package/compose/src/commonMain/composeResources/font/sfprotext_medium.ttf +0 -0
  15. package/compose/src/commonMain/composeResources/font/sfprotext_regular.ttf +0 -0
  16. package/compose/src/commonMain/composeResources/font/sfprotext_semibold.ttf +0 -0
  17. package/compose/src/commonMain/composeResources/font/sfprotext_thin.otf +0 -0
  18. package/compose/src/commonMain/composeResources/font/sfprotext_thin.ttf +0 -0
  19. package/compose/src/commonMain/composeResources/font/sfprotext_ultralight.otf +0 -0
  20. package/compose/src/commonMain/composeResources/font/sfprotext_ultralight.ttf +0 -0
  21. package/compose/src/commonMain/kotlin/vn/momo/kits/application/AnimationSearchInput.kt +52 -0
  22. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +109 -0
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/application/FloatingButton.kt +183 -0
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Header.kt +207 -0
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderAnimated.kt +39 -0
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderBackground.kt +86 -0
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderDefault.kt +76 -0
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderExtended.kt +76 -0
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderRight.kt +294 -0
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderTitle.kt +33 -0
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +826 -0
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/application/NavigationContainer.kt +109 -0
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Screen.kt +378 -0
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/application/useHeaderSearchAnimation.kt +69 -0
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +157 -0
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +80 -0
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +32 -0
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +338 -0
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +175 -0
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +354 -0
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +113 -0
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +89 -0
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +128 -0
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +209 -0
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +543 -0
  46. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +23 -0
  47. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +76 -0
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +140 -0
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +188 -0
  50. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +112 -0
  51. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +477 -0
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +114 -0
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +214 -0
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +240 -0
  55. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +216 -0
  56. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +259 -0
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +180 -0
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +343 -0
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +108 -0
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +56 -0
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +41 -0
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +84 -0
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +40 -0
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +331 -0
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +97 -0
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +310 -0
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +59 -0
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +87 -0
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +90 -0
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +323 -0
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +217 -0
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +473 -0
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +122 -0
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +199 -0
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +91 -0
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +470 -0
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +88 -0
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +131 -0
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +203 -0
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +498 -0
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +177 -0
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +182 -0
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +193 -0
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +29 -0
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +234 -0
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +188 -0
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +306 -0
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +12 -0
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +16 -0
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +188 -0
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +270 -0
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +2 -0
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +35 -0
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +2 -0
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +52 -0
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +66 -0
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +11 -0
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +104 -0
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +48 -0
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +51 -0
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +253 -0
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +129 -0
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +94 -0
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +163 -0
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationEvent.kt +53 -0
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +399 -0
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +8 -0
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +557 -0
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +155 -0
  110. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +223 -0
  111. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +86 -0
  112. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +169 -0
  113. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +319 -0
  114. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +81 -0
  115. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +309 -0
  116. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +34 -0
  117. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +360 -0
  118. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +132 -0
  119. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +128 -0
  120. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +70 -0
  121. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +58 -0
  122. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +1329 -0
  123. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +55 -0
  124. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +15 -0
  125. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +105 -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/Platform.ios.kt +184 -0
  128. package/gradle/libs.versions.toml +67 -0
  129. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  130. package/gradle/wrapper/gradle-wrapper.properties +8 -0
  131. package/gradle.properties +26 -0
  132. package/gradlew +252 -0
  133. package/gradlew.bat +94 -0
  134. package/local.properties +8 -0
  135. package/package.json +1 -1
  136. package/settings.gradle.kts +64 -0
@@ -0,0 +1,253 @@
1
+ package vn.momo.kits.navigation
2
+
3
+ import androidx.compose.animation.core.Animatable
4
+ import androidx.compose.animation.core.CubicBezierEasing
5
+ import androidx.compose.animation.core.tween
6
+ import androidx.compose.foundation.background
7
+ import androidx.compose.foundation.border
8
+ import androidx.compose.foundation.gestures.detectDragGestures
9
+ import androidx.compose.foundation.layout.Box
10
+ import androidx.compose.foundation.layout.BoxWithConstraints
11
+ import androidx.compose.foundation.layout.Column
12
+ import androidx.compose.foundation.layout.Row
13
+ import androidx.compose.foundation.layout.Spacer
14
+ import androidx.compose.foundation.layout.fillMaxHeight
15
+ import androidx.compose.foundation.layout.fillMaxSize
16
+ import androidx.compose.foundation.layout.fillMaxWidth
17
+ import androidx.compose.foundation.layout.height
18
+ import androidx.compose.foundation.layout.heightIn
19
+ import androidx.compose.foundation.layout.offset
20
+ import androidx.compose.foundation.layout.padding
21
+ import androidx.compose.foundation.layout.size
22
+ import androidx.compose.foundation.layout.width
23
+ import androidx.compose.foundation.shape.RoundedCornerShape
24
+ import androidx.compose.runtime.Composable
25
+ import androidx.compose.runtime.DisposableEffect
26
+ import androidx.compose.runtime.LaunchedEffect
27
+ import androidx.compose.runtime.remember
28
+ import androidx.compose.runtime.rememberCoroutineScope
29
+ import androidx.compose.ui.Alignment
30
+ import androidx.compose.ui.Modifier
31
+ import androidx.compose.ui.graphics.Color
32
+ import androidx.compose.ui.input.pointer.pointerInput
33
+ import androidx.compose.ui.platform.LocalDensity
34
+ import androidx.compose.ui.unit.IntOffset
35
+ import androidx.compose.ui.unit.dp
36
+ import kotlinx.coroutines.launch
37
+ import vn.momo.kits.components.Divider
38
+ import vn.momo.kits.components.Icon
39
+ import vn.momo.kits.components.Text
40
+ import vn.momo.kits.const.AppTheme
41
+ import vn.momo.kits.const.Colors
42
+ import vn.momo.kits.const.Radius
43
+ import vn.momo.kits.const.Spacing
44
+ import vn.momo.kits.application.ApplicationContext
45
+ import vn.momo.kits.application.IsShowBaseLineDebug
46
+ import vn.momo.kits.const.Typography
47
+ import vn.momo.kits.navigation.tracking.ScreenTracker
48
+ import vn.momo.kits.modifier.conditional
49
+ import vn.momo.kits.modifier.noFeedbackClickable
50
+ import vn.momo.kits.platform.BackHandler
51
+ import vn.momo.kits.platform.getScreenHeight
52
+
53
+ @Composable
54
+ internal fun BottomSheet(
55
+ content: @Composable () -> Unit,
56
+ header: BottomHeader,
57
+ isSurface: Boolean = false,
58
+ barrierDismissible: Boolean = true,
59
+ onDismiss: (() -> Unit)?
60
+ ) {
61
+ val navigator = LocalNavigator.current
62
+
63
+ val screenHeightDp = getScreenHeight()
64
+ val screenHeightPx = with(LocalDensity.current) { screenHeightDp.toPx() }
65
+ val sheetOffset = remember { Animatable(screenHeightPx) }
66
+
67
+ val backgroundAlpha = remember { Animatable(0f) }
68
+ val dynamicAlpha = ((1f - (sheetOffset.value / screenHeightPx)).coerceIn(0f, 1f)) * 0.3f
69
+ val alpha = backgroundAlpha.value + dynamicAlpha
70
+
71
+ val sheetCloseOffset = with(LocalDensity.current) { 100.dp.toPx() }
72
+
73
+ val coroutineScope = rememberCoroutineScope()
74
+
75
+ val maxApi = LocalMaxApi.current
76
+ val context = ApplicationContext.current
77
+
78
+ DisposableEffect(Unit) {
79
+ ScreenTracker.trackPopupDisplayed(
80
+ maxApi = maxApi,
81
+ context = context,
82
+ parentScreenName = ScreenTracker.getLastScreenName()
83
+ )
84
+ onDispose { }
85
+ }
86
+
87
+ suspend fun openEvent(){
88
+ backgroundAlpha.animateTo(
89
+ targetValue = 0.3f,
90
+ animationSpec = tween(
91
+ durationMillis = 100,
92
+ easing = CubicBezierEasing(0.05f, 0.7f, 0.1f, 1f)
93
+ )
94
+ )
95
+ sheetOffset.animateTo(
96
+ targetValue = 0f,
97
+ animationSpec = tween(
98
+ durationMillis = 350,
99
+ easing = CubicBezierEasing(0.05f, 0.7f, 0.1f, 1f)
100
+ )
101
+ )
102
+ }
103
+
104
+ fun closeEvent(){
105
+ coroutineScope.launch {
106
+ sheetOffset.animateTo(
107
+ targetValue = screenHeightPx,
108
+ animationSpec = tween(
109
+ durationMillis = 200,
110
+ easing = CubicBezierEasing(0.3f, 0.0f, 0.8f, 0.15f)
111
+ )
112
+ )
113
+ backgroundAlpha.animateTo(
114
+ targetValue = 0f,
115
+ animationSpec = tween(
116
+ durationMillis = 100,
117
+ easing = CubicBezierEasing(0.3f, 0.0f, 0.8f, 0.15f)
118
+ )
119
+ )
120
+ navigator.pop()
121
+ }
122
+ }
123
+
124
+ LaunchedEffect(Unit) {
125
+ openEvent()
126
+ }
127
+
128
+ DisposableEffect(Unit) {
129
+ OverplayComponentRegistry.bindClose { closeEvent() }
130
+ onDispose {
131
+ onDismiss?.invoke()
132
+ }
133
+ }
134
+
135
+ BackHandler(true){
136
+ closeEvent()
137
+ }
138
+
139
+ BoxWithConstraints(
140
+ modifier = Modifier
141
+ .fillMaxSize()
142
+ .background(Color.Black.copy(alpha = alpha))
143
+ .noFeedbackClickable {
144
+ if(barrierDismissible) closeEvent()
145
+ }
146
+ ) {
147
+ val parentHeight = with(LocalDensity.current) { constraints.maxHeight.toDp() }
148
+
149
+ Box(
150
+ modifier = Modifier
151
+ .align(Alignment.BottomCenter)
152
+ .offset { IntOffset(x = 0, y = sheetOffset.value.toInt()) }
153
+ .fillMaxWidth()
154
+ .heightIn(max = parentHeight - 90.dp)
155
+ .background(
156
+ color = if (isSurface) AppTheme.current.colors.background.surface else AppTheme.current.colors.background.default,
157
+ shape = RoundedCornerShape(topStart = Radius.M, topEnd = Radius.M)
158
+ )
159
+ .conditional(IsShowBaseLineDebug) {
160
+ border(1.dp, Colors.blue_03)
161
+ }
162
+ .noFeedbackClickable { },
163
+ contentAlignment = Alignment.BottomCenter
164
+ ) {
165
+ Column {
166
+ Box(
167
+ modifier = Modifier
168
+ .height(72.dp)
169
+ .fillMaxWidth()
170
+ .pointerInput(Unit) {
171
+ detectDragGestures(
172
+ onDrag = { change, dragAmount ->
173
+ change.consume()
174
+ coroutineScope.launch {
175
+ val newOffset = (sheetOffset.value + dragAmount.y).coerceAtLeast(0f)
176
+ sheetOffset.snapTo(newOffset)
177
+ }
178
+ },
179
+ onDragEnd = {
180
+ coroutineScope.launch {
181
+ if (sheetOffset.value > sheetCloseOffset) {
182
+ closeEvent()
183
+ } else {
184
+ sheetOffset.animateTo(0f)
185
+ }
186
+ }
187
+ }
188
+ )
189
+ }
190
+ ) {
191
+ Column(
192
+ modifier = Modifier
193
+ .fillMaxSize()
194
+ .padding(horizontal = Spacing.M),
195
+ horizontalAlignment = Alignment.CenterHorizontally
196
+ ) {
197
+ Spacer(Modifier.height(8.dp))
198
+ Box(
199
+ modifier = Modifier
200
+ .height(4.dp)
201
+ .width(40.dp)
202
+ .background(
203
+ color = Colors.black_06,
204
+ shape = RoundedCornerShape(Radius.S)
205
+ )
206
+ )
207
+ Spacer(Modifier.height(4.dp))
208
+ Box(Modifier.fillMaxWidth().height(56.dp), contentAlignment = Alignment.Center){
209
+ when (header) {
210
+ is BottomHeader.Title -> {
211
+ Row(modifier = Modifier.fillMaxSize(), verticalAlignment = Alignment.CenterVertically) {
212
+ Box(Modifier.size(24.dp))
213
+ Box(Modifier.fillMaxHeight().weight(1f), contentAlignment = Alignment.Center){
214
+ Text(
215
+ text = header.data,
216
+ color = Colors.black_17,
217
+ style = Typography.headerDefaultBold
218
+ )
219
+ }
220
+ Box(Modifier
221
+ .size(24.dp)
222
+ .noFeedbackClickable {
223
+ closeEvent()
224
+ },
225
+ contentAlignment = Alignment.Center
226
+ ){
227
+ Icon(source = "navigation_close")
228
+ }
229
+ }
230
+ }
231
+ is BottomHeader.Custom -> {
232
+ header.content()
233
+ }
234
+ }
235
+ }
236
+ }
237
+ }
238
+ Divider()
239
+ content()
240
+ }
241
+ }
242
+ }
243
+ }
244
+
245
+ sealed class BottomHeader {
246
+ data class Title(
247
+ val data: String = "Bottom Sheet Title",
248
+ ) : BottomHeader()
249
+
250
+ data class Custom(
251
+ val content: @Composable () -> Unit
252
+ ) : BottomHeader()
253
+ }
@@ -0,0 +1,129 @@
1
+ package vn.momo.kits.navigation
2
+
3
+ import androidx.compose.animation.core.Animatable
4
+ import androidx.compose.animation.core.CubicBezierEasing
5
+ import androidx.compose.animation.core.tween
6
+ import androidx.compose.foundation.background
7
+ import androidx.compose.foundation.border
8
+ import androidx.compose.foundation.clickable
9
+ import androidx.compose.foundation.interaction.MutableInteractionSource
10
+ import androidx.compose.foundation.layout.Box
11
+ import androidx.compose.foundation.layout.fillMaxSize
12
+ import androidx.compose.foundation.layout.wrapContentSize
13
+ import androidx.compose.runtime.*
14
+ import androidx.compose.ui.Alignment
15
+ import androidx.compose.ui.Modifier
16
+ import androidx.compose.ui.draw.alpha
17
+ import androidx.compose.ui.draw.scale
18
+ import androidx.compose.ui.graphics.Color
19
+ import androidx.compose.ui.unit.dp
20
+ import kotlinx.coroutines.launch
21
+ import vn.momo.kits.application.ApplicationContext
22
+ import vn.momo.kits.application.IsShowBaseLineDebug
23
+ import vn.momo.kits.const.Colors
24
+ import vn.momo.kits.modifier.conditional
25
+ import vn.momo.kits.modifier.noFeedbackClickable
26
+ import vn.momo.kits.navigation.tracking.ScreenTracker
27
+ import vn.momo.kits.platform.BackHandler
28
+
29
+ @Composable
30
+ internal fun ModalScreen(
31
+ content: @Composable () -> Unit,
32
+ barrierDismissible: Boolean = true,
33
+ onDismiss: (() -> Unit)? = null
34
+ ) {
35
+ val navigator = LocalNavigator.current
36
+
37
+ val alpha = remember { Animatable(0f) }
38
+ val scale = remember { Animatable(0.8f) }
39
+
40
+ val coroutineScope = rememberCoroutineScope()
41
+
42
+ val maxApi = LocalMaxApi.current
43
+ val context = ApplicationContext.current
44
+
45
+ DisposableEffect(Unit) {
46
+ ScreenTracker.trackPopupDisplayed(
47
+ maxApi = maxApi,
48
+ context = context,
49
+ parentScreenName = ScreenTracker.getLastScreenName()
50
+ )
51
+ onDispose { }
52
+ }
53
+
54
+ fun openEvent() {
55
+ coroutineScope.launch {
56
+ launch {
57
+ alpha.animateTo(
58
+ targetValue = 1f,
59
+ animationSpec = tween(durationMillis = 250)
60
+ )
61
+ }
62
+ launch {
63
+ scale.animateTo(
64
+ targetValue = 1f,
65
+ animationSpec = tween(
66
+ durationMillis = 250,
67
+ easing = CubicBezierEasing(0.2f, 0.0f, 0f, 1f)
68
+ )
69
+ )
70
+ }
71
+ }
72
+ }
73
+
74
+ fun closeEvent() {
75
+ coroutineScope.launch {
76
+ alpha.animateTo(
77
+ targetValue = 0f,
78
+ animationSpec = tween(durationMillis = 200)
79
+ )
80
+ scale.animateTo(
81
+ targetValue = 0.8f,
82
+ animationSpec = tween(durationMillis = 200)
83
+ )
84
+ navigator.pop()
85
+ }
86
+ }
87
+
88
+ LaunchedEffect(Unit) {
89
+ openEvent()
90
+ }
91
+
92
+ DisposableEffect(Unit) {
93
+ OverplayComponentRegistry.bindClose { closeEvent() }
94
+ onDispose {
95
+ onDismiss?.invoke()
96
+ }
97
+ }
98
+
99
+ BackHandler(enabled = true) {
100
+ closeEvent()
101
+ }
102
+
103
+ Box(
104
+ modifier = Modifier
105
+ .fillMaxSize()
106
+ .background(Color.Black.copy(alpha = 0.6f * alpha.value))
107
+ .noFeedbackClickable {
108
+ if(barrierDismissible) closeEvent()
109
+ },
110
+ contentAlignment = Alignment.Center
111
+ ) {
112
+ Box(
113
+ modifier = Modifier
114
+ .scale(scale.value)
115
+ .alpha(alpha.value)
116
+ .wrapContentSize()
117
+ .conditional(IsShowBaseLineDebug) {
118
+ border(1.dp, Colors.blue_03)
119
+ }
120
+ .clickable(
121
+ indication = null,
122
+ interactionSource = remember { MutableInteractionSource() }
123
+ ) {},
124
+ contentAlignment = Alignment.Center
125
+ ) {
126
+ content()
127
+ }
128
+ }
129
+ }
@@ -0,0 +1,94 @@
1
+ package vn.momo.kits.navigation
2
+
3
+ import androidx.compose.foundation.gestures.ScrollableState
4
+ import androidx.compose.runtime.*
5
+ import androidx.compose.ui.graphics.Color
6
+ import vn.momo.kits.navigation.bottomtab.setBottomTabOption
7
+ import vn.momo.kits.navigation.component.*
8
+
9
+ class Navigation(
10
+ val id: Int = -1,
11
+ val bottomTabIndex: Int = -1,
12
+ val initOptions: NavigationOptions? = null,
13
+ private val registry: DynamicScreenRegistry? = null
14
+ ) {
15
+ private val _options = mutableStateOf(initOptions ?: NavigationOptions())
16
+ val currentOptions: State<NavigationOptions> get() = _options
17
+ val options: NavigationOptions get() = _options.value
18
+
19
+ fun setOptions(
20
+ onBackHandler: (() -> Unit)? = null,
21
+ hiddenBack: Boolean? = null,
22
+ headerBackProps: HeaderBackProps? = null,
23
+ headerTitle: HeaderTitle? = null,
24
+ titlePosition: TitlePosition? = null,
25
+ headerRight: HeaderRight? = null,
26
+ headerType: HeaderType? = null,
27
+ scrollData: ScrollData? = null,
28
+ backgroundColor: Color? = null,
29
+ tintColor: Color? = null,
30
+ footerComponent: (@Composable () -> Unit)? = null,
31
+ floatingButtonProps: FloatingButtonProps? = null,
32
+ keyboardOptions: KeyboardOptions? = null
33
+ ) {
34
+ updateOptions(
35
+ options.copy(
36
+ onBackHandler = onBackHandler ?: options.onBackHandler,
37
+ hiddenBack = hiddenBack ?: options.hiddenBack,
38
+ headerBackProps = headerBackProps ?: options.headerBackProps,
39
+ headerTitle = headerTitle ?: options.headerTitle,
40
+ titlePosition = titlePosition ?: options.titlePosition,
41
+ headerRight = headerRight ?: options.headerRight,
42
+ headerType = headerType ?: options.headerType,
43
+ scrollData = scrollData ?: options.scrollData,
44
+ backgroundColor = backgroundColor ?: options.backgroundColor,
45
+ tintColor = tintColor ?: options.tintColor,
46
+ footerComponent = footerComponent ?: options.footerComponent,
47
+ floatingButtonProps = floatingButtonProps ?: options.floatingButtonProps,
48
+ keyboardOptions = keyboardOptions ?: options.keyboardOptions,
49
+ )
50
+ )
51
+ }
52
+
53
+ fun setOptions(newOptions: NavigationOptions) {
54
+ updateOptions(newOptions)
55
+ }
56
+
57
+ private fun updateOptions(updated: NavigationOptions) {
58
+ _options.value = updated
59
+ if (bottomTabIndex != -1) setBottomTabOption(bottomTabIndex, updated)
60
+ if (id != -1) registry?.setOptions(id, updated)
61
+ }
62
+ }
63
+
64
+ val LocalNavigation = staticCompositionLocalOf<Navigation> {
65
+ error("No NavigationStack provided")
66
+ }
67
+
68
+ @Stable
69
+ data class NavigationOptions(
70
+ val screenName: String? = null,
71
+ val onBackHandler: (() -> Unit)? = null,
72
+ val hiddenBack: Boolean = false,
73
+ val headerBackProps: HeaderBackProps = HeaderBackProps(),
74
+ val headerTitle: HeaderTitle = HeaderTitle.Default("Stack"),
75
+ val titlePosition: TitlePosition = TitlePosition.LEFT,
76
+ val headerRight: HeaderRight = HeaderRight.Toolkit(),
77
+ val headerType: HeaderType = HeaderType.Default(),
78
+ val scrollData: ScrollData = ScrollData(),
79
+ val backgroundColor: Color? = null,
80
+ val tintColor: Color? = null,
81
+ val footerComponent: @Composable (() -> Unit)? = null,
82
+ val floatingButtonProps: FloatingButtonProps? = null,
83
+ val keyboardOptions: KeyboardOptions = KeyboardOptions()
84
+ )
85
+
86
+ data class KeyboardOptions(
87
+ val keyboardShouldPersistTaps: Boolean = false,
88
+ val useAvoidKeyboard: Boolean = true
89
+ )
90
+ data class ScrollData(
91
+ val scrollable: Boolean = true,
92
+ val scrollState: ScrollableState? = null,
93
+ val scrollToTopCallback: (() -> Unit)? = null,
94
+ )
@@ -0,0 +1,163 @@
1
+ package vn.momo.kits.navigation
2
+
3
+ import androidx.compose.animation.*
4
+ import androidx.compose.animation.core.tween
5
+ import androidx.compose.runtime.*
6
+ import androidx.compose.runtime.saveable.rememberSaveable
7
+ import androidx.compose.ui.unit.Dp
8
+ import androidx.navigation.NavController
9
+ import androidx.navigation.compose.NavHost
10
+ import androidx.navigation.compose.composable
11
+ import androidx.navigation.compose.rememberNavController
12
+ import androidx.navigation.toRoute
13
+ import vn.momo.kits.application.*
14
+ import vn.momo.kits.const.*
15
+ import vn.momo.kits.platform.ProvideNavigationEventDispatcherOwner
16
+ import vn.momo.kits.utils.getAppStatusBarHeight
17
+ import vn.momo.kits.utils.getNavigationBarHeight
18
+ import vn.momo.maxapi.IMaxApi
19
+
20
+ @Composable
21
+ fun NavigationContainer(
22
+ initialScreenName: String,
23
+ initialScreen: @Composable () -> Unit,
24
+ options: NavigationOptions? = null,
25
+ initialTheme: Theme = defaultTheme,
26
+ applicationContext: MiniAppContext? = null,
27
+ maxApi: IMaxApi? = null,
28
+ setNavigator: ((Navigator) -> Unit)? = null,
29
+ statusBarHeight: Dp? = null,
30
+ config: KitConfig? = null,
31
+ language: String? = null,
32
+ onNavigationEvent: ((NavigationEvent) -> Unit)? = null
33
+ ){
34
+ val navController = rememberNavController()
35
+ val registry = remember { DynamicScreenRegistry() }
36
+ val navigator = remember { Navigator(navController = navController, maxApi = maxApi, registry = registry, onNavigationEvent = onNavigationEvent) }
37
+
38
+ val recomposeCount = remember { mutableStateOf(0) }
39
+ SideEffect {
40
+ recomposeCount.value += 1
41
+ onNavigationEvent?.invoke(NavigationEvent.ContainerRecompose(recomposeCount.value))
42
+ }
43
+ val statusBarHeight = statusBarHeight ?: getAppStatusBarHeight()
44
+ val navigationBarHeight = getNavigationBarHeight()
45
+
46
+ val parentContext = ApplicationContext.current
47
+ val mergedContext = MiniAppContext.merge(parentContext, applicationContext)
48
+
49
+ val theme = remember { mutableStateOf(initialTheme) }
50
+
51
+ LaunchedEffect(Unit) {
52
+ val headerBar = config?.headerBar
53
+ if (headerBar != null && theme.value.assets.headerBackground == null) {
54
+ theme.value = theme.value.copy(
55
+ assets = ThemeAssets(
56
+ headerBackground = headerBar
57
+ )
58
+ )
59
+ }
60
+ }
61
+
62
+ val screenId = rememberSaveable { registry.nextId() }
63
+ registry.bind(screenId, initialScreenName, initialScreen, options)
64
+ val startDestination = remember(screenId) { DynamicScreenRoute(screenId) }
65
+
66
+ ProvideNavigationEventDispatcherOwner {
67
+ CompositionLocalProvider(
68
+ LocalNavigator provides navigator,
69
+ LocalDynamicScreenRegistry provides registry,
70
+ LocalMaxApi provides maxApi,
71
+ AppTheme provides theme.value,
72
+ AppStatusBar provides statusBarHeight,
73
+ AppNavigationBar provides navigationBarHeight,
74
+ ApplicationContext provides mergedContext,
75
+ AppConfig provides config,
76
+ AppLanguage provides language,
77
+ ScaleSizeMaxRate provides mergedContext?.scaleSizeMaxRate,
78
+ ) {
79
+ LaunchedEffect(Unit) {
80
+ setNavigator?.invoke(navigator)
81
+ }
82
+
83
+ NavHost(navController, startDestination = startDestination) {
84
+ composable<DynamicScreenRoute>(
85
+ enterTransition = {
86
+ slideInHorizontally(
87
+ animationSpec = tween(300),
88
+ initialOffsetX = { it }
89
+ )
90
+ },
91
+ exitTransition = null,
92
+ popEnterTransition = { fadeIn(animationSpec = tween(0)) },
93
+ popExitTransition = {
94
+ slideOutHorizontally(
95
+ animationSpec = tween(300),
96
+ targetOffsetX = { it }
97
+ )
98
+ }
99
+ ) { backStackEntry ->
100
+ val route = backStackEntry.toRoute<DynamicScreenRoute>()
101
+ val screen = registry.getScreen(route.id)
102
+
103
+ if (screen != null) {
104
+ StackScreen(
105
+ id = route.id,
106
+ name = screen.name,
107
+ content = screen.content,
108
+ navigationOptions = screen.options
109
+ )
110
+ }
111
+ }
112
+
113
+ composable<DynamicDialogRoute>(
114
+ enterTransition = {
115
+ slideInVertically(
116
+ animationSpec = tween(300),
117
+ initialOffsetY = { it }
118
+ )
119
+ },
120
+ exitTransition = null,
121
+ popEnterTransition = { fadeIn(animationSpec = tween(0)) },
122
+ popExitTransition = {
123
+ slideOutVertically(
124
+ animationSpec = tween(300),
125
+ targetOffsetY = { it }
126
+ )
127
+ }
128
+ ) { backStackEntry ->
129
+ val route = backStackEntry.toRoute<DynamicDialogRoute>()
130
+ val screen = registry.getScreen(route.id)
131
+
132
+ if (screen != null) {
133
+ StackScreen(
134
+ id = route.id,
135
+ name = screen.name,
136
+ content = screen.content,
137
+ navigationOptions = screen.options
138
+ )
139
+ }
140
+ }
141
+ }
142
+ }
143
+ }
144
+
145
+ DisposableEffect(navController) {
146
+ val listener = NavController.OnDestinationChangedListener { _, destination, _ ->
147
+ val current = registry.getLatestScreen()
148
+ onNavigationEvent?.invoke(
149
+ NavigationEvent.DestinationChanged(destination.route, current?.id, current?.name)
150
+ )
151
+ }
152
+ navController.addOnDestinationChangedListener(listener)
153
+ onDispose {
154
+ navController.removeOnDestinationChangedListener(listener)
155
+ navigator.dispose()
156
+ registry.unregisterScreen(screenId)
157
+ }
158
+ }
159
+ }
160
+
161
+ val LocalMaxApi = staticCompositionLocalOf<IMaxApi?> {
162
+ error("No MaxApi provided")
163
+ }
@@ -0,0 +1,53 @@
1
+ package vn.momo.kits.navigation
2
+
3
+ sealed class NavigationEvent {
4
+ abstract val label: String
5
+
6
+ data class Push(val screenName: String, val id: Int) : NavigationEvent() {
7
+ override val label get() = "Push(screen=$screenName, id=$id)"
8
+ }
9
+
10
+ data class Replace(val screenName: String, val id: Int) : NavigationEvent() {
11
+ override val label get() = "Replace(screen=$screenName, id=$id)"
12
+ }
13
+
14
+ data class Pop(val count: Int, val overlayType: OverplayComponentType?) : NavigationEvent() {
15
+ override val label get() = "Pop(count=$count, overlay=$overlayType)"
16
+ }
17
+
18
+ data class Present(val screenName: String, val id: Int) : NavigationEvent() {
19
+ override val label get() = "Present(screen=$screenName, id=$id)"
20
+ }
21
+
22
+ data class Reset(val screenName: String, val id: Int) : NavigationEvent() {
23
+ override val label get() = "Reset(screen=$screenName, id=$id)"
24
+ }
25
+
26
+ data class ShowModal(val parentId: Int, val barrierDismissible: Boolean) : NavigationEvent() {
27
+ override val label get() = "ShowModal(parentId=$parentId, barrierDismissible=$barrierDismissible)"
28
+ }
29
+
30
+ data class ShowBottomSheet(val parentId: Int, val barrierDismissible: Boolean) : NavigationEvent() {
31
+ override val label get() = "ShowBottomSheet(parentId=$parentId, barrierDismissible=$barrierDismissible)"
32
+ }
33
+
34
+ data class ShowSnackBar(val parentId: Int) : NavigationEvent() {
35
+ override val label get() = "ShowSnackBar(parentId=$parentId)"
36
+ }
37
+
38
+ data class DestinationChanged(
39
+ val route: String?,
40
+ val id: Int?,
41
+ val screenName: String?
42
+ ) : NavigationEvent() {
43
+ override val label get() = "DestinationChanged(route=$route, id=$id, screen=$screenName)"
44
+ }
45
+
46
+ data class ContainerRecompose(val recomposeCount: Int) : NavigationEvent() {
47
+ override val label get() = "ContainerRecompose(count=$recomposeCount)"
48
+ }
49
+
50
+ object Dispose : NavigationEvent() {
51
+ override val label get() = "Dispose"
52
+ }
53
+ }