@momo-kits/native-kits 0.168.1-beta.38 → 0.168.1-beta.39-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 (153) hide show
  1. package/CLAUDE.md +3 -2
  2. package/build.gradle.kts +11 -0
  3. package/compose/build.gradle.kts +198 -0
  4. package/compose/build.gradle.kts.backup +198 -0
  5. package/compose/compose.podspec +47 -0
  6. package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +20 -0
  7. package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +6 -0
  8. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/BackGesture.android.kt +12 -0
  9. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +7 -0
  10. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +154 -0
  11. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +17 -0
  12. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReservedRegions.android.kt +6 -0
  13. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +110 -0
  14. package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +62 -0
  15. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +1071 -0
  16. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +269 -0
  17. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +56 -0
  18. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +157 -0
  19. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +81 -0
  20. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +32 -0
  21. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +338 -0
  22. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +175 -0
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +357 -0
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +115 -0
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +89 -0
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +128 -0
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +209 -0
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +542 -0
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +49 -0
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +86 -0
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +125 -0
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +231 -0
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +189 -0
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +478 -0
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +114 -0
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +265 -0
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +235 -0
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +223 -0
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +265 -0
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +185 -0
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +343 -0
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +108 -0
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +56 -0
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +41 -0
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +84 -0
  46. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +40 -0
  47. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +361 -0
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +108 -0
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +308 -0
  50. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +59 -0
  51. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +87 -0
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +21 -0
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +90 -0
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +330 -0
  55. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +220 -0
  56. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +473 -0
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +122 -0
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +207 -0
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +92 -0
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +560 -0
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +86 -0
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +125 -0
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +207 -0
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +501 -0
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +176 -0
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +182 -0
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +193 -0
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +29 -0
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +236 -0
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +180 -0
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +325 -0
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +17 -0
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +12 -0
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +16 -0
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +194 -0
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +287 -0
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +54 -0
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +50 -0
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +187 -0
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +316 -0
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +41 -0
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +52 -0
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +66 -0
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +11 -0
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +104 -0
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +48 -0
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +51 -0
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +393 -0
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/HostBackGestureBridge.kt +58 -0
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +153 -0
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +113 -0
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +205 -0
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +422 -0
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +8 -0
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +739 -0
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +148 -0
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +35 -0
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +239 -0
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +389 -0
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +94 -0
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +97 -0
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +203 -0
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +104 -0
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +169 -0
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +455 -0
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +105 -0
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderJourney.kt +106 -0
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderLocation.kt +74 -0
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +399 -0
  110. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +39 -0
  111. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +363 -0
  112. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +192 -0
  113. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +133 -0
  114. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +127 -0
  115. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +12 -0
  116. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +92 -0
  117. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +9 -0
  118. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +76 -0
  119. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +7 -0
  120. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +22 -0
  121. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +1329 -0
  122. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +55 -0
  123. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +15 -0
  124. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +118 -0
  125. package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +42 -0
  126. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/HostBackGesture.ios.kt +45 -0
  127. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +32 -0
  128. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/BackGesture.ios.kt +38 -0
  129. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +66 -0
  130. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +219 -0
  131. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +48 -0
  132. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +144 -0
  133. package/gradle/libs.versions.toml +69 -0
  134. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  135. package/gradle/wrapper/gradle-wrapper.properties +8 -0
  136. package/gradle.properties +26 -0
  137. package/gradlew +252 -0
  138. package/gradlew.bat +94 -0
  139. package/ios/Input/Input.swift +3 -1
  140. package/ios/Input/InputTextArea.swift +3 -1
  141. package/ios/Layout/ModalLayout.swift +152 -0
  142. package/ios/Layout/ScreenLayout.swift +28 -24
  143. package/ios/Navigation/BottomSheet.swift +29 -157
  144. package/ios/Navigation/Component/HeaderRight.swift +1 -1
  145. package/ios/Navigation/ModalScreen.swift +18 -7
  146. package/ios/Popup/PopupDisplay.swift +4 -2
  147. package/ios/Popup/PopupInput.swift +4 -2
  148. package/ios/Popup/PopupLayout.swift +10 -9
  149. package/ios/Popup/PopupNotify.swift +26 -23
  150. package/ios-demo/README.md +120 -0
  151. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/NavigationDemo.swift +103 -0
  152. package/package.json +1 -1
  153. package/settings.gradle.kts +64 -0
@@ -0,0 +1,104 @@
1
+ package vn.momo.kits.modifier
2
+
3
+ import androidx.compose.animation.core.LinearEasing
4
+ import androidx.compose.animation.core.RepeatMode
5
+ import androidx.compose.animation.core.animateFloat
6
+ import androidx.compose.animation.core.infiniteRepeatable
7
+ import androidx.compose.animation.core.rememberInfiniteTransition
8
+ import androidx.compose.animation.core.tween
9
+ import androidx.compose.runtime.Composable
10
+ import androidx.compose.runtime.getValue
11
+ import androidx.compose.ui.Modifier
12
+ import androidx.compose.ui.draw.drawWithContent
13
+ import androidx.compose.ui.geometry.Offset
14
+ import androidx.compose.ui.graphics.Color
15
+ import androidx.compose.ui.graphics.drawscope.clipRect
16
+ import androidx.compose.ui.text.TextStyle
17
+ import androidx.compose.ui.text.drawText
18
+ import androidx.compose.ui.text.font.FontWeight
19
+ import androidx.compose.ui.text.rememberTextMeasurer
20
+ import androidx.compose.ui.unit.sp
21
+ import vn.momo.kits.application.IsShowBaseLineDebug
22
+ import vn.momo.kits.const.Colors
23
+
24
+ @Suppress("ExperimentalAnnotationRetention")
25
+ @RequiresOptIn(
26
+ message = "This is internal API of native-kits, become internal in next sprint",
27
+ level = RequiresOptIn.Level.WARNING,
28
+ )
29
+ @Retention(AnnotationRetention.BINARY)
30
+ @Target(
31
+ AnnotationTarget.CLASS,
32
+ AnnotationTarget.FUNCTION,
33
+ AnnotationTarget.PROPERTY,
34
+ )
35
+ annotation class InternalApi
36
+
37
+ @Composable
38
+ fun DeprecatedModifier(text: String = "Deprecated component"): Modifier = debugMarker(
39
+ label = text,
40
+ background = Colors.red_04.copy(alpha = 0.7f),
41
+ textColor = Colors.red_01,
42
+ animationLabel = "deprecatedMarquee",
43
+ )
44
+
45
+ @Composable
46
+ private fun debugMarker(
47
+ label: String,
48
+ background: Color,
49
+ textColor: Color,
50
+ animationLabel: String,
51
+ ): Modifier {
52
+ if (!IsShowBaseLineDebug) return Modifier
53
+
54
+ val textMeasurer = rememberTextMeasurer()
55
+ val marquee = rememberInfiniteTransition(label = animationLabel)
56
+ val progress by marquee.animateFloat(
57
+ initialValue = 0f,
58
+ targetValue = 1f,
59
+ animationSpec = infiniteRepeatable(
60
+ animation = tween(durationMillis = 4000, easing = LinearEasing),
61
+ repeatMode = RepeatMode.Restart,
62
+ ),
63
+ label = "${animationLabel}Progress",
64
+ )
65
+
66
+ return Modifier.drawWithContent {
67
+ drawContent()
68
+ drawRect(color = background)
69
+
70
+ if (size.width <= 0f || size.height <= 0f) return@drawWithContent
71
+
72
+ val fontPx = (size.width * 0.1f).coerceIn(12.sp.toPx(), 20.sp.toPx())
73
+ val style = TextStyle(
74
+ color = textColor,
75
+ fontSize = fontPx.toSp(),
76
+ fontWeight = FontWeight.Bold,
77
+ )
78
+
79
+ val intrinsic = textMeasurer.measure(
80
+ text = label,
81
+ style = style,
82
+ maxLines = 1,
83
+ softWrap = false,
84
+ )
85
+ val textW = intrinsic.size.width
86
+ val textH = intrinsic.size.height
87
+ val y = (size.height - textH) / 2f
88
+
89
+ if (textW <= size.width) {
90
+ drawText(
91
+ textLayoutResult = intrinsic,
92
+ topLeft = Offset((size.width - textW) / 2f, y),
93
+ )
94
+ } else {
95
+ clipRect(right = size.width, bottom = size.height) {
96
+ val gap = textW * 0.5f
97
+ val travel = textW + gap
98
+ val x = -progress * travel
99
+ drawText(textLayoutResult = intrinsic, topLeft = Offset(x, y))
100
+ drawText(textLayoutResult = intrinsic, topLeft = Offset(x + travel, y))
101
+ }
102
+ }
103
+ }
104
+ }
@@ -0,0 +1,48 @@
1
+ package vn.momo.kits.modifier
2
+
3
+ import androidx.compose.ui.Modifier
4
+ import androidx.compose.ui.draw.drawBehind
5
+ import androidx.compose.ui.graphics.Color
6
+ import androidx.compose.ui.graphics.Paint
7
+ import androidx.compose.ui.graphics.drawscope.drawIntoCanvas
8
+ import androidx.compose.ui.unit.Dp
9
+ import androidx.compose.ui.unit.dp
10
+ import vn.momo.kits.platform.setColor
11
+ import vn.momo.kits.platform.setMaskFilter
12
+ fun Modifier.shadow(
13
+ color: Color = Color.Black,
14
+ borderRadius: Dp = 0.dp,
15
+ blurRadius: Float = 0f,
16
+ offsetY: Dp = 0.dp,
17
+ offsetX: Dp = 0.dp,
18
+ spread: Dp = 0f.dp,
19
+ modifier: Modifier = Modifier
20
+ ) = this.then(
21
+ modifier.drawBehind {
22
+ this.drawIntoCanvas {
23
+ val paint = Paint()
24
+ val frameworkPaint = paint.asFrameworkPaint()
25
+ val spreadPixel = spread.toPx()
26
+ val leftPixel = (0f - spreadPixel) + offsetX.toPx()
27
+ val topPixel = (0f - spreadPixel) + offsetY.toPx()
28
+ val rightPixel = (this.size.width + spreadPixel)
29
+ val bottomPixel = (0f + spreadPixel) - offsetY.toPx()
30
+
31
+ if (blurRadius != 0f) {
32
+ frameworkPaint.setMaskFilter(blurRadius)
33
+ }
34
+
35
+ frameworkPaint.setColor(color)
36
+
37
+ it.drawRoundRect(
38
+ left = leftPixel,
39
+ top = topPixel,
40
+ right = rightPixel,
41
+ bottom = bottomPixel,
42
+ radiusX = borderRadius.toPx(),
43
+ radiusY = borderRadius.toPx(),
44
+ paint
45
+ )
46
+ }
47
+ }
48
+ )
@@ -0,0 +1,51 @@
1
+ package vn.momo.kits.modifier
2
+
3
+ import androidx.compose.runtime.Composable
4
+ import androidx.compose.runtime.State
5
+ import androidx.compose.ui.Modifier
6
+ import androidx.compose.ui.layout.Measurable
7
+ import androidx.compose.ui.layout.MeasureResult
8
+ import androidx.compose.ui.layout.MeasureScope
9
+ import androidx.compose.ui.node.LayoutModifierNode
10
+ import androidx.compose.ui.node.ModifierNodeElement
11
+ import androidx.compose.ui.unit.Constraints
12
+ import androidx.compose.ui.unit.IntOffset
13
+
14
+ @Composable
15
+ fun Modifier.dynamicSize(
16
+ widthState: State<Int>? = null,
17
+ heightState: State<Int>? = null,
18
+ ) = this then DynamicSizeElement(widthState, heightState)
19
+
20
+ private data class DynamicSizeElement(
21
+ val widthState: State<Int>?,
22
+ val heightState: State<Int>?,
23
+ ) : ModifierNodeElement<DynamicSizeNode>() {
24
+ override fun create(): DynamicSizeNode {
25
+ return DynamicSizeNode(widthState, heightState)
26
+ }
27
+
28
+ override fun update(node: DynamicSizeNode) {
29
+ node.widthState = widthState
30
+ node.heightState = heightState
31
+ }
32
+
33
+ }
34
+
35
+ private class DynamicSizeNode(
36
+ var widthState: State<Int>?,
37
+ var heightState: State<Int>?,
38
+ ) : Modifier.Node(), LayoutModifierNode {
39
+ override fun MeasureScope.measure(
40
+ measurable: Measurable,
41
+ constraints: Constraints
42
+ ): MeasureResult {
43
+ val p = measurable.measure(constraints)
44
+ return layout(
45
+ width = widthState?.value ?: p.width,
46
+ height = heightState?.value ?: p.height,
47
+ ) {
48
+ p.place(IntOffset.Zero)
49
+ }
50
+ }
51
+ }
@@ -0,0 +1,393 @@
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.Arrangement
10
+ import androidx.compose.foundation.layout.Box
11
+ import androidx.compose.foundation.layout.BoxWithConstraints
12
+ import androidx.compose.foundation.layout.Column
13
+ import androidx.compose.foundation.layout.Row
14
+ import androidx.compose.foundation.layout.Spacer
15
+ import androidx.compose.foundation.layout.fillMaxHeight
16
+ import androidx.compose.foundation.layout.fillMaxSize
17
+ import androidx.compose.foundation.layout.fillMaxWidth
18
+ import androidx.compose.foundation.layout.height
19
+ import androidx.compose.foundation.layout.heightIn
20
+ import androidx.compose.foundation.layout.offset
21
+ import androidx.compose.foundation.layout.padding
22
+ import androidx.compose.foundation.layout.size
23
+ import androidx.compose.foundation.layout.width
24
+ import androidx.compose.foundation.layout.absolutePadding
25
+ import androidx.compose.foundation.shape.RoundedCornerShape
26
+ import androidx.compose.runtime.Composable
27
+ import androidx.compose.runtime.DisposableEffect
28
+ import androidx.compose.runtime.LaunchedEffect
29
+ import androidx.compose.runtime.getValue
30
+ import androidx.compose.runtime.mutableStateOf
31
+ import androidx.compose.runtime.remember
32
+ import androidx.compose.runtime.setValue
33
+ import androidx.compose.runtime.rememberCoroutineScope
34
+ import androidx.compose.ui.Alignment
35
+ import androidx.compose.ui.Modifier
36
+ import androidx.compose.ui.graphics.Brush
37
+ import androidx.compose.ui.graphics.Color
38
+ import androidx.compose.ui.input.pointer.pointerInput
39
+ import androidx.compose.ui.platform.LocalDensity
40
+ import androidx.compose.ui.unit.Density
41
+ import androidx.compose.ui.unit.IntOffset
42
+ import androidx.compose.ui.unit.dp
43
+ import kotlinx.coroutines.launch
44
+ import vn.momo.kits.components.Divider
45
+ import vn.momo.kits.components.Text
46
+ import vn.momo.kits.const.AppTheme
47
+ import vn.momo.kits.const.Colors
48
+ import vn.momo.kits.const.Radius
49
+ import vn.momo.kits.const.Spacing
50
+ import vn.momo.kits.application.LocalContext
51
+ import vn.momo.kits.application.IsShowBaseLineDebug
52
+ import vn.momo.kits.const.AppNavigationBar
53
+ import vn.momo.kits.const.Typography
54
+ import vn.momo.kits.navigation.tracking.ScreenTracker
55
+ import vn.momo.kits.modifier.conditional
56
+ import vn.momo.kits.modifier.noFeedbackClickable
57
+ import vn.momo.kits.platform.BackHandler
58
+ import vn.momo.kits.platform.getScreenHeight
59
+ import vn.momo.kits.layout.MODAL_ICON_BUTTON_SIZE
60
+ import vn.momo.kits.layout.ModalIconButton
61
+ import vn.momo.kits.layout.getScreenLayout
62
+ import vn.momo.kits.layout.rememberModalLayout
63
+
64
+ private val INDICATOR_HEIGHT = 16.dp
65
+ private val HEADER_ROW_HEIGHT = 56.dp
66
+
67
+ // A sheet held at its min height keeps the footer at the bottom; the room goes above it.
68
+ private object FooterAtBottom : Arrangement.Vertical {
69
+ override fun Density.arrange(totalSize: Int, sizes: IntArray, outPositions: IntArray) {
70
+ var y = 0
71
+ sizes.forEachIndexed { index, size ->
72
+ outPositions[index] = y
73
+ y += size
74
+ }
75
+ if (sizes.isNotEmpty()) outPositions[sizes.lastIndex] = maxOf(y - sizes.last(), totalSize - sizes.last())
76
+ }
77
+ }
78
+
79
+ @Composable
80
+ internal fun BottomSheet(
81
+ content: @Composable () -> Unit,
82
+ header: BottomHeader,
83
+ isSurface: Boolean = false,
84
+ barrierDismissible: Boolean = true,
85
+ draggable: Boolean = true,
86
+ useBottomInset: Boolean = true,
87
+ footerComponent: (@Composable () -> Unit)? = null,
88
+ onDismiss: (() -> Unit)?
89
+ ) {
90
+ val layout = getScreenLayout()
91
+ val modal = rememberModalLayout()
92
+ val isFoldable = modal.isFoldable
93
+ val sheet = modal.sheet
94
+ val title = header as? BottomHeader.Title
95
+ // the screen is the outer display on iPhone Duo, even when unfolded
96
+ val screenHeightDp = if (isFoldable) layout.height else getScreenHeight()
97
+ val screenHeightPx = with(LocalDensity.current) { screenHeightDp.toPx() }
98
+ val sheetOffset = remember { Animatable(screenHeightPx) }
99
+
100
+ // half the scrim fades in first, the other half follows the sheet
101
+ val backgroundAlpha = remember { Animatable(0f) }
102
+ val dynamicAlpha = ((1f - (sheetOffset.value / screenHeightPx)).coerceIn(0f, 1f)) * 0.5f
103
+ val alpha = (backgroundAlpha.value + dynamicAlpha) * modal.scrimOpacity
104
+
105
+ val sheetCloseOffset = with(LocalDensity.current) { 100.dp.toPx() }
106
+
107
+ val coroutineScope = rememberCoroutineScope()
108
+
109
+ val maxApi = LocalMaxApi.current
110
+ val context = LocalContext.current
111
+
112
+ DisposableEffect(Unit) {
113
+ ScreenTracker.trackPopupDisplayed(
114
+ maxApi = maxApi,
115
+ context = context,
116
+ parentScreenName = ScreenTracker.getLastScreenName()
117
+ )
118
+ onDispose { }
119
+ }
120
+
121
+ // a closing sheet keeps going: a second close, the open slide or a drag would cancel its animation
122
+ var isClosing by remember { mutableStateOf(false) }
123
+ // runs once the sheet has closed itself, after its onDismiss
124
+ var afterDismiss by remember { mutableStateOf<(() -> Unit)?>(null) }
125
+
126
+ suspend fun openEvent(){
127
+ backgroundAlpha.animateTo(
128
+ targetValue = 0.5f,
129
+ animationSpec = tween(
130
+ durationMillis = 100,
131
+ easing = CubicBezierEasing(0.05f, 0.7f, 0.1f, 1f)
132
+ )
133
+ )
134
+ if (isClosing) return
135
+ sheetOffset.animateTo(
136
+ targetValue = 0f,
137
+ animationSpec = tween(
138
+ durationMillis = 350,
139
+ easing = CubicBezierEasing(0.05f, 0.7f, 0.1f, 1f)
140
+ )
141
+ )
142
+ }
143
+
144
+ fun closeEvent(then: (() -> Unit)? = null){
145
+ if (isClosing) return
146
+ isClosing = true
147
+ coroutineScope.launch {
148
+ sheetOffset.animateTo(
149
+ targetValue = screenHeightPx,
150
+ animationSpec = tween(
151
+ durationMillis = 200,
152
+ easing = CubicBezierEasing(0.3f, 0.0f, 0.8f, 0.15f)
153
+ )
154
+ )
155
+ backgroundAlpha.animateTo(
156
+ targetValue = 0f,
157
+ animationSpec = tween(
158
+ durationMillis = 100,
159
+ easing = CubicBezierEasing(0.3f, 0.0f, 0.8f, 0.15f)
160
+ )
161
+ )
162
+ // not reached when a newer overlay replaced this one, so its back is dropped
163
+ afterDismiss = then
164
+ OverplayComponentRegistry.hardClearAfterDismiss()
165
+ }
166
+ }
167
+
168
+ // RN `leftOptions.onPressIconLeft`: the sheet closes first, then the back runs
169
+ val onBack = title?.onBack?.let { back -> { closeEvent(then = back) } }
170
+
171
+ LaunchedEffect(Unit) {
172
+ openEvent()
173
+ }
174
+
175
+ DisposableEffect(Unit) {
176
+ OverplayComponentRegistry.bindClose { closeEvent() }
177
+ onDispose {
178
+ onDismiss?.invoke()
179
+ afterDismiss?.invoke()
180
+ }
181
+ }
182
+
183
+ BackHandler(true){
184
+ closeEvent()
185
+ }
186
+
187
+ BoxWithConstraints(
188
+ modifier = Modifier
189
+ .fillMaxSize()
190
+ // full screen on foldables too, over the iPhone Duo control column
191
+ .background(Colors.black_20.copy(alpha = alpha))
192
+ .noFeedbackClickable {
193
+ if(barrierDismissible) closeEvent()
194
+ }
195
+ // centered in the placement: off the iPhone Duo control column, the right half when half folded
196
+ .conditional(isFoldable) {
197
+ absolutePadding(left = modal.placement.left, right = layout.width - modal.placement.right)
198
+ }
199
+ ) {
200
+ val parentHeight = with(LocalDensity.current) { constraints.maxHeight.toDp() }
201
+ val maxHeight = sheet.maxHeight ?: (parentHeight - 90.dp)
202
+
203
+ Box(
204
+ modifier = Modifier
205
+ .align(Alignment.BottomCenter)
206
+ .offset { IntOffset(x = 0, y = sheetOffset.value.toInt()) }
207
+ .then(if (sheet.width != null) Modifier.width(sheet.width) else Modifier.fillMaxWidth())
208
+ .heightIn(max = maxHeight)
209
+ .background(
210
+ color = if (isSurface) AppTheme.current.colors.background.surface else AppTheme.current.colors.background.default,
211
+ shape = RoundedCornerShape(topStart = sheet.radius, topEnd = sheet.radius)
212
+ )
213
+ .conditional(IsShowBaseLineDebug) {
214
+ border(1.dp, Colors.blue_03)
215
+ }
216
+ .noFeedbackClickable { },
217
+ contentAlignment = Alignment.BottomCenter
218
+ ) {
219
+ val bottomInset = if (useBottomInset) {
220
+ (AppNavigationBar.current - keyboardSizeState().value).coerceAtLeast(0.dp)
221
+ } else 0.dp
222
+ Column(
223
+ modifier = Modifier.heightIn(min = sheet.minHeight).padding(bottom = bottomInset),
224
+ verticalArrangement = if (footerComponent != null) FooterAtBottom else Arrangement.Top,
225
+ ) {
226
+ Box(
227
+ modifier = Modifier
228
+ .height(INDICATOR_HEIGHT + HEADER_ROW_HEIGHT)
229
+ .fillMaxWidth()
230
+ .conditional(draggable) {
231
+ pointerInput(Unit) {
232
+ detectDragGestures(
233
+ onDrag = { change, dragAmount ->
234
+ change.consume()
235
+ if (isClosing) return@detectDragGestures
236
+ coroutineScope.launch {
237
+ val newOffset = (sheetOffset.value + dragAmount.y).coerceAtLeast(0f)
238
+ sheetOffset.snapTo(newOffset)
239
+ }
240
+ },
241
+ onDragEnd = {
242
+ if (isClosing) return@detectDragGestures
243
+ coroutineScope.launch {
244
+ if (sheetOffset.value > sheetCloseOffset) {
245
+ closeEvent()
246
+ } else {
247
+ sheetOffset.animateTo(0f)
248
+ }
249
+ }
250
+ }
251
+ )
252
+ }
253
+ }
254
+ ) {
255
+ Column(
256
+ modifier = Modifier
257
+ .fillMaxSize()
258
+ .padding(horizontal = Spacing.M),
259
+ horizontalAlignment = Alignment.CenterHorizontally
260
+ ) {
261
+ Spacer(Modifier.height(8.dp))
262
+ Box(
263
+ modifier = Modifier
264
+ .height(4.dp)
265
+ .width(40.dp)
266
+ .background(
267
+ color = Colors.black_06,
268
+ shape = RoundedCornerShape(Radius.S)
269
+ )
270
+ )
271
+ Spacer(Modifier.height(4.dp))
272
+ Box(
273
+ Modifier.fillMaxWidth().height(HEADER_ROW_HEIGHT),
274
+ contentAlignment = Alignment.Center
275
+ ) {
276
+ when (header) {
277
+ is BottomHeader.Title -> BottomSheetTitle(
278
+ text = header.data,
279
+ backIcon = header.backIcon,
280
+ onBack = onBack,
281
+ onClose = { closeEvent() },
282
+ )
283
+ is BottomHeader.Custom -> {
284
+ header.content()
285
+ }
286
+ }
287
+ }
288
+ }
289
+ }
290
+ Divider()
291
+ if (footerComponent != null) {
292
+ Box(Modifier.weight(1f, fill = false)) {
293
+ content()
294
+ }
295
+ BottomSheetFooter(footerComponent)
296
+ } else if (isFoldable) {
297
+ // content shrinks so a tall sheet keeps its header
298
+ Box(Modifier.weight(1f, fill = false)) {
299
+ content()
300
+ }
301
+ } else {
302
+ content()
303
+ }
304
+ }
305
+ }
306
+ }
307
+ }
308
+
309
+ @Composable
310
+ private fun BottomSheetTitle(
311
+ text: String,
312
+ backIcon: String,
313
+ onBack: (() -> Unit)?,
314
+ onClose: () -> Unit,
315
+ ) {
316
+ Row(
317
+ modifier = Modifier.fillMaxSize(),
318
+ horizontalArrangement = Arrangement.spacedBy(Spacing.S),
319
+ verticalAlignment = Alignment.CenterVertically,
320
+ ) {
321
+ if (onBack != null) {
322
+ ModalIconButton(icon = backIcon, automationId = "btn_bottom_sheet_back", onClick = onBack)
323
+ } else {
324
+ Box(Modifier.size(MODAL_ICON_BUTTON_SIZE))
325
+ }
326
+ Box(
327
+ Modifier
328
+ .fillMaxHeight()
329
+ .weight(1f),
330
+ contentAlignment = Alignment.Center
331
+ ) {
332
+ Text(
333
+ text = text,
334
+ color = Colors.black_17,
335
+ style = Typography.headerDefaultBold
336
+ )
337
+ }
338
+ ModalIconButton(icon = "navigation_close", automationId = "btn_bottom_sheet_close", onClick = onClose)
339
+ }
340
+ }
341
+
342
+ @Composable
343
+ private fun BottomSheetFooter(footerComponent: @Composable () -> Unit) {
344
+ val shadowBrush = remember {
345
+ Brush.verticalGradient(
346
+ colors = listOf(Color.Transparent, Color.Black.copy(alpha = 0.05f))
347
+ )
348
+ }
349
+
350
+ Box {
351
+ Box(
352
+ Modifier
353
+ .fillMaxWidth()
354
+ .background(AppTheme.current.colors.background.surface)
355
+ .conditional(IsShowBaseLineDebug) {
356
+ border(1.dp, Colors.blue_03)
357
+ }
358
+ .padding(vertical = Spacing.S)
359
+ ) {
360
+ footerComponent()
361
+ }
362
+
363
+ Box(
364
+ modifier = Modifier
365
+ .fillMaxWidth()
366
+ .height(6.dp)
367
+ .offset(x = 0.dp, y = (-6).dp)
368
+ .background(shadowBrush)
369
+ )
370
+ }
371
+ }
372
+
373
+ sealed class BottomHeader {
374
+ data class Title(
375
+ val data: String = "Bottom Sheet Title",
376
+ ) : BottomHeader() {
377
+ // Outside the primary constructor so code built against older kits keeps Title() and copy().
378
+ // onBack shows a back button: the sheet closes (onDismiss fires), then it runs.
379
+ var onBack: (() -> Unit)? = null
380
+ private set
381
+ var backIcon: String = "arrow-back"
382
+ private set
383
+
384
+ constructor(data: String, onBack: (() -> Unit)?, backIcon: String = "arrow-back") : this(data) {
385
+ this.onBack = onBack
386
+ this.backIcon = backIcon
387
+ }
388
+ }
389
+
390
+ data class Custom(
391
+ val content: @Composable () -> Unit
392
+ ) : BottomHeader()
393
+ }
@@ -0,0 +1,58 @@
1
+ package vn.momo.kits.navigation
2
+
3
+ interface HostBackTarget {
4
+ fun canPop(): Boolean
5
+
6
+ fun onBack()
7
+
8
+ fun backStarted()
9
+ fun backProgressed(progress: Float)
10
+ fun backCompleted()
11
+ fun backCancelled()
12
+ }
13
+
14
+ object HostBackGestureBridge {
15
+ private val targets = mutableListOf<HostBackTarget>()
16
+ private var gestureTarget: HostBackTarget? = null
17
+
18
+ var shouldUseFloatingArrowBack: Boolean = false
19
+
20
+ fun checkCanPop(): Boolean = targets.isNotEmpty()
21
+
22
+ fun canPopInner(): Boolean = top()?.canPop() == true
23
+
24
+ fun pop() {
25
+ top()?.onBack()
26
+ }
27
+
28
+ fun started() {
29
+ val target = top() ?: return
30
+ gestureTarget = target
31
+ target.backStarted()
32
+ }
33
+
34
+ fun progressed(progress: Float) {
35
+ gestureTarget?.backProgressed(progress.coerceIn(0f, 1f))
36
+ }
37
+
38
+ fun completed() {
39
+ (gestureTarget ?: top())?.backCompleted()
40
+ gestureTarget = null
41
+ }
42
+
43
+ fun cancelled() {
44
+ gestureTarget?.backCancelled()
45
+ gestureTarget = null
46
+ }
47
+
48
+ fun attach(target: HostBackTarget) {
49
+ targets += target
50
+ }
51
+
52
+ fun detach(target: HostBackTarget) {
53
+ targets -= target
54
+ if (gestureTarget === target) gestureTarget = null
55
+ }
56
+
57
+ private fun top(): HostBackTarget? = targets.lastOrNull()
58
+ }