@momo-kits/native-kits 0.169.13-debug → 0.169.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/package.json +1 -1
  2. package/build.gradle.kts +0 -11
  3. package/compose/build.gradle.kts +0 -198
  4. package/compose/compose.podspec +0 -47
  5. package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +0 -19
  6. package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +0 -6
  7. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/BackGesture.android.kt +0 -12
  8. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +0 -7
  9. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +0 -154
  10. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +0 -17
  11. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReservedRegions.android.kt +0 -6
  12. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +0 -110
  13. package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +0 -61
  14. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +0 -1067
  15. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +0 -268
  16. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +0 -56
  17. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +0 -157
  18. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +0 -81
  19. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +0 -32
  20. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +0 -338
  21. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +0 -175
  22. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +0 -354
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +0 -115
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +0 -89
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +0 -130
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +0 -209
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +0 -482
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +0 -49
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +0 -86
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +0 -125
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +0 -224
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +0 -137
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +0 -473
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +0 -113
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +0 -262
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +0 -237
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +0 -228
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +0 -280
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +0 -183
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +0 -342
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +0 -108
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +0 -56
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +0 -40
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +0 -82
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +0 -39
  46. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +0 -362
  47. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +0 -108
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +0 -304
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +0 -59
  50. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +0 -87
  51. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +0 -21
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +0 -88
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +0 -308
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +0 -218
  55. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +0 -456
  56. package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +0 -122
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +0 -205
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +0 -89
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +0 -542
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +0 -86
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +0 -175
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +0 -201
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +0 -498
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +0 -176
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +0 -182
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +0 -193
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +0 -29
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +0 -208
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +0 -180
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +0 -325
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +0 -12
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +0 -12
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +0 -16
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +0 -194
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +0 -291
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +0 -54
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/HeaderLayout.kt +0 -71
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +0 -50
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +0 -184
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +0 -315
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +0 -41
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +0 -54
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +0 -66
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +0 -11
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +0 -104
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +0 -48
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +0 -51
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +0 -397
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/HostBackGestureBridge.kt +0 -58
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +0 -153
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +0 -118
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +0 -206
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +0 -421
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +0 -8
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +0 -750
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +0 -152
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +0 -35
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +0 -242
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +0 -406
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +0 -111
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +0 -93
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +0 -208
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +0 -133
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +0 -167
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +0 -446
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +0 -105
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderJourney.kt +0 -106
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderLocation.kt +0 -74
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +0 -400
  110. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +0 -39
  111. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +0 -363
  112. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +0 -197
  113. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +0 -133
  114. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +0 -127
  115. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +0 -12
  116. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +0 -114
  117. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +0 -7
  118. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +0 -76
  119. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +0 -7
  120. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +0 -21
  121. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +0 -1329
  122. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +0 -55
  123. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +0 -15
  124. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +0 -117
  125. package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +0 -42
  126. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/HostBackGesture.ios.kt +0 -45
  127. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +0 -32
  128. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/BackGesture.ios.kt +0 -38
  129. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +0 -65
  130. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +0 -217
  131. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +0 -48
  132. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +0 -143
  133. package/gradle/libs.versions.toml +0 -67
  134. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  135. package/gradle/wrapper/gradle-wrapper.properties +0 -8
  136. package/gradle.properties +0 -24
  137. package/gradlew +0 -252
  138. package/gradlew.bat +0 -94
  139. package/ios-demo/README.md +0 -120
  140. package/settings.gradle.kts +0 -64
@@ -1,104 +0,0 @@
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
- }
@@ -1,48 +0,0 @@
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
- )
@@ -1,51 +0,0 @@
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
- }
@@ -1,397 +0,0 @@
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
- }
@@ -1,58 +0,0 @@
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
- }