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