@momo-kits/native-kits 0.168.1-beta.4-debug → 0.168.1-beta.40-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 (100) hide show
  1. package/CLAUDE.md +15 -10
  2. package/README.md +2 -10
  3. package/build.gradle.kts +1 -3
  4. package/compose/build.gradle.kts +20 -19
  5. package/compose/build.gradle.kts.backup +19 -18
  6. package/compose/compose.podspec +1 -1
  7. package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +4 -3
  8. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +3 -2
  9. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +17 -0
  10. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReservedRegions.android.kt +1 -1
  11. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +0 -14
  12. package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +62 -0
  13. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +14 -23
  14. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +21 -15
  15. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +84 -82
  16. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +3 -3
  17. package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +2 -1
  18. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +18 -14
  19. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +187 -0
  20. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +20 -13
  21. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +117 -62
  22. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +22 -6
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +4 -7
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +16 -26
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +54 -36
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +18 -11
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +1 -6
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +35 -29
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +321 -149
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +79 -71
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +2 -3
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +89 -198
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +104 -0
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +1 -1
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +3 -1
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +30 -44
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +2 -2
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +32 -40
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +3 -2
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +3 -1
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +7 -0
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +12 -3
  43. package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +3 -1
  44. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +2 -6
  45. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +12 -10
  46. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +48 -0
  47. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +60 -10
  48. package/gradle/libs.versions.toml +4 -11
  49. package/gradle/wrapper/gradle-wrapper.properties +1 -3
  50. package/gradle.properties +3 -3
  51. package/ios/Application/ApplicationEnvironment.swift +7 -6
  52. package/ios/Application/DesignSystemKits.swift +163 -0
  53. package/ios/Application/DesignSystemKitsPayload.swift +68 -0
  54. package/ios/Badge/BadgeRibbon.swift +8 -1
  55. package/ios/Extensions/Color++.swift +2 -4
  56. package/ios/Input/Input.swift +16 -4
  57. package/ios/Input/InputPhoneNumber.swift +1 -3
  58. package/ios/Input/InputSearch.swift +1 -2
  59. package/ios/Input/InputTextArea.swift +8 -4
  60. package/ios/InputMoney/InputMoney.swift +6 -7
  61. package/ios/Layout/ModalLayout.swift +152 -0
  62. package/ios/Layout/ScreenLayout.swift +77 -18
  63. package/ios/Navigation/BottomSheet.swift +56 -53
  64. package/ios/Navigation/BottomTab/BottomTab.swift +46 -52
  65. package/ios/Navigation/BottomTab/BottomTabBar.swift +281 -115
  66. package/ios/Navigation/BottomTab/CurvedContainer.swift +51 -47
  67. package/ios/Navigation/BottomTab/DuoBarCompression.swift +2 -3
  68. package/ios/Navigation/BottomTab/DuoTabBar.swift +64 -172
  69. package/ios/Navigation/BottomTab/TabBarMetrics.swift +84 -0
  70. package/ios/Navigation/Component/HeaderBackground.swift +22 -1
  71. package/ios/Navigation/Component/HeaderRight.swift +1 -1
  72. package/ios/Navigation/Component/SnackBar.swift +4 -0
  73. package/ios/Navigation/ModalScreen.swift +20 -5
  74. package/ios/Navigation/StackScreen.swift +6 -8
  75. package/ios/Popup/PopupDisplay.swift +6 -4
  76. package/ios/Popup/PopupInput.swift +6 -4
  77. package/ios/Popup/PopupLayout.swift +17 -11
  78. package/ios/Popup/PopupNotify.swift +32 -25
  79. package/ios/Stepper/Stepper.swift +1 -2
  80. package/ios/Template/TrustBanner/TrustBanner.swift +4 -2
  81. package/ios/Typography/FontScale.swift +29 -15
  82. package/ios/Typography/Text.swift +88 -14
  83. package/ios/Typography/Typography.swift +2 -2
  84. package/ios/native-kits.podspec +1 -1
  85. package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
  86. package/ios-demo/Resources/tabbar_scan_qr_button.json +1 -0
  87. package/ios-demo/Resources/tabbar_scan_qr_label.json +1 -0
  88. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +272 -59
  89. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/NavigationDemo.swift +103 -0
  90. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/PopupNotifyDemo.swift +29 -1
  91. package/package.json +1 -1
  92. package/publish.sh +2 -33
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/const/KitDesignSystem.kt +0 -18
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/const/KitFontScale.kt +0 -22
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HelpCenterRequest.kt +0 -37
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/ToolkitRequests.kt +0 -41
  97. package/compose/src/commonTest/kotlin/vn/momo/kits/navigation/component/HelpCenterRequestTest.kt +0 -44
  98. package/compose/src/commonTest/kotlin/vn/momo/kits/navigation/component/ToolkitRequestsTest.kt +0 -62
  99. package/ios/Typography/FontScaleStore.swift +0 -58
  100. package/ios/Typography/KitDesignSystem.swift +0 -17
@@ -202,6 +202,13 @@ private struct NavigationDemoContent: View {
202
202
  )
203
203
  }
204
204
 
205
+ row("Header Types") {
206
+ navigator.push(
207
+ { HeaderTypesScreen() },
208
+ options: NavigationOptions(title: "Header Types")
209
+ )
210
+ }
211
+
205
212
  row("Bottom Tabs") {
206
213
  navigator.push(
207
214
  { BottomTabDemoContent() },
@@ -253,6 +260,102 @@ private struct UpdateOptionsScreen: View {
253
260
  }
254
261
  }
255
262
 
263
+ /// Header options switched at runtime (Compose `HeaderTypeUsage`).
264
+ @available(iOS 16.0, *)
265
+ private struct HeaderTypesScreen: View {
266
+ private enum Kind: String, CaseIterable {
267
+ case none = "None", `default` = "Default", extended = "Extended", transparent = "Transparent"
268
+ }
269
+
270
+ private enum HeaderRightOption: String, CaseIterable {
271
+ case toolkit = "Toolkit", homeOnly = "Home only", none = "None"
272
+ }
273
+
274
+ @EnvironmentObject private var navigation: Navigation
275
+ @Environment(\.applicationEnvironment) private var applicationEnvironment
276
+ @State private var kind: AnyHashable = Kind.default
277
+ @State private var titlePosition: AnyHashable = TitlePosition.left
278
+ @State private var showBack = true
279
+ @State private var headerRight: AnyHashable = HeaderRightOption.toolkit
280
+ @State private var isAnimated = false
281
+ @State private var isHeader = false
282
+ @State private var isFullScreenContent = false
283
+ @State private var searchText = ""
284
+
285
+ var body: some View {
286
+ VStack(alignment: .leading, spacing: Spacing.M) {
287
+ ForEach(Kind.allCases, id: \.self) { item in
288
+ Radio(value: item, groupValue: $kind, onChange: applyHeader, label: item.rawValue)
289
+ }
290
+ Divider()
291
+ MomoText("Title Position")
292
+ ForEach([TitlePosition.left, TitlePosition.center], id: \.self) { position in
293
+ Radio(value: position, groupValue: $titlePosition, onChange: {
294
+ navigation.setOptions { $0.titlePosition = position }
295
+ }, label: position == .left ? "LEFT" : "CENTER")
296
+ }
297
+ Divider()
298
+ Checkbox($showBack, onChange: { checked in
299
+ navigation.setOptions { $0.hiddenBack = !checked }
300
+ }, title: "Show Back")
301
+ MomoText("Header Right")
302
+ ForEach(HeaderRightOption.allCases, id: \.self) { option in
303
+ Radio(value: option, groupValue: $headerRight, onChange: { applyHeaderRight(option) }, label: option.rawValue)
304
+ }
305
+ Divider()
306
+ Checkbox($isAnimated, onChange: { checked in
307
+ if checked { isHeader = false }
308
+ applyHeader()
309
+ }, title: "Search Animated")
310
+ Checkbox($isHeader, onChange: { checked in
311
+ if checked { isAnimated = false }
312
+ applyHeader()
313
+ }, title: "Search Header")
314
+ if kind == AnyHashable(Kind.transparent) {
315
+ Checkbox($isFullScreenContent, onChange: { _ in applyHeader() }, title: "Is Full Screen Content")
316
+ }
317
+ Color.clear.frame(height: 1600)
318
+ }
319
+ .padding(Spacing.M)
320
+ }
321
+
322
+ private func applyHeaderRight(_ option: HeaderRightOption) {
323
+ let maxApi = applicationEnvironment.maxApi
324
+ navigation.setOptions {
325
+ $0.headerRightData = option == .toolkit ? HeaderRightData() : nil
326
+ $0.headerRight = option == .homeOnly ? {
327
+ NavigationButton(icon: "16_basic_home") { maxApi?.dismissAll(completion: nil) }
328
+ } : nil
329
+ }
330
+ }
331
+
332
+ private func applyHeader() {
333
+ let selected = kind.base as? Kind ?? .default
334
+ var search: InputSearchProps?
335
+ if isAnimated {
336
+ search = InputSearchProps(text: $searchText, placeholder: "Search input")
337
+ } else if isHeader {
338
+ search = InputSearchProps(text: $searchText, buttonText: "Huỷ", showButtonText: true, placeholder: "Search input")
339
+ }
340
+ navigation.setOptions {
341
+ switch selected {
342
+ case .none:
343
+ $0.headerType = .none
344
+ case .default, .extended:
345
+ $0.headerType = selected == .default ? .default : .extended
346
+ $0.useAnimated = isAnimated
347
+ $0.inputSearchProps = search
348
+ case .transparent:
349
+ $0.headerType = .default
350
+ $0.useAnimated = false
351
+ $0.inputSearchProps = nil
352
+ }
353
+ $0.headerTransparent = selected == .transparent
354
+ $0.fullScreenContent = selected == .transparent && isFullScreenContent
355
+ }
356
+ }
357
+ }
358
+
256
359
  @available(iOS 16.0, *)
257
360
  private struct DemoLeafScreen: View {
258
361
  @EnvironmentObject private var navigator: Navigator
@@ -13,6 +13,14 @@ struct PopupNotifyDemo: View {
13
13
 
14
14
  // MARK: - Preview
15
15
 
16
+ // Figma Risk - eKYC (node 51445-177824)
17
+ private let popupHighlightTitle = "Tạm khoá giao dịch để báo vệ bạn"
18
+ private let popupHighlightSentence =
19
+ "Mỗi ngày có ít nhất 20 người bị lừa đảo hơn 100 triệu đồng trong các giao dịch có dấu hiệu tương tự"
20
+ private let popupHighlightDescription =
21
+ "Hệ thống AI của MoMo đánh giá giao dịch này có dấu hiệu rủi ro. \(popupHighlightSentence)\n"
22
+ + "Hãy kiểm tra lại người nhận và lý do chuyển tiền trước khi quyết định tiếp tục."
23
+
16
24
  @available(iOS 16.0, *)
17
25
  private struct PopupNotifyPreview: View {
18
26
  @EnvironmentObject private var navigator: Navigator
@@ -21,6 +29,22 @@ private struct PopupNotifyPreview: View {
21
29
  BasicColumnBox("PopupNotify", alignment: .leading) {
22
30
  MoMoUIKits.Button(title: "Show popup", action: { show() }, size: .large)
23
31
  }
32
+ BasicColumnBox("Highlight text", alignment: .leading) {
33
+ MoMoUIKits.Button(title: "Show highlight popup", action: { showHighlight() }, type: .secondary, size: .large)
34
+ }
35
+ }
36
+
37
+ private func showHighlight() {
38
+ navigator.showModal {
39
+ PopupNotify(props: PopupNotifyProps(
40
+ title: popupHighlightTitle,
41
+ description: popupHighlightDescription,
42
+ primary: PopupAction(title: "Primary", onPress: { navigator.hideOverplay() }),
43
+ secondary: PopupAction(title: "Secondary", onPress: { navigator.hideOverplay() }),
44
+ onIconClose: { navigator.hideOverplay() },
45
+ highlightText: [popupHighlightSentence]
46
+ ))
47
+ }
24
48
  }
25
49
 
26
50
  private func show() {
@@ -53,6 +77,7 @@ private struct PopupNotifyPlayground: View {
53
77
  @State private var image = "https://static.momocdn.net/app/img/popup_permission/img_permission_popup_camera.png"
54
78
  @State private var title = "Title"
55
79
  @State private var description = "Check lại một nhịp auto chuyển sang dạng CTA."
80
+ @State private var highlightText = ""
56
81
  @State private var error = "9004"
57
82
  @State private var primaryTitle = "Primary"
58
83
  @State private var secondaryTitle = "Secondary"
@@ -68,6 +93,7 @@ private struct PopupNotifyPlayground: View {
68
93
  .string("Image", $image),
69
94
  .string("Title", $title),
70
95
  .string("Description", $description),
96
+ .string("HighlightText: [String] (comma-separated)", $highlightText),
71
97
  .string("Error", $error),
72
98
  .string("PrimaryTitle", $primaryTitle),
73
99
  .string("SecondaryTitle", $secondaryTitle),
@@ -88,7 +114,9 @@ private struct PopupNotifyPlayground: View {
88
114
  secondary: PopupAction(title: secondaryTitle, onPress: { navigator.hideOverplay() }),
89
115
  buttonDirection: (direction?.value as? PopupActionDirection) ?? .auto,
90
116
  onIconClose: { navigator.hideOverplay() },
91
- isShowCloseIcon: showClose
117
+ isShowCloseIcon: showClose,
118
+ highlightText: highlightText.components(separatedBy: ",")
119
+ .map { $0.trimmingCharacters(in: .whitespaces) }
92
120
  ))
93
121
  }
94
122
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/native-kits",
3
- "version": "0.168.1-beta.4-debug",
3
+ "version": "0.168.1-beta.40-debug",
4
4
  "private": false,
5
5
  "dependeNavigationncies": {},
6
6
  "devDependencies": {},
package/publish.sh CHANGED
@@ -379,12 +379,6 @@ phase_publish_npm() {
379
379
  exit 1
380
380
  fi
381
381
 
382
- # AI-GENERATED START: preserve an existing credential backup owned by another run
383
- if [ -e gradle.properties.npm-backup ]; then
384
- echo "❌ Error: gradle.properties.npm-backup already exists; recover it before publishing."
385
- exit 1
386
- fi
387
- # AI-GENERATED END: preserve an existing credential backup owned by another run
388
382
  echo "🔧 Preparing debug version with compose kits..."
389
383
 
390
384
  # Create debug version
@@ -395,9 +389,6 @@ phase_publish_npm() {
395
389
  restore_npm_workspace() {
396
390
  [ -f .npmignore.backup ] && mv .npmignore.backup .npmignore
397
391
  [ -f compose/build.gradle.kts.backup ] && mv compose/build.gradle.kts.backup compose/build.gradle.kts
398
- # AI-GENERATED START: restore private publishing credentials after npm packaging
399
- [ -f gradle.properties.npm-backup ] && mv gradle.properties.npm-backup gradle.properties
400
- # AI-GENERATED END: restore private publishing credentials after npm packaging
401
392
  local pkg_version
402
393
  pkg_version=$(node -p "require('./package.json').version")
403
394
  if [ "$pkg_version" != "$VERSION" ]; then
@@ -409,16 +400,6 @@ phase_publish_npm() {
409
400
  fi
410
401
  }
411
402
  trap restore_npm_workspace EXIT
412
- # AI-GENERATED START: keep private Maven credentials out of the debug npm package
413
- cp gradle.properties gradle.properties.npm-backup
414
- node <<'NODE'
415
- const fs = require('fs');
416
- const path = 'gradle.properties';
417
- const sanitized = fs.readFileSync(path, 'utf8')
418
- .replace(/^(gitlab\.(?:user|password)\s*=).*$/gm, '$1');
419
- fs.writeFileSync(path, sanitized);
420
- NODE
421
- # AI-GENERATED END: keep private Maven credentials out of the debug npm package
422
403
  echo "📦 Debug version: $DEBUG_VERSION"
423
404
 
424
405
  # Get current version from package.json (in case it's different from $VERSION)
@@ -455,18 +436,12 @@ NODE
455
436
  echo "🔧 Modifying android configuration for debug version..."
456
437
  if [[ "$OSTYPE" == "darwin"* ]]; then
457
438
  sed -i '' 's/namespace = "\$gitlabGroup\.\$gitlabArtifactId"/namespace = "vn.momo.kits.kits"/' compose/build.gradle.kts
458
- # AI-GENERATED START: keep the debug package on the approved SDK 36 toolchain
459
- sed -i '' \
460
- 's/compileSdk = libs\.versions\.android\.compileSdk\.get()\.toInt()/compileSdk = 36/' compose/build.gradle.kts
461
- # AI-GENERATED END: keep the debug package on the approved SDK 36 toolchain
439
+ sed -i '' 's/compileSdk = libs\.versions\.android\.compileSdk\.get()\.toInt()/compileSdk = 35/' compose/build.gradle.kts
462
440
  sed -i '' 's/minSdk = libs\.versions\.android\.minSdk\.get()\.toInt()/minSdk = 24/' compose/build.gradle.kts
463
441
  sed -i '' "s/version = gitlabVersion/version = \"$DEBUG_VERSION\"/" compose/build.gradle.kts
464
442
  else
465
443
  sed -i 's/namespace = "\$gitlabGroup\.\$gitlabArtifactId"/namespace = "vn.momo.kits.kits"/' compose/build.gradle.kts
466
- # AI-GENERATED START: keep the debug package on the approved SDK 36 toolchain
467
- sed -i \
468
- 's/compileSdk = libs\.versions\.android\.compileSdk\.get()\.toInt()/compileSdk = 36/' compose/build.gradle.kts
469
- # AI-GENERATED END: keep the debug package on the approved SDK 36 toolchain
444
+ sed -i 's/compileSdk = libs\.versions\.android\.compileSdk\.get()\.toInt()/compileSdk = 35/' compose/build.gradle.kts
470
445
  sed -i 's/minSdk = libs\.versions\.android\.minSdk\.get()\.toInt()/minSdk = 24/' compose/build.gradle.kts
471
446
  sed -i "s/version = gitlabVersion/version = \"$DEBUG_VERSION\"/" compose/build.gradle.kts
472
447
  fi
@@ -488,9 +463,6 @@ build/
488
463
  .gitattributes
489
464
  .gitlab-ci.yml
490
465
  .npmignore.backup
491
- # AI-GENERATED START: exclude the private credential backup from debug npm packages
492
- gradle.properties.npm-backup
493
- # AI-GENERATED END: exclude the private credential backup from debug npm packages
494
466
  EOF
495
467
 
496
468
  echo "📤 Publishing debug version (with compose)..."
@@ -505,9 +477,6 @@ EOF
505
477
  # Restore compose/build.gradle.kts
506
478
  mv compose/build.gradle.kts.backup compose/build.gradle.kts
507
479
  echo "✅ compose/build.gradle.kts restored"
508
- # AI-GENERATED START: restore credentials before leaving the debug packaging phase
509
- mv gradle.properties.npm-backup gradle.properties
510
- # AI-GENERATED END: restore credentials before leaving the debug packaging phase
511
480
 
512
481
  # Restore package.json version to original
513
482
  # Verify current version is debug version before restoring
@@ -1,18 +0,0 @@
1
- package vn.momo.kits.const
2
-
3
- import androidx.compose.runtime.getValue
4
- import androidx.compose.runtime.mutableStateOf
5
- import androidx.compose.runtime.setValue
6
-
7
- // Design-system rollout holder, same shape as KitFontScale: the kit is sandboxed and can't read the
8
- // host config, so the host seeds this once at startup from DesignSystemConfig. getFontFamily() reads
9
- // it to decide whether the new default font applies, so every screen follows the flag with no prop
10
- // threading. Backed by snapshot state: writes recompose text automatically.
11
- object KitDesignSystem {
12
- var isWhiteList by mutableStateOf(false)
13
- private set
14
-
15
- fun update(isWhiteList: Boolean) {
16
- this.isWhiteList = isWhiteList
17
- }
18
- }
@@ -1,22 +0,0 @@
1
- package vn.momo.kits.const
2
-
3
- import androidx.compose.runtime.getValue
4
- import androidx.compose.runtime.mutableStateOf
5
- import androidx.compose.runtime.setValue
6
-
7
- // App-wide font-scale holder. The kit is sandboxed and can't read the host cache directly, so the
8
- // host (which sees both core and this kit) seeds this once at startup and pushes runtime updates into
9
- // it. scaleSize() reads it as the fallback, so every screen — including direct NavigationContainer
10
- // screens with no host-pushed MiniAppContext — scales with no per-render prop and no async flicker.
11
- // Backed by snapshot state: writes recompose text automatically.
12
- object KitFontScale {
13
- var userScaleRate by mutableStateOf(1f)
14
- private set
15
- var useOSScaleRate by mutableStateOf(true)
16
- private set
17
-
18
- fun update(userScaleRate: Float, useOSScaleRate: Boolean) {
19
- this.userScaleRate = userScaleRate
20
- this.useOSScaleRate = useOSScaleRate
21
- }
22
- }
@@ -1,37 +0,0 @@
1
- // File: HelpCenterRequest.kt
2
- // Created At: 2026-10-19 +07:00
3
- // Created By: AI | AI Agent: Codex | Model: GPT-6
4
- // AI-GENERATED START: preserve the toolkit Help Center payload in the typed request
5
- package vn.momo.kits.navigation.component
6
-
7
- import kotlinx.serialization.json.JsonArray
8
- import kotlinx.serialization.json.JsonElement
9
- import kotlinx.serialization.json.JsonNull
10
- import kotlinx.serialization.json.JsonObject
11
- import kotlinx.serialization.json.JsonPrimitive
12
- import vn.momo.kits.application.MiniAppContext
13
- import vn.momo.maxapi.contract.navigation.model.BottomSheetRequest
14
- import vn.momo.maxapi.contract.navigation.model.HelpCenterContext
15
-
16
- internal fun MiniAppContext.helpCenterRequest() = BottomSheetRequest.HelpCenter(
17
- HelpCenterContext(
18
- appId = appId,
19
- code = appCode,
20
- name = appName?.helpCenterJson(),
21
- icon = appIcon,
22
- description = description?.helpCenterJson(),
23
- ),
24
- )
25
-
26
- private fun Any?.helpCenterJson(): JsonElement = when (this) {
27
- null -> JsonNull
28
- is JsonElement -> this
29
- is String -> JsonPrimitive(this)
30
- is Boolean -> JsonPrimitive(this)
31
- is Number -> JsonPrimitive(this)
32
- is Map<*, *> -> JsonObject(entries.associate { (key, value) -> key.toString() to value.helpCenterJson() })
33
- is Iterable<*> -> JsonArray(map { it.helpCenterJson() })
34
- is Array<*> -> JsonArray(map { it.helpCenterJson() })
35
- else -> JsonPrimitive(toString())
36
- }
37
- // AI-GENERATED END: preserve the toolkit Help Center payload in the typed request
@@ -1,41 +0,0 @@
1
- // File: ToolkitRequests.kt
2
- // Created At: 2026-10-12 +07:00 | Created By: AI | AI Agent: Codex | Model: GPT-6
3
- // AI-GENERATED START: cancel only toolkit requests owned by this composition
4
- package vn.momo.kits.navigation.component
5
-
6
- import vn.momo.maxapi.runtime.ApiCallback
7
- import vn.momo.maxapi.runtime.ApiRequestHandle
8
-
9
- internal class ToolkitRequests {
10
- private var active = true
11
- private val handles = mutableSetOf<ApiRequestHandle>()
12
-
13
- fun <T> launch(request: (ApiCallback<T>) -> ApiRequestHandle, onResult: ApiCallback<T>) {
14
- if (!active) return
15
- var completed = false
16
- var handle: ApiRequestHandle? = null
17
- val created = request { result ->
18
- completed = true
19
- handle?.let(handles::remove)
20
- if (active) onResult(result)
21
- }
22
- handle = created
23
- if (!active) created.cancel() else if (!completed) handles.add(created)
24
- }
25
-
26
- // AI-GENERATED START: retain subscriptions across nonterminal sheet events
27
- fun <T> observe(request: (ApiCallback<T>) -> ApiRequestHandle, onResult: ApiCallback<T>) {
28
- if (!active) return
29
- val handle = request { result -> if (active) onResult(result) }
30
- if (active) handles.add(handle) else handle.cancel()
31
- }
32
- // AI-GENERATED END: retain subscriptions across nonterminal sheet events
33
-
34
- fun close() {
35
- active = false
36
- val pending = handles.toList()
37
- handles.clear()
38
- pending.forEach { it.cancel() }
39
- }
40
- }
41
- // AI-GENERATED END: cancel only toolkit requests owned by this composition
@@ -1,44 +0,0 @@
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
@@ -1,62 +0,0 @@
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
@@ -1,58 +0,0 @@
1
- import SwiftUI
2
-
3
- /// App-wide font-scale inputs for the SwiftUI kit, and the single place they publish from.
4
- /// The host writes `update(...)` at startup (from the cache-backed `FontScaleProvider`) and again
5
- /// whenever the in-app font-size preference changes; the OS Dynamic Type factor is tracked here.
6
- /// Mirrors Compose's `KitFontScale` + `ProvideOsFontScale` pair, including its live behaviour —
7
- /// views re-render on change as long as the subtree got `.momoFontScale()` (`NavigationContainer`
8
- /// applies it). When `useOSScaleRate` is false the kit applies `userScaleRate` instead of the OS factor.
9
- public final class FontScaleStore: ObservableObject {
10
- public static let shared = FontScaleStore()
11
-
12
- @Published public private(set) var userScaleRate: CGFloat = 1
13
- @Published public private(set) var useOSScaleRate: Bool = true
14
- @Published public private(set) var osFontScale: CGFloat = FontScaleStore.currentOsFontScale()
15
-
16
- private init() {
17
- NotificationCenter.default.addObserver(
18
- self,
19
- selector: #selector(contentSizeCategoryDidChange),
20
- name: UIContentSizeCategory.didChangeNotification,
21
- object: nil
22
- )
23
- }
24
-
25
- public var snapshot: FontScale {
26
- FontScale(
27
- userScaleRate: userScaleRate,
28
- useOSScaleRate: useOSScaleRate,
29
- osFontScale: osFontScale
30
- )
31
- }
32
-
33
- public func update(userScaleRate: CGFloat, useOSScaleRate: Bool) {
34
- onMain {
35
- // Re-assigning an unchanged value would still publish and invalidate every kit subtree.
36
- if self.userScaleRate != userScaleRate { self.userScaleRate = userScaleRate }
37
- if self.useOSScaleRate != useOSScaleRate { self.useOSScaleRate = useOSScaleRate }
38
- }
39
- }
40
-
41
- @objc private func contentSizeCategoryDidChange() {
42
- let next = Self.currentOsFontScale()
43
- guard next != osFontScale else { return }
44
- osFontScale = next
45
- }
46
-
47
- /// Same factor Compose's iOS `ProvideOsFontScale` derives from
48
- /// `UIFont.preferredFont(forTextStyle: .body).pointSize / 17`, so both iOS surfaces scale alike.
49
- static func currentOsFontScale() -> CGFloat {
50
- let base = UIFont.systemFont(ofSize: UIFont.labelFontSize)
51
- return UIFontMetrics.default.scaledFont(for: base).pointSize / base.pointSize
52
- }
53
-
54
- /// Synchronous when already on main — an async hop would defer the change by a frame.
55
- private func onMain(_ work: @escaping () -> Void) {
56
- if Thread.isMainThread { work() } else { DispatchQueue.main.async(execute: work) }
57
- }
58
- }
@@ -1,17 +0,0 @@
1
- import Foundation
2
-
3
- /// Design-system rollout flag for the SwiftUI kit, mirroring Compose's `KitDesignSystem`.
4
- /// The kit is sandboxed and can't read the host config, so the host writes `update(_:)` once at
5
- /// startup from `DesignSystemConfig`. Startup-only and non-reactive, like `FontScaleStore` was
6
- /// before it gained live updates: there is no SwiftUI navigation container to re-render from.
7
- public final class KitDesignSystem {
8
- public static let shared = KitDesignSystem()
9
-
10
- public private(set) var isWhiteList: Bool = false
11
-
12
- private init() {}
13
-
14
- public func update(isWhiteList: Bool) {
15
- self.isWhiteList = isWhiteList
16
- }
17
- }