@momo-kits/native-kits 0.168.1-beta.35-debug → 0.168.1-beta.36

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