@momo-kits/native-kits 0.300.4 → 0.300.5-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 (141) hide show
  1. package/build.gradle.kts +13 -0
  2. package/compose/build.gradle.kts +197 -0
  3. package/compose/build.gradle.kts.backup +197 -0
  4. package/compose/compose.podspec +47 -0
  5. package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +20 -0
  6. package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +6 -0
  7. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/BackGesture.android.kt +12 -0
  8. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +7 -0
  9. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +153 -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 +62 -0
  13. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +1071 -0
  14. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +269 -0
  15. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +65 -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 +357 -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 +128 -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 +542 -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 +231 -0
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +189 -0
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +478 -0
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +114 -0
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +265 -0
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +235 -0
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +223 -0
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +265 -0
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +185 -0
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +343 -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 +41 -0
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +84 -0
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +40 -0
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +361 -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 +308 -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 +90 -0
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +330 -0
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +220 -0
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +473 -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 +207 -0
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +92 -0
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +560 -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 +125 -0
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +207 -0
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +501 -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 +236 -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 +17 -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 +287 -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/Item.kt +50 -0
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +306 -0
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +41 -0
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +52 -0
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +66 -0
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +11 -0
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +104 -0
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +48 -0
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +51 -0
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +338 -0
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/HostBackGestureBridge.kt +58 -0
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +137 -0
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +116 -0
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +215 -0
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +404 -0
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +8 -0
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +732 -0
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +148 -0
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +40 -0
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +233 -0
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +217 -0
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +86 -0
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +97 -0
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +377 -0
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +169 -0
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +455 -0
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +103 -0
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderJourney.kt +106 -0
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderLocation.kt +74 -0
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +413 -0
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +39 -0
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +363 -0
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HelpCenterRequest.kt +37 -0
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +192 -0
  110. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +133 -0
  111. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/ToolkitRequests.kt +41 -0
  112. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +135 -0
  113. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +12 -0
  114. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +91 -0
  115. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +9 -0
  116. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +74 -0
  117. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +20 -0
  118. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +1329 -0
  119. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +55 -0
  120. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +15 -0
  121. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +118 -0
  122. package/compose/src/commonTest/kotlin/vn/momo/kits/navigation/component/HelpCenterRequestTest.kt +44 -0
  123. package/compose/src/commonTest/kotlin/vn/momo/kits/navigation/component/ToolkitRequestsTest.kt +62 -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 +34 -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 +66 -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/ReservedRegions.ios.kt +138 -0
  131. package/gradle/libs.versions.toml +68 -0
  132. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  133. package/gradle/wrapper/gradle-wrapper.properties +8 -0
  134. package/gradle.properties +26 -0
  135. package/gradlew +252 -0
  136. package/gradlew.bat +94 -0
  137. package/ios/native-kits.podspec +1 -1
  138. package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
  139. package/ios-demo/README.md +120 -0
  140. package/package.json +1 -1
  141. package/settings.gradle.kts +64 -0
@@ -0,0 +1,55 @@
1
+ package vn.momo.kits.utils
2
+
3
+ import androidx.compose.runtime.*
4
+ import org.jetbrains.compose.resources.DrawableResource
5
+ import org.jetbrains.compose.resources.InternalResourceApi
6
+ import org.jetbrains.compose.resources.ResourceItem
7
+ import org.jetbrains.compose.resources.readResourceBytes
8
+ @OptIn(InternalResourceApi::class)
9
+ @Composable
10
+ internal fun readJson(name: String): String {
11
+ val path = name.plus(".json")
12
+ val candidatePaths = listOf(
13
+ path,
14
+ "composeResources/vn.momo.compose.resources/$path",
15
+ )
16
+
17
+ val jsonContent by rememberState(path, { "" }) {
18
+ val cached = resourceCache.getOrPut(path) {
19
+ var content = ""
20
+ for (candidate in candidatePaths) {
21
+ try {
22
+ content = readResourceBytes(candidate).decodeToString()
23
+ break
24
+ } catch (_: Exception) {
25
+ // try next candidate
26
+ }
27
+ }
28
+ ResourceCache.JSON(content)
29
+ } as ResourceCache.JSON
30
+
31
+ cached.json
32
+ }
33
+
34
+ return jsonContent
35
+ }
36
+
37
+
38
+ private val resourceCache = mutableMapOf<String, ResourceCache>()
39
+
40
+ private sealed interface ResourceCache {
41
+ class JSON(val json: String) : ResourceCache
42
+ }
43
+
44
+ @Composable
45
+ fun <T> rememberState(
46
+ key: Any,
47
+ getDefault: () -> T,
48
+ block: suspend () -> T
49
+ ): MutableState<T> {
50
+ val state = remember(key) { mutableStateOf(getDefault()) }
51
+ LaunchedEffect(key) {
52
+ state.value = block()
53
+ }
54
+ return state
55
+ }
@@ -0,0 +1,15 @@
1
+ package vn.momo.kits.utils
2
+
3
+ import androidx.compose.runtime.Composable
4
+ import vn.momo.kits.application.LocalComponentInformation
5
+
6
+ @Composable
7
+ internal fun getComponentId(
8
+ componentName: String? = null,
9
+ accessibilityLabel: String? = null,
10
+ ): String {
11
+ val componentInformation = LocalComponentInformation.current
12
+ if (accessibilityLabel != null) return accessibilityLabel
13
+ if (componentInformation?.componentId != null) return componentInformation.componentId
14
+ return ""
15
+ }
@@ -0,0 +1,118 @@
1
+ package vn.momo.kits.utils
2
+
3
+ import androidx.compose.foundation.layout.WindowInsets
4
+ import androidx.compose.foundation.layout.WindowInsetsSides
5
+ import androidx.compose.foundation.layout.displayCutout
6
+ import androidx.compose.foundation.layout.only
7
+ import androidx.compose.foundation.layout.union
8
+ import androidx.compose.foundation.layout.windowInsetsPadding
9
+ import androidx.compose.foundation.layout.asPaddingValues
10
+ import androidx.compose.foundation.layout.systemBars
11
+ import androidx.compose.runtime.Composable
12
+ import androidx.compose.ui.Modifier
13
+ import androidx.compose.ui.composed
14
+ import androidx.compose.ui.draw.drawBehind
15
+ import androidx.compose.ui.geometry.Offset
16
+ import androidx.compose.ui.graphics.Color
17
+ import androidx.compose.ui.platform.LocalDensity
18
+ import androidx.compose.ui.unit.Dp
19
+ import androidx.compose.ui.unit.dp
20
+ import androidx.compose.ui.unit.min
21
+ import vn.momo.kits.const.AppNavigationBar
22
+ import vn.momo.kits.const.AppStatusBar
23
+ import vn.momo.kits.platform.getPlatformName
24
+ import kotlin.math.abs
25
+
26
+
27
+ internal fun Modifier.bottomBorder(strokeWidth: Dp, color: Color) = composed(
28
+ factory = {
29
+ val density = LocalDensity.current
30
+ val strokeWidthPx = density.run { strokeWidth.toPx() }
31
+ if (strokeWidth > 0.dp) {
32
+ Modifier.drawBehind {
33
+ val width = size.width
34
+ val height = size.height - strokeWidthPx / 2
35
+
36
+ drawLine(
37
+ color = color,
38
+ start = Offset(x = 0f, y = height),
39
+ end = Offset(x = width, y = height),
40
+ strokeWidth = strokeWidthPx
41
+ )
42
+ }
43
+ } else {
44
+ Modifier
45
+ }
46
+ }
47
+ )
48
+
49
+ fun <T> Boolean.ifTrue(trueCase: T, falseCase: T): T = if (this) trueCase else falseCase
50
+ fun <T> String.ifNotNull(trueCase: T, falseCase: T): T =
51
+ if (this.isBlank()) falseCase else trueCase
52
+
53
+ fun formatNumberToMoney(number: Long, currency: String = "đ"): String {
54
+ if (number == 0L) {
55
+ return "0$currency"
56
+ }
57
+ val array = mutableListOf<Char>()
58
+ var result = ""
59
+ var isNegative = false
60
+
61
+ if (number < 0) {
62
+ isNegative = true
63
+ }
64
+ val numberString = abs(number).toString() // Convert to Int to avoid decimal places
65
+ if (numberString.length < 3) {
66
+ return numberString + currency
67
+ }
68
+ var count = 0
69
+ for (i in numberString.length - 1 downTo 0) {
70
+ count += 1
71
+ array.add(numberString[i])
72
+ if (count == 3 && i >= 1) {
73
+ array.add('.')
74
+ count = 0
75
+ }
76
+ }
77
+
78
+ for (i in array.size - 1 downTo 0) {
79
+ result += array[i]
80
+ }
81
+
82
+ if (isNegative) {
83
+ result = "-$result"
84
+ }
85
+
86
+ return result + currency
87
+ }
88
+
89
+ @Composable
90
+ fun getAppStatusBarHeight(): Dp {
91
+ return if (AppStatusBar.current == 0.dp) {
92
+ WindowInsets.systemBars.asPaddingValues().calculateTopPadding()
93
+ } else {
94
+ AppStatusBar.current
95
+ }
96
+ }
97
+
98
+ internal val horizontalSafeAreaInsets: WindowInsets
99
+ @Composable get() = WindowInsets.systemBars.union(WindowInsets.displayCutout).only(WindowInsetsSides.Horizontal)
100
+
101
+ // Left/right safe area like SwiftUI (landscape camera/notch); consumed, so nested StackScreens don't pad twice.
102
+ internal fun Modifier.horizontalSafeAreaPadding(): Modifier = composed {
103
+ windowInsetsPadding(horizontalSafeAreaInsets)
104
+ }
105
+
106
+ @Composable
107
+ internal fun getNavigationBarHeight(): Dp {
108
+ return if (AppNavigationBar.current == 0.dp) {
109
+ val systemBottomPadding = WindowInsets.systemBars.asPaddingValues().calculateBottomPadding()
110
+ if (getPlatformName() == "iOS") {
111
+ min(systemBottomPadding, 21.dp)
112
+ } else {
113
+ systemBottomPadding
114
+ }
115
+ } else {
116
+ AppNavigationBar.current
117
+ }
118
+ }
@@ -0,0 +1,44 @@
1
+ // File: HelpCenterRequestTest.kt
2
+ // Created At: 2026-10-19 +07:00
3
+ // Created By: AI | AI Agent: Codex | Model: GPT-6
4
+ // AI-GENERATED START: verify Help Center identity and localized payload preservation
5
+ package vn.momo.kits.navigation.component
6
+
7
+ import kotlinx.serialization.json.JsonObject
8
+ import kotlinx.serialization.json.JsonPrimitive
9
+ import vn.momo.kits.application.MiniAppContext
10
+ import kotlin.test.Test
11
+ import kotlin.test.assertEquals
12
+ import kotlin.test.assertNull
13
+
14
+ class HelpCenterRequestTest {
15
+ @Test
16
+ fun preservesApplicationIdentityAndLocalizedObjects() {
17
+ val context = MiniAppContext(
18
+ appId = "app-id",
19
+ appCode = "app-code",
20
+ appIcon = "app-icon",
21
+ appName = mapOf("vi" to "Tên ứng dụng", "en" to "App name"),
22
+ description = mapOf("vi" to "Mô tả", "en" to "Description"),
23
+ )
24
+ val request = context.helpCenterRequest().context
25
+ assertEquals(context.appId, request.appId)
26
+ assertEquals(context.appCode, request.code)
27
+ assertEquals(context.appIcon, request.icon)
28
+ assertEquals(JsonObject(mapOf("vi" to JsonPrimitive("Tên ứng dụng"),
29
+ "en" to JsonPrimitive("App name"))), request.name)
30
+ assertEquals(JsonObject(mapOf("vi" to JsonPrimitive("Mô tả"),
31
+ "en" to JsonPrimitive("Description"))), request.description)
32
+ assertNull(request.support)
33
+ assertNull(request.toolkitConfig)
34
+ assertNull(request.permissions)
35
+ }
36
+
37
+ @Test
38
+ fun preservesPlainStringsAndAbsentValues() {
39
+ val request = MiniAppContext(appName = "App name").helpCenterRequest().context
40
+ assertEquals(JsonPrimitive("App name"), request.name)
41
+ assertNull(request.description)
42
+ }
43
+ }
44
+ // AI-GENERATED END: verify Help Center identity and localized payload preservation
@@ -0,0 +1,62 @@
1
+ // File: ToolkitRequestsTest.kt
2
+ // Created At: 2026-10-12 +07:00 | Created By: AI | AI Agent: Codex | Model: GPT-6
3
+ // AI-GENERATED START: verify cancellation and late callback suppression for toolkit UI
4
+ package vn.momo.kits.navigation.component
5
+
6
+ import kotlin.test.Test
7
+ import kotlin.test.assertEquals
8
+ import vn.momo.maxapi.runtime.ApiCallback
9
+ import vn.momo.maxapi.runtime.ApiRequestHandle
10
+ import vn.momo.maxapi.runtime.ApiResult
11
+
12
+ class ToolkitRequestsTest {
13
+ @Test
14
+ fun closingCancelsPendingRequestsAndSuppressesLateCallbacks() {
15
+ val owner = ToolkitRequests()
16
+ val handle = Handle()
17
+ var callback: ApiCallback<Boolean> = {}
18
+ var results = 0
19
+ owner.launch<Boolean>({ callback = it; handle }) { results++ }
20
+ owner.close()
21
+ owner.close()
22
+ callback(ApiResult.Success(true))
23
+ assertEquals(1, handle.cancellations)
24
+ assertEquals(0, results)
25
+ }
26
+
27
+ @Test
28
+ fun completedRequestsAreReleasedAndClosedOwnersNeverStartNewRequests() {
29
+ val owner = ToolkitRequests()
30
+ val handle = Handle()
31
+ var starts = 0
32
+ var results = 0
33
+ owner.launch<Boolean>({ callback -> starts++; callback(ApiResult.Success(false)); handle }) { results++ }
34
+ owner.close()
35
+ owner.launch<Boolean>({ starts++; handle }) { results++ }
36
+ assertEquals(0, handle.cancellations)
37
+ assertEquals(1, starts)
38
+ assertEquals(1, results)
39
+ }
40
+
41
+ @Test
42
+ fun sheetEventsKeepTheirSubscriptionUntilTheOwnerCloses() {
43
+ val owner = ToolkitRequests()
44
+ val handle = Handle()
45
+ var callback: ApiCallback<Boolean> = {}
46
+ var results = 0
47
+ owner.observe<Boolean>({ callback = it; handle }) { results++ }
48
+ callback(ApiResult.Success(true))
49
+ callback(ApiResult.Success(false))
50
+ owner.close()
51
+ callback(ApiResult.Success(true))
52
+ assertEquals(2, results)
53
+ assertEquals(1, handle.cancellations)
54
+ }
55
+
56
+ private class Handle : ApiRequestHandle {
57
+ override val requestId = "toolkit-test"
58
+ var cancellations = 0
59
+ override fun cancel() { cancellations++ }
60
+ }
61
+ }
62
+ // AI-GENERATED END: verify cancellation and late callback suppression for toolkit UI
@@ -0,0 +1,42 @@
1
+ @file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
2
+
3
+ package vn.momo.kits.const
4
+
5
+ import androidx.compose.runtime.Composable
6
+ import androidx.compose.runtime.remember
7
+ import androidx.compose.ui.text.font.FontFamily
8
+ import androidx.compose.ui.text.font.FontWeight
9
+ import androidx.compose.ui.text.platform.Font
10
+ import kotlinx.cinterop.ExperimentalForeignApi
11
+ import kotlinx.cinterop.addressOf
12
+ import kotlinx.cinterop.usePinned
13
+ import platform.Foundation.NSBundle
14
+ import platform.Foundation.NSData
15
+ import platform.Foundation.dataWithContentsOfFile
16
+ import platform.posix.memcpy
17
+
18
+ @Composable
19
+ internal actual fun hostFontFamily(fileName: String, weight: FontWeight): FontFamily? = remember(fileName, weight) {
20
+ val name = fileName.substringBeforeLast('.')
21
+ val ext = fileName.substringAfterLast('.', "")
22
+ // Font từ font-source nằm rời ở bundle root, không nằm trong compose-resources.
23
+ val path = NSBundle.mainBundle.pathForResource(name, ext) ?: return@remember null
24
+ FontFamily(
25
+ Font(
26
+ identity = fileName,
27
+ getData = {
28
+ NSData.dataWithContentsOfFile(path)?.toByteArray() ?: ByteArray(0)
29
+ },
30
+ weight = weight,
31
+ ),
32
+ )
33
+ }
34
+
35
+ @OptIn(ExperimentalForeignApi::class)
36
+ private fun NSData.toByteArray(): ByteArray {
37
+ val size = length.toInt()
38
+ if (size == 0) return ByteArray(0)
39
+ return ByteArray(size).apply {
40
+ usePinned { pinned -> memcpy(pinned.addressOf(0), bytes, length) }
41
+ }
42
+ }
@@ -0,0 +1,45 @@
1
+ package vn.momo.kits.navigation
2
+
3
+ import androidx.compose.runtime.Composable
4
+ import androidx.compose.runtime.DisposableEffect
5
+ import androidx.compose.runtime.remember
6
+ import androidx.navigationevent.NavigationEvent
7
+ import androidx.navigationevent.NavigationEventDispatcher
8
+ import androidx.navigationevent.NavigationEventInput
9
+
10
+ @Suppress("ParamsComparedByRef")
11
+ @Composable
12
+ internal fun AttachHostBackGesture(dispatcher: NavigationEventDispatcher, navigator: Navigator) {
13
+ val input = remember(dispatcher) { HostNavigationEventInput() }
14
+ val target = remember(input, navigator) {
15
+ object : HostBackTarget {
16
+ override fun canPop() = navigator.canPop()
17
+ override fun onBack() = navigator.onBackSafe()
18
+ override fun backStarted() = input.backStarted()
19
+ override fun backProgressed(progress: Float) = input.backProgressed(progress)
20
+ override fun backCompleted() = input.backCompleted()
21
+ override fun backCancelled() = input.backCancelled()
22
+ }
23
+ }
24
+
25
+ DisposableEffect(dispatcher, target) {
26
+ dispatcher.addInput(input)
27
+ HostBackGestureBridge.attach(target)
28
+ onDispose {
29
+ HostBackGestureBridge.detach(target)
30
+ dispatcher.removeInput(input)
31
+ }
32
+ }
33
+ }
34
+
35
+ internal class HostNavigationEventInput : NavigationEventInput() {
36
+ fun backStarted() = dispatchOnBackStarted(NavigationEvent(swipeEdge = NavigationEvent.EDGE_LEFT))
37
+
38
+ fun backProgressed(progress: Float) = dispatchOnBackProgressed(
39
+ NavigationEvent(swipeEdge = NavigationEvent.EDGE_LEFT, progress = progress)
40
+ )
41
+
42
+ fun backCancelled() = dispatchOnBackCancelled()
43
+
44
+ fun backCompleted() = dispatchOnBackCompleted()
45
+ }
@@ -0,0 +1,34 @@
1
+ package vn.momo.kits.navigation
2
+
3
+ import androidx.compose.runtime.Composable
4
+ import androidx.compose.runtime.DisposableEffect
5
+ import platform.Foundation.NSNotification
6
+ import platform.Foundation.NSNotificationCenter
7
+ import platform.Foundation.NSOperationQueue
8
+ import platform.darwin.NSObjectProtocol
9
+ import vn.momo.maxapi.contract.observability.logging.model.LogLevel
10
+
11
+ private const val STATUS_BAR_TAPPED_NOTIFICATION = "statusBarSelected"
12
+
13
+ @Composable
14
+ internal actual fun RegisterScrollToTop(callback: (() -> Unit)?) {
15
+ val maxApi = LocalMaxApi.current
16
+ DisposableEffect(callback, maxApi) {
17
+ val logger = if (callback != null) maxApi?.openLogger() else null
18
+ val token: NSObjectProtocol? = if (callback != null) {
19
+ NSNotificationCenter.defaultCenter.addObserverForName(
20
+ name = STATUS_BAR_TAPPED_NOTIFICATION,
21
+ `object` = null,
22
+ queue = NSOperationQueue.mainQueue,
23
+ ) { _: NSNotification? ->
24
+ runCatching { callback() }.onFailure {
25
+ logger?.log(LogLevel.ERROR, "[ScrollToTop] callback failed")
26
+ }
27
+ }
28
+ } else null
29
+ onDispose {
30
+ token?.let { NSNotificationCenter.defaultCenter.removeObserver(it) }
31
+ logger?.close()
32
+ }
33
+ }
34
+ }
@@ -0,0 +1,38 @@
1
+ package vn.momo.kits.platform
2
+
3
+ import androidx.compose.runtime.Composable
4
+ import androidx.compose.runtime.LaunchedEffect
5
+ import androidx.compose.runtime.State
6
+ import androidx.compose.runtime.mutableStateOf
7
+ import androidx.compose.runtime.remember
8
+ import androidx.compose.ui.InternalComposeUiApi
9
+ import androidx.compose.ui.backhandler.LocalCompatNavigationEventDispatcherOwner
10
+ import androidx.navigationevent.NavigationEventTransitionState
11
+ import vn.momo.kits.navigation.HostBackGestureBridge
12
+
13
+ // transitionState is a passive observer; its progress is touch.x / view width.
14
+ @OptIn(InternalComposeUiApi::class)
15
+ @Composable
16
+ actual fun rememberBackGestureProgress(): State<Float?> {
17
+ val dispatcher = LocalCompatNavigationEventDispatcherOwner.current?.navigationEventDispatcher
18
+ val progress = remember { mutableStateOf<Float?>(null) }
19
+
20
+ LaunchedEffect(dispatcher) {
21
+ if (dispatcher == null) {
22
+ progress.value = null
23
+ return@LaunchedEffect
24
+ }
25
+ dispatcher.transitionState.collect { state ->
26
+ progress.value = (state as? NavigationEventTransitionState.InProgress)
27
+ ?.takeIf { it.direction == NavigationEventTransitionState.TRANSITIONING_BACK }
28
+ ?.latestEvent
29
+ ?.progress
30
+ }
31
+ }
32
+
33
+ return progress
34
+ }
35
+
36
+ actual fun reportFloatingArrowBack(shouldUse: Boolean) {
37
+ HostBackGestureBridge.shouldUseFloatingArrowBack = shouldUse
38
+ }
@@ -0,0 +1,66 @@
1
+ package vn.momo.kits.platform
2
+
3
+ import androidx.compose.runtime.Composable
4
+ import androidx.compose.runtime.CompositionLocalProvider
5
+ import androidx.compose.runtime.DisposableEffect
6
+ import androidx.compose.runtime.mutableStateOf
7
+ import androidx.compose.runtime.remember
8
+ import androidx.compose.ui.platform.LocalDensity
9
+ import androidx.compose.ui.unit.Density
10
+ import kotlinx.cinterop.ExperimentalForeignApi
11
+ import kotlinx.cinterop.ObjCAction
12
+ import platform.Foundation.NSNotification
13
+ import platform.Foundation.NSNotificationCenter
14
+ import platform.Foundation.NSSelectorFromString
15
+ import platform.UIKit.UIContentSizeCategoryDidChangeNotification
16
+ import platform.UIKit.UIFont
17
+ import platform.UIKit.UIFontTextStyleBody
18
+ import platform.darwin.NSObject
19
+
20
+ // Compose MP iOS reads LocalDensity.fontScale once at ComposeUIViewController creation and does not
21
+ // recompose it when UIContentSizeCategory changes (Android tracks Configuration.fontScale live). We
22
+ // observe the notification and override LocalDensity.fontScale so scaleSize() recomposes live. The
23
+ // formula matches the SwiftUI kit (UIFont body point size / 17) so both iOS surfaces scale alike.
24
+ private const val DEFAULT_BODY_POINT_SIZE = 17.0
25
+
26
+ private fun currentOsFontScale(): Float =
27
+ (UIFont.preferredFontForTextStyle(UIFontTextStyleBody).pointSize / DEFAULT_BODY_POINT_SIZE).toFloat()
28
+
29
+ @OptIn(ExperimentalForeignApi::class)
30
+ @Composable
31
+ actual fun ProvideOsFontScale(content: @Composable () -> Unit) {
32
+ val osFontScale = remember { mutableStateOf(currentOsFontScale()) }
33
+
34
+ val listener = remember {
35
+ object : NSObject() {
36
+ @Suppress("unused")
37
+ @ObjCAction
38
+ fun contentSizeChanged(arg: NSNotification) {
39
+ osFontScale.value = currentOsFontScale()
40
+ }
41
+ }
42
+ }
43
+
44
+ DisposableEffect(Unit) {
45
+ NSNotificationCenter.defaultCenter.addObserver(
46
+ observer = listener,
47
+ selector = NSSelectorFromString(listener::contentSizeChanged.name + ":"),
48
+ name = UIContentSizeCategoryDidChangeNotification,
49
+ `object` = null,
50
+ )
51
+ onDispose {
52
+ NSNotificationCenter.defaultCenter.removeObserver(
53
+ observer = listener,
54
+ name = UIContentSizeCategoryDidChangeNotification,
55
+ `object` = null,
56
+ )
57
+ }
58
+ }
59
+
60
+ val density = LocalDensity.current
61
+ CompositionLocalProvider(
62
+ LocalDensity provides Density(density.density, osFontScale.value),
63
+ ) {
64
+ content()
65
+ }
66
+ }