@momo-kits/native-kits 0.164.1-beta.4 → 0.164.1-beta.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 (140) hide show
  1. package/.claude/settings.local.json +185 -0
  2. package/build.gradle.kts +11 -0
  3. package/compose/build.gradle.kts +190 -0
  4. package/compose/build.gradle.kts.backup +190 -0
  5. package/compose/compose.podspec +47 -0
  6. package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +19 -0
  7. package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +6 -0
  8. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/BackGesture.android.kt +12 -0
  9. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +7 -0
  10. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +150 -0
  11. package/compose/src/commonMain/kotlin/vn/momo/kits/application/AnimationSearchInput.kt +52 -0
  12. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +106 -0
  13. package/compose/src/commonMain/kotlin/vn/momo/kits/application/FloatingButton.kt +183 -0
  14. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Header.kt +207 -0
  15. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderAnimated.kt +39 -0
  16. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderBackground.kt +86 -0
  17. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderDefault.kt +76 -0
  18. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderExtended.kt +76 -0
  19. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderRight.kt +293 -0
  20. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderTitle.kt +33 -0
  21. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +826 -0
  22. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +269 -0
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/application/NavigationContainer.kt +110 -0
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Screen.kt +378 -0
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +56 -0
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/application/useHeaderSearchAnimation.kt +69 -0
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +157 -0
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +82 -0
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +32 -0
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +338 -0
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +175 -0
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +356 -0
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +113 -0
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +89 -0
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +128 -0
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +209 -0
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +542 -0
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +23 -0
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +76 -0
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +125 -0
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +231 -0
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +134 -0
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +475 -0
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +114 -0
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +214 -0
  46. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +240 -0
  47. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +216 -0
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +259 -0
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +182 -0
  50. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +343 -0
  51. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +108 -0
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +56 -0
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +41 -0
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +84 -0
  55. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +40 -0
  56. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +328 -0
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +97 -0
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +310 -0
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +59 -0
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +87 -0
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +21 -0
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +90 -0
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +323 -0
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +217 -0
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +473 -0
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +122 -0
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +199 -0
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +91 -0
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +470 -0
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +88 -0
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +131 -0
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +203 -0
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +498 -0
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +175 -0
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +182 -0
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +193 -0
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +29 -0
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +234 -0
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +188 -0
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +325 -0
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +16 -0
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/const/KitFontScale.kt +22 -0
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +12 -0
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +16 -0
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +188 -0
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +263 -0
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +52 -0
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +38 -0
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +39 -0
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +52 -0
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +66 -0
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +11 -0
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +104 -0
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +48 -0
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +51 -0
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +299 -0
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +129 -0
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +103 -0
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +191 -0
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +385 -0
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +8 -0
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +599 -0
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +157 -0
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +39 -0
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +156 -0
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +225 -0
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +86 -0
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +169 -0
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +320 -0
  110. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +81 -0
  111. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +309 -0
  112. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +34 -0
  113. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +360 -0
  114. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +132 -0
  115. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +127 -0
  116. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +15 -0
  117. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +91 -0
  118. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +9 -0
  119. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +69 -0
  120. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +1329 -0
  121. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +55 -0
  122. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +15 -0
  123. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +105 -0
  124. package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +40 -0
  125. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +32 -0
  126. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/BackGesture.ios.kt +35 -0
  127. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +66 -0
  128. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +225 -0
  129. package/gradle/libs.versions.toml +69 -0
  130. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  131. package/gradle/wrapper/gradle-wrapper.properties +8 -0
  132. package/gradle.properties +26 -0
  133. package/gradlew +252 -0
  134. package/gradlew.bat +94 -0
  135. package/ios/native-kits.podspec +1 -1
  136. package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
  137. package/ios-demo/README.md +120 -0
  138. package/local.properties +8 -0
  139. package/package.json +1 -1
  140. 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,105 @@
1
+ package vn.momo.kits.utils
2
+
3
+ import androidx.compose.foundation.layout.WindowInsets
4
+ import androidx.compose.foundation.layout.asPaddingValues
5
+ import androidx.compose.foundation.layout.systemBars
6
+ import androidx.compose.runtime.Composable
7
+ import androidx.compose.ui.Modifier
8
+ import androidx.compose.ui.composed
9
+ import androidx.compose.ui.draw.drawBehind
10
+ import androidx.compose.ui.geometry.Offset
11
+ import androidx.compose.ui.graphics.Color
12
+ import androidx.compose.ui.platform.LocalDensity
13
+ import androidx.compose.ui.unit.Dp
14
+ import androidx.compose.ui.unit.dp
15
+ import androidx.compose.ui.unit.min
16
+ import vn.momo.kits.const.AppNavigationBar
17
+ import vn.momo.kits.const.AppStatusBar
18
+ import vn.momo.kits.platform.getPlatformName
19
+ import kotlin.math.abs
20
+
21
+
22
+ internal fun Modifier.bottomBorder(strokeWidth: Dp, color: Color) = composed(
23
+ factory = {
24
+ val density = LocalDensity.current
25
+ val strokeWidthPx = density.run { strokeWidth.toPx() }
26
+ if (strokeWidth > 0.dp) {
27
+ Modifier.drawBehind {
28
+ val width = size.width
29
+ val height = size.height - strokeWidthPx / 2
30
+
31
+ drawLine(
32
+ color = color,
33
+ start = Offset(x = 0f, y = height),
34
+ end = Offset(x = width, y = height),
35
+ strokeWidth = strokeWidthPx
36
+ )
37
+ }
38
+ } else {
39
+ Modifier
40
+ }
41
+ }
42
+ )
43
+
44
+ fun <T> Boolean.ifTrue(trueCase: T, falseCase: T): T = if (this) trueCase else falseCase
45
+ fun <T> String.ifNotNull(trueCase: T, falseCase: T): T =
46
+ if (this.isBlank()) falseCase else trueCase
47
+
48
+ fun formatNumberToMoney(number: Long, currency: String = "đ"): String {
49
+ if (number == 0L) {
50
+ return "0$currency"
51
+ }
52
+ val array = mutableListOf<Char>()
53
+ var result = ""
54
+ var isNegative = false
55
+
56
+ if (number < 0) {
57
+ isNegative = true
58
+ }
59
+ val numberString = abs(number).toString() // Convert to Int to avoid decimal places
60
+ if (numberString.length < 3) {
61
+ return numberString + currency
62
+ }
63
+ var count = 0
64
+ for (i in numberString.length - 1 downTo 0) {
65
+ count += 1
66
+ array.add(numberString[i])
67
+ if (count == 3 && i >= 1) {
68
+ array.add('.')
69
+ count = 0
70
+ }
71
+ }
72
+
73
+ for (i in array.size - 1 downTo 0) {
74
+ result += array[i]
75
+ }
76
+
77
+ if (isNegative) {
78
+ result = "-$result"
79
+ }
80
+
81
+ return result + currency
82
+ }
83
+
84
+ @Composable
85
+ fun getAppStatusBarHeight(): Dp {
86
+ return if (AppStatusBar.current == 0.dp) {
87
+ WindowInsets.systemBars.asPaddingValues().calculateTopPadding()
88
+ } else {
89
+ AppStatusBar.current
90
+ }
91
+ }
92
+
93
+ @Composable
94
+ internal fun getNavigationBarHeight(): Dp {
95
+ return if (AppNavigationBar.current == 0.dp) {
96
+ val systemBottomPadding = WindowInsets.systemBars.asPaddingValues().calculateBottomPadding()
97
+ if (getPlatformName() == "iOS") {
98
+ min(systemBottomPadding, 21.dp)
99
+ } else {
100
+ systemBottomPadding
101
+ }
102
+ } else {
103
+ AppNavigationBar.current
104
+ }
105
+ }
@@ -0,0 +1,40 @@
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.platform.Font
9
+ import kotlinx.cinterop.ExperimentalForeignApi
10
+ import kotlinx.cinterop.addressOf
11
+ import kotlinx.cinterop.usePinned
12
+ import platform.Foundation.NSBundle
13
+ import platform.Foundation.NSData
14
+ import platform.Foundation.dataWithContentsOfFile
15
+ import platform.posix.memcpy
16
+
17
+ @Composable
18
+ internal actual fun hostFontFamily(fileName: String): FontFamily? = remember(fileName) {
19
+ val name = fileName.substringBeforeLast('.')
20
+ val ext = fileName.substringAfterLast('.', "")
21
+ // Font từ font-source nằm rời ở bundle root, không nằm trong compose-resources.
22
+ val path = NSBundle.mainBundle.pathForResource(name, ext) ?: return@remember null
23
+ FontFamily(
24
+ Font(
25
+ identity = fileName,
26
+ getData = {
27
+ NSData.dataWithContentsOfFile(path)?.toByteArray() ?: ByteArray(0)
28
+ },
29
+ ),
30
+ )
31
+ }
32
+
33
+ @OptIn(ExperimentalForeignApi::class)
34
+ private fun NSData.toByteArray(): ByteArray {
35
+ val size = length.toInt()
36
+ if (size == 0) return ByteArray(0)
37
+ return ByteArray(size).apply {
38
+ usePinned { pinned -> memcpy(pinned.addressOf(0), bytes, length) }
39
+ }
40
+ }
@@ -0,0 +1,32 @@
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
+
10
+ private const val STATUS_BAR_TAPPED_NOTIFICATION = "statusBarSelected"
11
+
12
+ @Composable
13
+ internal actual fun RegisterScrollToTop(callback: (() -> Unit)?) {
14
+ val maxApi = LocalMaxApi.current
15
+ DisposableEffect(callback) {
16
+ val token: NSObjectProtocol? = if (callback != null) {
17
+ NSNotificationCenter.defaultCenter.addObserverForName(
18
+ name = STATUS_BAR_TAPPED_NOTIFICATION,
19
+ `object` = null,
20
+ queue = NSOperationQueue.mainQueue,
21
+ ) { _: NSNotification? ->
22
+ runCatching { callback() }.onFailure {
23
+ maxApi?.logFile("[ScrollToTop] callback threw: ${it.message}") {}
24
+
25
+ }
26
+ }
27
+ } else null
28
+ onDispose {
29
+ token?.let { NSNotificationCenter.defaultCenter.removeObserver(it) }
30
+ }
31
+ }
32
+ }
@@ -0,0 +1,35 @@
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
+
12
+ // NavigationEventDispatcher.transitionState is a passive observer: UIKitNavigationEventInput
13
+ // publishes every edge-pan event to it without any handler consuming the gesture. Its `progress`
14
+ // is touch.x / view width, i.e. a plain fraction of the screen width.
15
+ @OptIn(InternalComposeUiApi::class)
16
+ @Composable
17
+ actual fun rememberBackGestureProgress(): State<Float?> {
18
+ val dispatcher = LocalCompatNavigationEventDispatcherOwner.current?.navigationEventDispatcher
19
+ val progress = remember { mutableStateOf<Float?>(null) }
20
+
21
+ LaunchedEffect(dispatcher) {
22
+ if (dispatcher == null) {
23
+ progress.value = null
24
+ return@LaunchedEffect
25
+ }
26
+ dispatcher.transitionState.collect { state ->
27
+ progress.value = (state as? NavigationEventTransitionState.InProgress)
28
+ ?.takeIf { it.direction == NavigationEventTransitionState.TRANSITIONING_BACK }
29
+ ?.latestEvent
30
+ ?.progress
31
+ }
32
+ }
33
+
34
+ return progress
35
+ }
@@ -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
+ }
@@ -0,0 +1,225 @@
1
+ package vn.momo.kits.platform
2
+
3
+ import androidx.compose.foundation.layout.Box
4
+ import androidx.compose.foundation.layout.WindowInsets
5
+ import androidx.compose.foundation.layout.asPaddingValues
6
+ import androidx.compose.foundation.layout.fillMaxSize
7
+ import androidx.compose.foundation.layout.systemBars
8
+ import androidx.compose.runtime.Composable
9
+ import androidx.compose.runtime.CompositionLocalProvider
10
+ import androidx.compose.runtime.LaunchedEffect
11
+ import androidx.compose.runtime.getValue
12
+ import androidx.compose.runtime.mutableStateOf
13
+ import androidx.compose.runtime.remember
14
+ import androidx.compose.runtime.rememberUpdatedState
15
+ import androidx.compose.runtime.setValue
16
+ import androidx.compose.ui.ExperimentalComposeUiApi
17
+ import androidx.compose.ui.InternalComposeUiApi
18
+ import androidx.compose.ui.Modifier
19
+ import androidx.compose.ui.backhandler.LocalCompatNavigationEventDispatcherOwner
20
+ import androidx.compose.ui.backhandler.BackHandler as ComposeBackHandler
21
+ import androidx.compose.ui.graphics.Color
22
+ import androidx.compose.ui.graphics.NativePaint
23
+ import androidx.compose.ui.graphics.toArgb
24
+ import androidx.compose.ui.unit.Dp
25
+ import androidx.compose.ui.unit.dp
26
+ import androidx.compose.ui.viewinterop.UIKitInteropProperties
27
+ import androidx.compose.ui.viewinterop.UIKitView
28
+ import cocoapods.lottie_ios.CompatibleAnimation
29
+ import cocoapods.lottie_ios.CompatibleAnimationKeypath
30
+ import cocoapods.lottie_ios.CompatibleAnimationView
31
+ import kotlinx.cinterop.ExperimentalForeignApi
32
+ import kotlinx.cinterop.get
33
+ import kotlinx.cinterop.memScoped
34
+ import androidx.navigationevent.NavigationEventDispatcher
35
+ import androidx.navigationevent.NavigationEventDispatcherOwner
36
+ import org.jetbrains.skia.FilterBlurMode
37
+ import org.jetbrains.skia.MaskFilter
38
+ import platform.Foundation.NSBundle
39
+ import platform.UIKit.UIColor
40
+ import platform.UIKit.UIDevice
41
+ import platform.UIKit.UIScreen
42
+ import vn.momo.kits.navigation.SwipeBackConfig
43
+
44
+ actual fun getPlatformName(): String = "iOS"
45
+
46
+ @OptIn(ExperimentalForeignApi::class)
47
+ @Composable
48
+ actual fun getScreenDimensions(): ScreenDimension = memScoped {
49
+ val config = UIScreen.mainScreen.bounds.ptr[0]
50
+ return ScreenDimension(
51
+ config.size.width.toInt(),
52
+ config.size.height.toInt()
53
+ )
54
+ }
55
+
56
+ actual fun NativePaint.setMaskFilter(blurRadius: Float) {
57
+ this.maskFilter = MaskFilter.makeBlur(FilterBlurMode.NORMAL, blurRadius / 2, true)
58
+ }
59
+
60
+ @Composable
61
+ actual fun getStatusBarHeight(): Dp {
62
+ return WindowInsets.systemBars.asPaddingValues().calculateTopPadding()
63
+ }
64
+
65
+ // An enabled kit BackHandler sits innermost and therefore consumes the edge-pan gesture — that is
66
+ // how a screen opts out of swipe-back (the port of RN's `hasCustomBackHandling`).
67
+ @Suppress("DEPRECATION")
68
+ @OptIn(ExperimentalComposeUiApi::class)
69
+ @Composable
70
+ actual fun BackHandler(enabled: Boolean, onBack: () -> Unit) {
71
+ ComposeBackHandler(enabled = enabled, onBack = onBack)
72
+ }
73
+
74
+ @OptIn(InternalComposeUiApi::class)
75
+ @Composable
76
+ actual fun ProvideNavigationEventDispatcherOwner(content: @Composable () -> Unit) {
77
+ val platformOwner = LocalCompatNavigationEventDispatcherOwner.current
78
+ if (platformOwner != null && SwipeBackConfig.enabled) {
79
+ // UIKitNavigationEventInput is registered on the scene's dispatcher. Providing a fresh
80
+ // NavigationEventDispatcher() here would shadow it with an input-less one that never sees
81
+ // a single edge-pan event, enabled or not — so pass the platform owner straight through.
82
+ content()
83
+ return
84
+ }
85
+
86
+ // Bare UIView hosts have no scene dispatcher, and BackHandler/PredictiveBackHandler error() on
87
+ // a null owner. This detached fallback is also what the kill switch falls back to.
88
+ val fallbackOwner = remember {
89
+ object : NavigationEventDispatcherOwner {
90
+ override val navigationEventDispatcher = NavigationEventDispatcher().apply {
91
+ isEnabled = false
92
+ }
93
+ }
94
+ }
95
+
96
+ CompositionLocalProvider(
97
+ LocalCompatNavigationEventDispatcherOwner provides fallbackOwner,
98
+ content = content
99
+ )
100
+ }
101
+
102
+ @Composable
103
+ actual fun getScreenHeight(): Dp {
104
+ return getScreenDimensions().height.dp
105
+ }
106
+
107
+ actual fun getOSVersion(): OSVersion = OSVersion.IOS(
108
+ major = UIDevice.currentDevice.systemVersion.substringBefore(".").toIntOrNull() ?: 0
109
+ )
110
+
111
+ @OptIn(ExperimentalForeignApi::class, ExperimentalComposeUiApi::class)
112
+ @Composable
113
+ actual fun LottieAnimation(
114
+ path: String,
115
+ tintColor: Color?,
116
+ bgColor: Color?,
117
+ placedAsOverlay: Boolean,
118
+ iterations: Int,
119
+ isPlaying: Boolean,
120
+ onEvent: ((String) -> Unit)?,
121
+ modifier: Modifier,
122
+ useCompose: Boolean
123
+ ) {
124
+ if (useCompose) {
125
+ ComposeLottieAnimation(path, tintColor, bgColor, iterations, isPlaying, onEvent, modifier)
126
+ return
127
+ }
128
+
129
+ val loopCount = if (iterations == LottieIterateForever) -1.0 else iterations.toDouble()
130
+
131
+ var animation by remember { mutableStateOf<CompatibleAnimation?>(null) }
132
+ val animationView = remember { mutableStateOf<CompatibleAnimationView?>(null) }
133
+
134
+ LaunchedEffect(Unit) {
135
+ animation = CompatibleAnimation(name = "compose-resources/composeResources/vn.momo.compose.resources/".plus(path), subdirectory = null, NSBundle.mainBundle)
136
+ }
137
+
138
+ val currentOnEvent by rememberUpdatedState(onEvent)
139
+
140
+ LaunchedEffect(isPlaying) {
141
+ currentOnEvent?.invoke(if (isPlaying) LottieEvent.Start else LottieEvent.Pause)
142
+ }
143
+
144
+ LaunchedEffect(animationView.value, isPlaying) {
145
+ val view = animationView.value ?: return@LaunchedEffect
146
+ if (isPlaying) {
147
+ view.playWithCompletion(completion = { finished -> if (finished) currentOnEvent?.invoke(LottieEvent.Finish) })
148
+ } else {
149
+ view.pause()
150
+ }
151
+ }
152
+
153
+ when (val value = animation) {
154
+ null -> {
155
+ Box(modifier)
156
+ }
157
+
158
+ else -> {
159
+ Box(modifier) {
160
+ UIKitView(
161
+ modifier = Modifier.fillMaxSize(),
162
+ properties = UIKitInteropProperties(placedAsOverlay = placedAsOverlay),
163
+ factory = {
164
+ CompatibleAnimationView(value).apply {
165
+ translatesAutoresizingMaskIntoConstraints = true
166
+
167
+ setBackgroundColor(bgColor?.toUIColor() ?: UIColor.clearColor)
168
+
169
+ setLoopAnimationCount(loopCount)
170
+ setAnimationSpeed(1.0)
171
+
172
+ if (tintColor != null) {
173
+ val uiColor = tintColor.toUIColor()
174
+ setColorValue(uiColor,
175
+ CompatibleAnimationKeypath("**.Fill 1.Color")
176
+ )
177
+ setColorValue(uiColor, CompatibleAnimationKeypath("**.Fill.Color"))
178
+ setColorValue(uiColor, CompatibleAnimationKeypath("**.Color"))
179
+ setColorValue(uiColor, CompatibleAnimationKeypath("**.Stroke 1.Color"))
180
+ setColorValue(uiColor, CompatibleAnimationKeypath("**.Stroke.Color"))
181
+ }
182
+
183
+ animationView.value = this
184
+ }
185
+ },
186
+
187
+ update = { view ->
188
+ view.setBackgroundColor(bgColor?.toUIColor() ?: UIColor.clearColor)
189
+ view.setLoopAnimationCount(loopCount)
190
+
191
+ if (tintColor != null) {
192
+ val uiColor = tintColor.toUIColor()
193
+
194
+ view.setColorValue(uiColor, CompatibleAnimationKeypath("**.Fill 1.Color"))
195
+ view.setColorValue(uiColor, CompatibleAnimationKeypath("**.Fill.Color"))
196
+ view.setColorValue(uiColor, CompatibleAnimationKeypath("**.Color"))
197
+ view.setColorValue(uiColor, CompatibleAnimationKeypath("**.Stroke 1.Color"))
198
+ view.setColorValue(uiColor, CompatibleAnimationKeypath("**.Stroke.Color"))
199
+ }
200
+ }
201
+ )
202
+ }
203
+ }
204
+ }
205
+ }
206
+
207
+ fun Color.toUIColor(): UIColor {
208
+ val argb = this.toArgb()
209
+
210
+ val a = ((argb shr 24) and 0xFF) / 255.0
211
+ val r = ((argb shr 16) and 0xFF) / 255.0
212
+ val g = ((argb shr 8) and 0xFF) / 255.0
213
+ val b = (argb and 0xFF) / 255.0
214
+
215
+ return UIColor(
216
+ red = r,
217
+ green = g,
218
+ blue = b,
219
+ alpha = a
220
+ )
221
+ }
222
+
223
+ actual fun NativePaint.setColor(color: Color){
224
+ this.color = color.toArgb()
225
+ }
@@ -0,0 +1,69 @@
1
+ [versions]
2
+ android-compileSdk = "36"
3
+ android-minSdk = "24"
4
+ android-targetSdk = "36"
5
+ ktor-version = "3.0.0-rc-1"
6
+ coroutines = "1.9.0"
7
+ kotlin = "2.3.10"
8
+ kSerialize = "1.7.1"
9
+ compose = "1.10.3"
10
+ navigation-multiplatform = "2.9.2"
11
+ coil3-multiplatform = "3.0.0-alpha10"
12
+ androidGradlePlugin = "8.13.2"
13
+ r8 = "8.9.35"
14
+ kotlinx-datetime = "0.7.1"
15
+ airbnb-lottie = "5.2.0"
16
+ compottie = "2.1.0"
17
+ androidx-activity = "1.9.1"
18
+ androidx-appcompat = "1.7.0"
19
+ material = "1.10.0"
20
+ maxapi = "0.1.1"
21
+ vanniktechMavenPublish = "0.34.0"
22
+ kits = "0.164.1-beta.1"
23
+ nativemaxapi = "0.0.6"
24
+ gif-image = "0.1.2"
25
+
26
+ [libraries]
27
+ ktor-client-core = { group = "io.ktor", name = "ktor-client-core", version.ref = "ktor-version" }
28
+ ktor-client-darwin = { group = "io.ktor", name = "ktor-client-darwin", version.ref = "ktor-version" }
29
+ ktor-client-okhttp = { group = "io.ktor", name = "ktor-client-okhttp", version.ref = "ktor-version" }
30
+ jetbrains-coroutines-android = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-android", version.ref = "coroutines" }
31
+ jetbrains-coroutines-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "coroutines" }
32
+ jetbrains-coroutines-test = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-test", version.ref = "coroutines" }
33
+ jetbrains-serialization = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization", version.ref = "kSerialize" }
34
+ jetbrains-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version.ref = "kSerialize" }
35
+ kotlinx-datetime = { group = "org.jetbrains.kotlinx", name = "kotlinx-datetime", version.ref = "kotlinx-datetime" }
36
+ compose-ui-backhandler = { module = "org.jetbrains.compose.ui:ui-backhandler", version.ref = "compose" }
37
+ navigation-multiplatform = { module = "org.jetbrains.androidx.navigation:navigation-compose", version.ref = "navigation-multiplatform" }
38
+ coil-multiplatform-core = { module = "io.coil-kt.coil3:coil-core", version.ref = "coil3-multiplatform" }
39
+ coil-multiplatform-compose = { module = "io.coil-kt.coil3:coil-compose", version.ref = "coil3-multiplatform" }
40
+ coil-multiplatform-network-ktor = { module = "io.coil-kt.coil3:coil-network-ktor3", version.ref = "coil3-multiplatform" }
41
+ r8 = { module = "com.android.tools:r8", version.ref = "r8" }
42
+ airbnb-lottie = { group = "com.airbnb.android", name = "lottie-compose", version.ref = "airbnb-lottie" }
43
+ # AI-GENERATED START
44
+ # Depend on compottie-core (not the `compottie` umbrella). The umbrella drags in the
45
+ # separate `keight` umbrella artifact, which collides with `keight-core` on the
46
+ # `findRoot__at__ScriptRuntime` symbol (duplicate symbol at the iOS `ld` link of
47
+ # shared.framework). compottie-core pulls only `keight-core` (which declares
48
+ # keight.js.JsAny, so the earlier unlinked-symbol error stays fixed too).
49
+ compottie = { module = "io.github.alexzhirkevich:compottie-core", version.ref = "compottie" }
50
+ # AI-GENERATED END
51
+ native-max-api = { group = "vn.momo.maxapi", name = "NativeMaxApi", version.ref = "nativemaxapi" }
52
+ kits = { module = "vn.momo.kits:kits", version.ref = "kits" }
53
+ androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "androidx-appcompat" }
54
+ androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activity" }
55
+ material = { module = "com.google.android.material:material", version.ref = "material" }
56
+
57
+ gif-image = { module = "vn.momo.kits:gif-image", version.ref = "gif-image" }
58
+ [plugins]
59
+ jetbrains-kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
60
+ jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
61
+ jetbrains-kotlin-parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref = "kotlin" }
62
+ jetbrains-kotlin-cocoapods = { id = "org.jetbrains.kotlin.native.cocoapods", version.ref = "kotlin" }
63
+ jetbrains-kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
64
+ jetbrains-kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
65
+ kotlin-compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
66
+ compose = { id = "org.jetbrains.compose", version.ref = "compose" }
67
+ android-library = { id = "com.android.library", version.ref = "androidGradlePlugin" }
68
+ android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" }
69
+ vanniktech-mavenPublish = { id = "com.vanniktech.maven.publish", version.ref = "vanniktechMavenPublish" }
@@ -0,0 +1,8 @@
1
+ #Thu Jul 31 17:05:40 ICT 2025
2
+ distributionBase=GRADLE_USER_HOME
3
+ distributionPath=wrapper/dists
4
+ distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.1-bin.zip
5
+ networkTimeout=10000
6
+ validateDistributionUrl=true
7
+ zipStoreBase=GRADLE_USER_HOME
8
+ zipStorePath=wrapper/dists