@momo-kits/native-kits 0.162.2-sp.7-debug → 0.162.2-sp.8-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 (160) hide show
  1. package/.claude/settings.local.json +15 -1
  2. package/CLAUDE.md +78 -0
  3. package/compose/build.gradle.kts +12 -31
  4. package/compose/build.gradle.kts.backup +11 -30
  5. package/compose/compose.podspec +1 -1
  6. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +7 -0
  7. package/compose/src/commonMain/kotlin/vn/momo/kits/application/AnimationSearchInput.kt +2 -7
  8. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +8 -11
  9. package/compose/src/commonMain/kotlin/vn/momo/kits/application/FloatingButton.kt +6 -24
  10. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Header.kt +4 -19
  11. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderAnimated.kt +1 -10
  12. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderBackground.kt +2 -2
  13. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderDefault.kt +1 -1
  14. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderExtended.kt +1 -1
  15. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderRight.kt +6 -17
  16. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderTitle.kt +1 -1
  17. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +6 -101
  18. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +269 -0
  19. package/compose/src/commonMain/kotlin/vn/momo/kits/application/NavigationContainer.kt +8 -19
  20. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Screen.kt +8 -33
  21. package/compose/src/commonMain/kotlin/vn/momo/kits/application/useHeaderSearchAnimation.kt +1 -1
  22. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +22 -25
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +27 -29
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +3 -26
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +30 -31
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +3 -13
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +0 -5
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +3 -11
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +3 -18
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +11 -11
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +42 -65
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +69 -26
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +1 -5
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +84 -59
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +13 -71
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +10 -51
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +6 -1
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +4 -21
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +1 -1
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +16 -75
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +5 -26
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +1 -1
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +3 -11
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +16 -40
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +3 -9
  46. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +0 -28
  47. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +2 -13
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +4 -0
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +4 -10
  50. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +3 -28
  51. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +8 -47
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +4 -25
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +2 -11
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +1 -17
  55. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +1 -6
  56. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +50 -111
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +1 -5
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +1 -5
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +1 -12
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +4 -96
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +5 -7
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +2 -12
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +9 -21
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +2 -2
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +9 -14
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +8 -11
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/const/KitFontScale.kt +22 -0
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +1 -1
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +11 -20
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +1 -1
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +0 -5
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +0 -2
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +94 -4
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +0 -2
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +2 -2
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +3 -7
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +9 -15
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +36 -24
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +48 -33
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +67 -61
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +6 -13
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +13 -31
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +1 -1
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +6 -24
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +11 -6
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +2 -1
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +9 -6
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +1 -1
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +3 -13
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +3 -2
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +1 -40
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +0 -2
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +9 -0
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +0 -8
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +2 -17
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +1 -1
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +3 -3
  98. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +2 -3
  99. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +66 -0
  100. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +0 -2
  101. package/gradle/libs.versions.toml +2 -0
  102. package/gradle.properties +1 -1
  103. package/ios/Application/ApplicationEnvironment.swift +4 -2
  104. package/ios/Application/Components.swift +16 -0
  105. package/ios/Application/Localize.swift +277 -0
  106. package/ios/Application/MaxApi.swift +18 -0
  107. package/ios/Application/Navigation/BottomTab/BottomTab.swift +1 -0
  108. package/ios/Application/Navigation/NavigationContainer.swift +27 -3
  109. package/ios/Application/Navigation/Navigator.swift +50 -29
  110. package/ios/Application/Navigation/Overplay/BottomSheet.swift +87 -19
  111. package/ios/Application/Navigation/Overplay/ModalScreen.swift +6 -0
  112. package/ios/Application/Navigation/Tracking/ScreenTracker.swift +117 -0
  113. package/ios/Application/Screen.swift +1 -1
  114. package/ios/Application/StackScreen.swift +49 -1
  115. package/ios/Badge/BadgeRibbon.swift +80 -0
  116. package/ios/Button/Button.swift +68 -12
  117. package/ios/Carousel/Carousel.swift +16 -1
  118. package/ios/Checkbox/Checkbox.swift +14 -20
  119. package/ios/Chip/Chip.swift +35 -26
  120. package/ios/Collapse/Collapse.swift +11 -1
  121. package/ios/Colors+Radius+Spacing/Colors.swift +9 -6
  122. package/ios/Colors+Radius+Spacing/Spacing.swift +3 -1
  123. package/ios/DateTimePicker/DateTimePicker.swift +4 -2
  124. package/ios/DateTimePicker/WheelPicker.swift +7 -3
  125. package/ios/Extensions/ActiveOpacityButtonStyle.swift +14 -0
  126. package/ios/Extensions/Color++.swift +5 -2
  127. package/ios/Icon/Icon.swift +5 -1
  128. package/ios/IconButton/IconButton.swift +35 -7
  129. package/ios/Image/Image.swift +16 -3
  130. package/ios/Information/Information.swift +3 -1
  131. package/ios/Input/ErrorView.swift +3 -1
  132. package/ios/Input/Input.swift +31 -8
  133. package/ios/Input/InputPhoneNumber.swift +14 -3
  134. package/ios/Input/InputSearch.swift +7 -1
  135. package/ios/Input/InputTextArea.swift +78 -34
  136. package/ios/InputDropDown/InputDropDown.swift +4 -1
  137. package/ios/InputMoney/InputMoney.swift +16 -4
  138. package/ios/PARITY_AUDIT.md +641 -0
  139. package/ios/Popup/PopupDisplay.swift +3 -4
  140. package/ios/Popup/PopupNotify.swift +3 -4
  141. package/ios/Popup/PopupPromotion.swift +16 -8
  142. package/ios/ProgressInfo/ProgressInfo.swift +4 -2
  143. package/ios/Radio/Radio.swift +12 -13
  144. package/ios/Rating/Rating.swift +1 -1
  145. package/ios/Stepper/Stepper.swift +2 -2
  146. package/ios/Steps/Steps.swift +22 -6
  147. package/ios/SuggestAction/SuggestAction.swift +5 -3
  148. package/ios/Swipeable/SwipeCell.swift +5 -3
  149. package/ios/Switch/Switch.swift +53 -28
  150. package/ios/TabView/TabView.swift +18 -14
  151. package/ios/Template/TrustBanner/TrustBanner.swift +6 -7
  152. package/ios/Tooltip/Tooltip.swift +3 -0
  153. package/ios/Typography/FontScaleStore.swift +19 -0
  154. package/ios/Typography/Text.swift +3 -0
  155. package/ios/Typography/Typography.swift +8 -5
  156. package/ios/Uploader/Uploader.swift +0 -9
  157. package/ios/native-kits.podspec +1 -1
  158. package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
  159. package/package.json +1 -1
  160. package/ios/Colors+Radius+Spacing/MoMoUIKitsResources.swift +0 -2
@@ -1,14 +1,104 @@
1
1
  package vn.momo.kits.modifier
2
2
 
3
- import androidx.compose.foundation.background
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
4
9
  import androidx.compose.runtime.Composable
10
+ import androidx.compose.runtime.getValue
5
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
6
21
  import vn.momo.kits.application.IsShowBaseLineDebug
7
22
  import vn.momo.kits.const.Colors
8
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
+
9
45
  @Composable
10
- fun DeprecatedModifier(): Modifier {
11
- return Modifier.conditional(IsShowBaseLineDebug) {
12
- background(Colors.red_01.copy(alpha = 0.5f))
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
+ }
13
103
  }
14
104
  }
@@ -9,8 +9,6 @@ import androidx.compose.ui.unit.Dp
9
9
  import androidx.compose.ui.unit.dp
10
10
  import vn.momo.kits.platform.setColor
11
11
  import vn.momo.kits.platform.setMaskFilter
12
-
13
-
14
12
  fun Modifier.shadow(
15
13
  color: Color = Color.Black,
16
14
  borderRadius: Dp = 0.dp,
@@ -41,7 +41,7 @@ import vn.momo.kits.const.AppTheme
41
41
  import vn.momo.kits.const.Colors
42
42
  import vn.momo.kits.const.Radius
43
43
  import vn.momo.kits.const.Spacing
44
- import vn.momo.kits.application.ApplicationContext
44
+ import vn.momo.kits.application.LocalContext
45
45
  import vn.momo.kits.application.IsShowBaseLineDebug
46
46
  import vn.momo.kits.const.Typography
47
47
  import vn.momo.kits.navigation.tracking.ScreenTracker
@@ -73,7 +73,7 @@ internal fun BottomSheet(
73
73
  val coroutineScope = rememberCoroutineScope()
74
74
 
75
75
  val maxApi = LocalMaxApi.current
76
- val context = ApplicationContext.current
76
+ val context = LocalContext.current
77
77
 
78
78
  DisposableEffect(Unit) {
79
79
  ScreenTracker.trackPopupDisplayed(
@@ -10,11 +10,7 @@ import androidx.compose.foundation.interaction.MutableInteractionSource
10
10
  import androidx.compose.foundation.layout.Box
11
11
  import androidx.compose.foundation.layout.fillMaxSize
12
12
  import androidx.compose.foundation.layout.wrapContentSize
13
- import androidx.compose.runtime.Composable
14
- import androidx.compose.runtime.DisposableEffect
15
- import androidx.compose.runtime.LaunchedEffect
16
- import androidx.compose.runtime.remember
17
- import androidx.compose.runtime.rememberCoroutineScope
13
+ import androidx.compose.runtime.*
18
14
  import androidx.compose.ui.Alignment
19
15
  import androidx.compose.ui.Modifier
20
16
  import androidx.compose.ui.draw.alpha
@@ -22,7 +18,7 @@ import androidx.compose.ui.draw.scale
22
18
  import androidx.compose.ui.graphics.Color
23
19
  import androidx.compose.ui.unit.dp
24
20
  import kotlinx.coroutines.launch
25
- import vn.momo.kits.application.ApplicationContext
21
+ import vn.momo.kits.application.LocalContext
26
22
  import vn.momo.kits.application.IsShowBaseLineDebug
27
23
  import vn.momo.kits.const.Colors
28
24
  import vn.momo.kits.modifier.conditional
@@ -44,7 +40,7 @@ internal fun ModalScreen(
44
40
  val coroutineScope = rememberCoroutineScope()
45
41
 
46
42
  val maxApi = LocalMaxApi.current
47
- val context = ApplicationContext.current
43
+ val context = LocalContext.current
48
44
 
49
45
  DisposableEffect(Unit) {
50
46
  ScreenTracker.trackPopupDisplayed(
@@ -1,29 +1,25 @@
1
1
  package vn.momo.kits.navigation
2
2
 
3
3
  import androidx.compose.foundation.gestures.ScrollableState
4
- import androidx.compose.runtime.Composable
5
- import androidx.compose.runtime.Stable
6
- import androidx.compose.runtime.State
7
- import androidx.compose.runtime.mutableStateOf
8
- import androidx.compose.runtime.staticCompositionLocalOf
4
+ import androidx.compose.runtime.*
9
5
  import androidx.compose.ui.graphics.Color
10
6
  import vn.momo.kits.navigation.bottomtab.setBottomTabOption
11
- import vn.momo.kits.navigation.component.FloatingButtonProps
12
- import vn.momo.kits.navigation.component.HeaderBackProps
13
- import vn.momo.kits.navigation.component.HeaderRight
14
- import vn.momo.kits.navigation.component.HeaderTitle
15
- import vn.momo.kits.navigation.component.HeaderType
16
- import vn.momo.kits.navigation.component.TitlePosition
7
+ import vn.momo.kits.navigation.component.*
17
8
 
18
9
  class Navigation(
19
10
  val id: Int = -1,
20
11
  val bottomTabIndex: Int = -1,
21
- val initOptions: NavigationOptions? = null
12
+ val initOptions: NavigationOptions? = null,
13
+ private val registry: DynamicScreenRegistry? = null
22
14
  ) {
23
15
  private val _options = mutableStateOf(initOptions ?: NavigationOptions())
24
16
  val currentOptions: State<NavigationOptions> get() = _options
25
17
  val options: NavigationOptions get() = _options.value
26
18
 
19
+ private val _isBottomTabRoot = mutableStateOf(false)
20
+ internal val isBottomTabRoot: Boolean get() = _isBottomTabRoot.value
21
+ internal fun markAsBottomTabRoot() { _isBottomTabRoot.value = true }
22
+
27
23
  fun setOptions(
28
24
  onBackHandler: (() -> Unit)? = null,
29
25
  hiddenBack: Boolean? = null,
@@ -65,7 +61,7 @@ class Navigation(
65
61
  private fun updateOptions(updated: NavigationOptions) {
66
62
  _options.value = updated
67
63
  if (bottomTabIndex != -1) setBottomTabOption(bottomTabIndex, updated)
68
- if (id != -1) DynamicScreenRegistry.setOptions(id, updated)
64
+ if (id != -1) registry?.setOptions(id, updated)
69
65
  }
70
66
  }
71
67
 
@@ -95,8 +91,6 @@ data class KeyboardOptions(
95
91
  val keyboardShouldPersistTaps: Boolean = false,
96
92
  val useAvoidKeyboard: Boolean = true
97
93
  )
98
-
99
-
100
94
  data class ScrollData(
101
95
  val scrollable: Boolean = true,
102
96
  val scrollState: ScrollableState? = null,
@@ -12,6 +12,7 @@ import androidx.navigation.toRoute
12
12
  import vn.momo.kits.application.*
13
13
  import vn.momo.kits.const.*
14
14
  import vn.momo.kits.platform.ProvideNavigationEventDispatcherOwner
15
+ import vn.momo.kits.platform.ProvideOsFontScale
15
16
  import vn.momo.kits.utils.getAppStatusBarHeight
16
17
  import vn.momo.kits.utils.getNavigationBarHeight
17
18
  import vn.momo.maxapi.IMaxApi
@@ -22,50 +23,53 @@ fun NavigationContainer(
22
23
  initialScreen: @Composable () -> Unit,
23
24
  options: NavigationOptions? = null,
24
25
  initialTheme: Theme = defaultTheme,
25
- applicationContext: MiniAppContext? = null,
26
+ miniAppContext: MiniAppContext? = null,
26
27
  maxApi: IMaxApi? = null,
27
28
  setNavigator: ((Navigator) -> Unit)? = null,
28
29
  statusBarHeight: Dp? = null,
29
- config: KitConfig? = null,
30
- language: String? = null
30
+ localize: Localize? = null,
31
31
  ){
32
32
  val navController = rememberNavController()
33
- val navigator = remember { Navigator(navController = navController, maxApi = maxApi) }
33
+ val registry = remember { DynamicScreenRegistry() }
34
+ val navigator = remember { Navigator(navController = navController, maxApi = maxApi, registry = registry) }
34
35
  val statusBarHeight = statusBarHeight ?: getAppStatusBarHeight()
35
36
  val navigationBarHeight = getNavigationBarHeight()
36
37
 
37
- val parentContext = ApplicationContext.current
38
- val mergedContext = MiniAppContext.merge(parentContext, applicationContext)
38
+ val parentContext = LocalContext.current
39
+ val mergedContext = MiniAppContext.merge(parentContext, miniAppContext)
39
40
 
40
41
  val theme = remember { mutableStateOf(initialTheme) }
42
+ val fallbackLocalize = remember { Localize() }
41
43
 
42
- LaunchedEffect(Unit) {
43
- val headerBar = config?.headerBar
44
- if (headerBar != null && theme.value.assets.headerBackground == null) {
45
- theme.value = theme.value.copy(
46
- assets = ThemeAssets(
47
- headerBackground = headerBar
48
- )
49
- )
44
+ val resolvedLocalize = localize ?: fallbackLocalize
45
+
46
+ LaunchedEffect(maxApi, resolvedLocalize) {
47
+ val api = maxApi ?: return@LaunchedEffect
48
+ runCatching {
49
+ api.getLanguage(callback = { data ->
50
+ if (parseLanguage(data) == Localize.EN) {
51
+ resolvedLocalize.changeLanguage(Localize.EN)
52
+ }
53
+ })
50
54
  }
51
55
  }
52
56
 
53
- val screenId = rememberSaveable { DynamicScreenRegistry.nextId() }
54
- DynamicScreenRegistry.bind(screenId, initialScreenName, initialScreen, options)
57
+ val screenId = rememberSaveable { registry.nextId() }
58
+ registry.bind(screenId, initialScreenName, initialScreen, options)
55
59
  val startDestination = remember(screenId) { DynamicScreenRoute(screenId) }
56
60
 
61
+ ProvideOsFontScale {
57
62
  ProvideNavigationEventDispatcherOwner {
58
63
  CompositionLocalProvider(
59
64
  LocalNavigator provides navigator,
65
+ LocalDynamicScreenRegistry provides registry,
60
66
  LocalMaxApi provides maxApi,
61
67
  AppTheme provides theme.value,
62
68
  AppStatusBar provides statusBarHeight,
63
69
  AppNavigationBar provides navigationBarHeight,
64
- ApplicationContext provides mergedContext,
65
- AppConfig provides config,
66
- AppLanguage provides language,
67
- ScaleSizeMaxRate provides mergedContext?.scaleSizeMaxRate,
68
- ) {
70
+ LocalContext provides mergedContext,
71
+ LocalLocalize provides resolvedLocalize,
72
+ ) {
69
73
  LaunchedEffect(Unit) {
70
74
  setNavigator?.invoke(navigator)
71
75
  }
@@ -88,7 +92,7 @@ fun NavigationContainer(
88
92
  }
89
93
  ) { backStackEntry ->
90
94
  val route = backStackEntry.toRoute<DynamicScreenRoute>()
91
- val screen = DynamicScreenRegistry.getScreen(route.id)
95
+ val screen = registry.getScreen(route.id)
92
96
 
93
97
  if (screen != null) {
94
98
  StackScreen(
@@ -117,7 +121,7 @@ fun NavigationContainer(
117
121
  }
118
122
  ) { backStackEntry ->
119
123
  val route = backStackEntry.toRoute<DynamicDialogRoute>()
120
- val screen = DynamicScreenRegistry.getScreen(route.id)
124
+ val screen = registry.getScreen(route.id)
121
125
 
122
126
  if (screen != null) {
123
127
  StackScreen(
@@ -131,11 +135,12 @@ fun NavigationContainer(
131
135
  }
132
136
  }
133
137
  }
138
+ }
134
139
 
135
140
  DisposableEffect(Unit) {
136
141
  onDispose {
137
142
  navigator.dispose()
138
- DynamicScreenRegistry.unregisterScreen(screenId)
143
+ registry.unregisterScreen(screenId)
139
144
  }
140
145
  }
141
146
  }
@@ -143,3 +148,10 @@ fun NavigationContainer(
143
148
  val LocalMaxApi = staticCompositionLocalOf<IMaxApi?> {
144
149
  error("No MaxApi provided")
145
150
  }
151
+
152
+ private fun parseLanguage(raw: Map<String, Any?>?): String? {
153
+ val code = (raw?.get("response") as? String)?.trim()?.lowercase()
154
+ if (code.isNullOrEmpty()) return null
155
+ return if (code.startsWith(Localize.EN)) Localize.EN else Localize.VI
156
+ }
157
+
@@ -9,6 +9,7 @@ import androidx.compose.runtime.staticCompositionLocalOf
9
9
  import androidx.compose.ui.Alignment
10
10
  import androidx.compose.ui.Modifier
11
11
  import androidx.navigation.NavController
12
+ import androidx.navigation.toRoute
12
13
  import kotlinx.coroutines.CoroutineScope
13
14
  import kotlinx.coroutines.Dispatchers
14
15
  import kotlinx.coroutines.SupervisorJob
@@ -21,30 +22,38 @@ import vn.momo.kits.components.PopupNotify
21
22
  import vn.momo.kits.navigation.BottomHeader.*
22
23
  import vn.momo.kits.navigation.component.SnackBar
23
24
  import vn.momo.maxapi.IMaxApi
25
+ import kotlin.time.Duration.Companion.milliseconds
24
26
 
25
27
  class Navigator(
26
28
  private val navController: NavController,
27
- private val maxApi: IMaxApi?
29
+ private val maxApi: IMaxApi?,
30
+ private val registry: DynamicScreenRegistry
28
31
  ) {
29
32
  private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
30
33
 
34
+ private fun currentScreen(): DynamicScreen? {
35
+ val entry = navController.currentBackStackEntry ?: return null
36
+ val id = runCatching { entry.toRoute<DynamicScreenRoute>().id }.getOrNull()
37
+ ?: runCatching { entry.toRoute<DynamicDialogRoute>().id }.getOrNull()
38
+ ?: return null
39
+ return registry.getScreen(id)
40
+ }
41
+
31
42
  fun push(screenName: String, content: @Composable () -> Unit, options: NavigationOptions? = null) {
32
- val route = DynamicScreenRegistry.register(screenName, content, options)
43
+ val route = registry.register(screenName, content, options)
33
44
  navController.navigate(DynamicScreenRoute(route.id))
34
45
  }
35
46
 
36
47
  fun replace(screenName: String, content: @Composable () -> Unit, options: NavigationOptions? = null) {
37
- if (navController.previousBackStackEntry != null){
38
- val latestScreen = DynamicScreenRegistry.getLatestScreen()
39
- latestScreen?.let { DynamicScreenRegistry.unregisterScreen(it.id) }
40
- navController.popBackStack()
41
- push(screenName, content, options)
42
- }
48
+ val replacedScreen = currentScreen()
49
+ replacedScreen?.let { registry.unregisterScreen(it.id) }
50
+ navController.popBackStack()
51
+ push(screenName, content, options)
43
52
  }
44
53
 
45
54
  fun onBackSafe(callBack: (() -> Unit)? = null) {
46
- val latestScreen = DynamicScreenRegistry.getLatestScreen()
47
- val options = latestScreen?.options
55
+ val currentScreen = currentScreen()
56
+ val options = currentScreen?.options
48
57
  if (options?.onBackHandler != null) {
49
58
  options.onBackHandler.invoke()
50
59
  return
@@ -87,31 +96,30 @@ class Navigator(
87
96
  }
88
97
  private suspend fun dismissOverplay(isDelay: Boolean = true) {
89
98
  OverplayComponentRegistry.clear()
90
- if (isDelay) delay(300L)
99
+ if (isDelay) delay(300L.milliseconds)
91
100
  OverplayComponentRegistry.hardClearAfterDismiss()
92
101
  }
93
102
 
94
103
  private suspend fun dismissScreen() {
95
104
  if (navController.previousBackStackEntry != null){
105
+ val dismissing = currentScreen()
96
106
  navController.popBackStack()
97
- delay(300L)
98
- DynamicScreenRegistry.getLatestScreen()?.let { it1 ->
99
- DynamicScreenRegistry.unregisterScreen(it1.id)
100
- }
107
+ delay(300L.milliseconds)
108
+ dismissing?.let { registry.unregisterScreen(it.id) }
101
109
  } else {
102
110
  maxApi?.dismiss { }
103
111
  }
104
112
  }
105
113
 
106
114
  fun present(screenName: String, content: @Composable () -> Unit, options: NavigationOptions? = null) {
107
- val route = DynamicScreenRegistry.register(screenName, content, options)
115
+ val route = registry.register(screenName, content, options)
108
116
  navController.navigate(DynamicDialogRoute(route.id))
109
117
  }
110
118
 
111
119
  fun reset(screenName: String, content: @Composable () -> Unit, options: NavigationOptions? = null) {
112
- DynamicScreenRegistry.unregisterAll()
120
+ registry.unregisterAll()
113
121
 
114
- val route = DynamicScreenRegistry.register(screenName, content, options)
122
+ val route = registry.register(screenName, content, options)
115
123
  navController.navigate(DynamicScreenRoute(route.id)) {
116
124
  popUpTo(0) { inclusive = true }
117
125
  }
@@ -122,7 +130,7 @@ class Navigator(
122
130
  barrierDismissible: Boolean = true,
123
131
  onDismiss: (() -> Unit)? = null
124
132
  ){
125
- val id = DynamicScreenRegistry.getLatestScreen()?.id ?: -1
133
+ val id = currentScreen()?.id ?: -1
126
134
  OverplayComponentRegistry.registerOverplay(id, content, OverplayComponentType.MODAL, false, barrierDismissible, onDismiss)
127
135
  }
128
136
 
@@ -133,12 +141,12 @@ class Navigator(
133
141
  onDismiss: (() -> Unit)? = null,
134
142
  bottomSheetHeader: BottomHeader? = null
135
143
  ){
136
- val id = DynamicScreenRegistry.getLatestScreen()?.id ?: -1
144
+ val id = currentScreen()?.id ?: -1
137
145
  OverplayComponentRegistry.registerOverplay(id, content, OverplayComponentType.BOTTOM_SHEET, isSurface, barrierDismissible, onDismiss, bottomSheetHeader)
138
146
  }
139
147
 
140
148
  fun showSnackBar(snackBar: SnackBar, onDismiss: (() -> Unit)? = null) {
141
- val id = DynamicScreenRegistry.getLatestScreen()?.id ?: -1
149
+ val id = currentScreen()?.id ?: -1
142
150
  scope.launch {
143
151
  OverplayComponentRegistry.registerOverplay(
144
152
  id = id,
@@ -154,7 +162,7 @@ class Navigator(
154
162
  fun hideSnackBar() {
155
163
  scope.launch {
156
164
  OverplayComponentRegistry.clear()
157
- delay(250L)
165
+ delay(250L.milliseconds)
158
166
  OverplayComponentRegistry.hardClearAfterDismiss()
159
167
  }
160
168
  }
@@ -181,12 +189,11 @@ data class DynamicScreen(
181
189
  var options: NavigationOptions? = null
182
190
  )
183
191
 
184
- object DynamicScreenRegistry {
192
+ class DynamicScreenRegistry {
185
193
  private val screens = mutableMapOf<Int, DynamicScreen>()
186
- private var idCounter = 1
187
194
 
188
195
  fun register(screenName: String, content: @Composable () -> Unit, options: NavigationOptions?): DynamicScreenRoute {
189
- val id = idCounter++
196
+ val id = nextGlobalId()
190
197
  screens[id] = DynamicScreen(
191
198
  id = id,
192
199
  name = screenName,
@@ -196,7 +203,7 @@ object DynamicScreenRegistry {
196
203
  return DynamicScreenRoute(id)
197
204
  }
198
205
 
199
- fun nextId(): Int = idCounter++
206
+ fun nextId(): Int = nextGlobalId()
200
207
 
201
208
  fun bind(id: Int, screenName: String, content: @Composable () -> Unit, options: NavigationOptions?) {
202
209
  screens[id] = DynamicScreen(
@@ -205,17 +212,13 @@ object DynamicScreenRegistry {
205
212
  content = content,
206
213
  options = options
207
214
  )
208
- if (id >= idCounter) idCounter = id + 1 // keep counter ahead after process-death restore
215
+ advanceGlobalIdPast(id) // keep counter ahead after process-death restore
209
216
  }
210
217
 
211
218
  fun unregisterScreen(id: Int) {
212
219
  screens.remove(id)
213
220
  }
214
221
 
215
- fun getLatestScreen(): DynamicScreen?{
216
- return screens.entries.lastOrNull()?.value
217
- }
218
-
219
222
  fun unregisterAll(){
220
223
  val ids = screens.keys.toList()
221
224
  for (id in ids) {
@@ -228,8 +231,20 @@ object DynamicScreenRegistry {
228
231
  fun setOptions(id: Int, options: NavigationOptions){
229
232
  screens[id]?.options = options
230
233
  }
234
+
235
+ companion object {
236
+ private var globalIdCounter = 1
237
+
238
+ private fun nextGlobalId(): Int = globalIdCounter++
239
+
240
+ private fun advanceGlobalIdPast(id: Int) {
241
+ if (id >= globalIdCounter) globalIdCounter = id + 1
242
+ }
243
+ }
231
244
  }
232
245
 
246
+ val LocalDynamicScreenRegistry = staticCompositionLocalOf<DynamicScreenRegistry?> { null }
247
+
233
248
 
234
249
  sealed class OverplayComponentParams {
235
250
  class Modal(
@@ -244,7 +259,7 @@ sealed class OverplayComponentParams {
244
259
  val bottomSheetHeader: BottomHeader? = null,
245
260
  ) : OverplayComponentParams()
246
261
 
247
- class SnackBar() : OverplayComponentParams()
262
+ class SnackBar : OverplayComponentParams()
248
263
  }
249
264
 
250
265
  data class OverplayComponent(
@@ -308,7 +323,7 @@ object OverplayComponentRegistry {
308
323
  }
309
324
 
310
325
  @Composable
311
- fun OverlayComponent(){
326
+ internal fun OverlayComponent(){
312
327
  val overplay = currentOverlayComponent.value ?: return
313
328
 
314
329
  when (val params = overplay.params) {