@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
@@ -9,9 +9,15 @@ import androidx.compose.runtime.setValue
9
9
  import androidx.compose.ui.uikit.LocalUIViewController
10
10
  import androidx.compose.ui.unit.dp
11
11
  import kotlinx.cinterop.BetaInteropApi
12
+ import kotlinx.cinterop.CFunction
13
+ import kotlinx.cinterop.COpaquePointer
12
14
  import kotlinx.cinterop.ExperimentalForeignApi
15
+ import kotlinx.cinterop.interpretCPointer
13
16
  import kotlinx.cinterop.interpretObjCPointer
17
+ import kotlinx.cinterop.interpretObjCPointerOrNull
18
+ import kotlinx.cinterop.invoke
14
19
  import kotlinx.cinterop.objcPtr
20
+ import kotlinx.cinterop.reinterpret
15
21
  import kotlinx.cinterop.readValue
16
22
  import kotlinx.cinterop.useContents
17
23
  import platform.CoreGraphics.CGRectZero
@@ -25,18 +31,55 @@ import platform.UIKit.UIViewAutoresizingFlexibleHeight
25
31
  import platform.UIKit.UIViewAutoresizingFlexibleWidth
26
32
  import platform.darwin.NSObject
27
33
  import platform.Foundation.NSClassFromString
34
+ import platform.posix.RTLD_DEFAULT
35
+ import platform.posix.dlsym
28
36
 
29
37
  // The API is newer than the SDK Kotlin/Native binds, so it is reached through the runtime.
30
38
  @OptIn(ExperimentalForeignApi::class)
31
39
  private val regionsOfKind = NSSelectorFromString("reservedRegionsOfKind:")
32
40
 
41
+ @OptIn(ExperimentalForeignApi::class)
42
+ private val regionsOfKindOptions = NSSelectorFromString("reservedRegionsOfKind:options:")
43
+
44
+ // a hinge never goes away, so a positive answer is kept for every later container
45
+ private var isKnownFoldable = false
46
+
33
47
  @OptIn(ExperimentalForeignApi::class, BetaInteropApi::class)
34
- private fun UIView.occlusionRegions(target: UIView): List<ReservedRegion> {
35
- if (window == null || !respondsToSelector(regionsOfKind)) return emptyList()
48
+ private fun regionKind(name: String): Any? {
36
49
  // a class object fails `as? NSObjectProtocol` (K/N checks it as an instance), so it is reinterpreted
37
50
  val kindClass = NSClassFromString("UIViewReservedRegionKind")
38
- ?.let { interpretObjCPointer<NSObject>(it.objcPtr()) } ?: return emptyList()
39
- val kind = kindClass.performSelector(NSSelectorFromString("occlusionRegionKind")) ?: return emptyList()
51
+ ?.let { interpretObjCPointer<NSObject>(it.objcPtr()) } ?: return null
52
+ return kindClass.performSelector(NSSelectorFromString(name))
53
+ }
54
+
55
+ // performSelector cannot pass the NSUInteger options, so objc_msgSend is called with the method's own signature.
56
+ @OptIn(ExperimentalForeignApi::class)
57
+ private val msgSendRegionsOfKindOptions = dlsym(RTLD_DEFAULT, "objc_msgSend")
58
+ ?.reinterpret<CFunction<(COpaquePointer?, COpaquePointer?, COpaquePointer?, ULong) -> COpaquePointer?>>()
59
+
60
+ // Apple's foldable check: only a device with a hinge reports a `.division` region, inactive while
61
+ // flat (UIViewReservedRegionQueryOptionsIncludeInactive) but still there. Screen size cannot tell it
62
+ // apart from a large iPhone in landscape or a narrowed window.
63
+ @OptIn(ExperimentalForeignApi::class)
64
+ private fun UIView.hasDivisionRegion(): Boolean {
65
+ if (window == null || !respondsToSelector(regionsOfKindOptions)) return false
66
+ val msgSend = msgSendRegionsOfKindOptions ?: return false
67
+ val kind = regionKind("divisionRegionKind") as? NSObject ?: return false
68
+ val result = msgSend(
69
+ interpretCPointer(objcPtr()),
70
+ regionsOfKindOptions,
71
+ interpretCPointer(kind.objcPtr()),
72
+ 1uL,
73
+ )
74
+ val regions = interpretObjCPointerOrNull<NSArray>(result?.rawValue ?: return false)
75
+ return (regions?.count ?: 0uL) > 0uL
76
+ }
77
+
78
+ // Active regions only: a division region is active while the device is half folded.
79
+ @OptIn(ExperimentalForeignApi::class)
80
+ private fun UIView.activeRegions(kindName: String, target: UIView): List<ReservedRegion> {
81
+ if (window == null || !respondsToSelector(regionsOfKind)) return emptyList()
82
+ val kind = regionKind(kindName) ?: return emptyList()
40
83
  val regions = when (val result = performSelector(regionsOfKind, withObject = kind)) {
41
84
  is List<*> -> result
42
85
  is NSArray -> List(result.count.toInt()) { result.objectAtIndex(it.toULong()) }
@@ -54,9 +97,9 @@ private fun UIView.occlusionRegions(target: UIView): List<ReservedRegion> {
54
97
  // when they change, so nothing polls.
55
98
  @OptIn(ExperimentalForeignApi::class)
56
99
  private class ReservedRegionsProbe(
57
- private val onChange: (List<ReservedRegion>) -> Unit,
100
+ private val onChange: (ReservedRegions) -> Unit,
58
101
  ) : UIView(frame = CGRectZero.readValue()) {
59
- private var last: List<ReservedRegion>? = null
102
+ private var last: ReservedRegions? = null
60
103
 
61
104
  init {
62
105
  userInteractionEnabled = false
@@ -65,7 +108,14 @@ private class ReservedRegionsProbe(
65
108
 
66
109
  override fun layoutSubviews() {
67
110
  super.layoutSubviews()
68
- val regions = superview?.let { occlusionRegions(it) } ?: emptyList()
111
+ // re-read until found: the window may not report the hinge on the first pass
112
+ if (!isKnownFoldable) isKnownFoldable = hasDivisionRegion()
113
+ val host = superview
114
+ val regions = ReservedRegions(
115
+ occlusion = host?.let { activeRegions("occlusionRegionKind", it) } ?: emptyList(),
116
+ isFoldable = isKnownFoldable,
117
+ division = host?.takeIf { isKnownFoldable }?.let { activeRegions("divisionRegionKind", it).firstOrNull() },
118
+ )
69
119
  if (regions != last) {
70
120
  last = regions
71
121
  onChange(regions)
@@ -80,10 +130,10 @@ private class ReservedRegionsProbe(
80
130
 
81
131
  @OptIn(ExperimentalForeignApi::class)
82
132
  @Composable
83
- internal actual fun rememberReservedRegions(): List<ReservedRegion> {
84
- if (!isPhoneIdiom()) return emptyList()
133
+ internal actual fun rememberReservedRegions(): ReservedRegions {
134
+ if (!isPhoneIdiom()) return ReservedRegions()
85
135
  val host = LocalUIViewController.current.view
86
- var regions by remember { mutableStateOf(emptyList<ReservedRegion>()) }
136
+ var regions by remember { mutableStateOf(ReservedRegions(isFoldable = isKnownFoldable)) }
87
137
  DisposableEffect(host) {
88
138
  val probe = ReservedRegionsProbe { regions = it }
89
139
  probe.setFrame(host.bounds)
@@ -1,7 +1,5 @@
1
1
  [versions]
2
- # AI-GENERATED START: align Kits and its samples with the approved SDK 36 toolchain
3
- android-compileSdk = "36"
4
- # AI-GENERATED END: align Kits and its samples with the approved SDK 36 toolchain
2
+ android-compileSdk = "37"
5
3
  android-minSdk = "24"
6
4
  android-targetSdk = "36"
7
5
  ktor-version = "3.0.0-rc-1"
@@ -11,9 +9,7 @@ kSerialize = "1.7.1"
11
9
  compose = "1.10.3"
12
10
  navigation-multiplatform = "2.9.2"
13
11
  coil3-multiplatform = "3.0.0-alpha10"
14
- # AI-GENERATED START: align the Android toolchain with the integrating app
15
- androidGradlePlugin = "9.2.1"
16
- # AI-GENERATED END: align the Android toolchain with the integrating app
12
+ androidGradlePlugin = "8.13.2"
17
13
  r8 = "8.9.35"
18
14
  kotlinx-datetime = "0.7.1"
19
15
  airbnb-lottie = "5.2.0"
@@ -21,9 +17,10 @@ compottie = "2.1.0"
21
17
  androidx-activity = "1.9.1"
22
18
  androidx-appcompat = "1.7.0"
23
19
  material = "1.10.0"
20
+ maxapi = "0.1.1"
24
21
  vanniktechMavenPublish = "0.34.0"
25
22
  kits = "0.167.1-duo.1"
26
- nativemaxapi = "0.3.9"
23
+ nativemaxapi = "0.0.6"
27
24
  gif-image = "0.1.2"
28
25
 
29
26
  [libraries]
@@ -70,7 +67,3 @@ compose = { id = "org.jetbrains.compose", version.ref = "compose" }
70
67
  android-library = { id = "com.android.library", version.ref = "androidGradlePlugin" }
71
68
  android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" }
72
69
  vanniktech-mavenPublish = { id = "com.vanniktech.maven.publish", version.ref = "vanniktechMavenPublish" }
73
-
74
- # AI-GENERATED START: use the AGP Android target for Kotlin Multiplatform libraries
75
- android-kotlin-multiplatform-library = { id = "com.android.kotlin.multiplatform.library", version.ref = "androidGradlePlugin" }
76
- # AI-GENERATED END: use the AGP Android target for Kotlin Multiplatform libraries
@@ -1,9 +1,7 @@
1
1
  #Thu Jul 31 17:05:40 ICT 2025
2
2
  distributionBase=GRADLE_USER_HOME
3
3
  distributionPath=wrapper/dists
4
- # AI-GENERATED START: align the Gradle wrapper with the integrating app
5
- distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.0-bin.zip
6
- # AI-GENERATED END: align the Gradle wrapper with the integrating app
4
+ distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.1-bin.zip
7
5
  networkTimeout=10000
8
6
  validateDistributionUrl=true
9
7
  zipStoreBase=GRADLE_USER_HOME
package/gradle.properties CHANGED
@@ -18,9 +18,9 @@ kotlin.apple.xcodeCompatibility.nowarn=true
18
18
  name="ComposeKits"
19
19
  group=vn.momo.kits
20
20
  artifact.id=kits
21
- version=0.300.4
21
+ version=0.168.1-beta.24
22
22
 
23
23
  repo=GitLab
24
24
  url=https://gitlab.mservice.com.vn/api/v4/projects/5400/packages/maven
25
- gitlab.user=
26
- gitlab.password=
25
+ gitlab.user=upload_packages
26
+ gitlab.password=gldt-CtTSGmzz57sUL9cnjdaQ
@@ -17,8 +17,8 @@ public class MiniAppContext {
17
17
  public var toolkitConfig: [String: Any] = [:]
18
18
  public var providerId: String = "momo"
19
19
  public var permissions: [[String: Any]] = []
20
- // Per-mini-app font-scale override; nil falls back to FontScaleStore. Mirrors Compose's
21
- // MiniAppContext.userScaleRate / useOSScaleRate, which win per field over KitFontScale.
20
+ // Per-mini-app font-scale override; nil falls back to DesignSystemKits. Mirrors Compose's
21
+ // MiniAppContext.userScaleRate / useOSScaleRate, which win per field over DesignSystemKits.
22
22
  public var userScaleRate: CGFloat? = nil
23
23
  public var useOSScaleRate: Bool? = nil
24
24
 
@@ -37,10 +37,11 @@ public class MiniAppContext {
37
37
  }
38
38
  }
39
39
 
40
- public class KitConfig {
41
- public var trustBanner: TrustBannerData? = nil
42
- public var headerBar: String? = nil
43
- public var headerGradient: String? = nil
40
+ // Value type so DesignSystemKitsConfigs can dedupe host pushes; mirrors Compose's DesignSystemConfig.
41
+ public struct KitConfig: Equatable {
42
+ public var trustBanner: TrustBannerData?
43
+ public var headerBar: String?
44
+ public var headerGradient: String?
44
45
 
45
46
  public init(trustBanner: TrustBannerData? = nil, headerBar: String? = nil, headerGradient: String? = nil) {
46
47
  self.trustBanner = trustBanner
@@ -0,0 +1,163 @@
1
+ // File: ios/Application/DesignSystemKits.swift
2
+ // Created At: 2026-10-02 14:17:29 +07:00
3
+ // Created By: AI
4
+ // AI Agent: Claude Code
5
+ // Model: claude-opus-5-5
6
+
7
+ // AI-GENERATED START: app-wide design-system holder mirroring Compose's DesignSystemKits
8
+ import SwiftUI
9
+
10
+ /// Host-owned design-system inputs; mirrors Compose's `DesignSystemKitsConfigs` field for field.
11
+ public struct DesignSystemKitsConfigs: Equatable {
12
+ public var userScaleRate: CGFloat
13
+ public var useOSScaleRate: Bool
14
+ public var isWhiteList: Bool
15
+ public var designSystemConfig: KitConfig?
16
+
17
+ public init(
18
+ userScaleRate: CGFloat = 1,
19
+ useOSScaleRate: Bool = true,
20
+ isWhiteList: Bool = false,
21
+ designSystemConfig: KitConfig? = nil
22
+ ) {
23
+ self.userScaleRate = userScaleRate
24
+ self.useOSScaleRate = useOSScaleRate
25
+ self.isWhiteList = isWhiteList
26
+ self.designSystemConfig = designSystemConfig
27
+ }
28
+ }
29
+
30
+ /// App-wide holder for the SwiftUI kit, mirroring Compose's `DesignSystemKits`. The kit is sandboxed from the
31
+ /// host, so the host pushes `setConfigs(_:)` at startup and on every change; the OS Dynamic Type factor is
32
+ /// tracked here. Views re-render on change as long as the subtree got `.momoFontScale()` (`NavigationContainer`
33
+ /// applies it). Swift reserves `init`, so there is no `init(source:)` twin: the host observes and pushes.
34
+ public final class DesignSystemKits: ObservableObject {
35
+ public static let shared = DesignSystemKits()
36
+
37
+ @Published private var configs = DesignSystemKitsConfigs()
38
+ @Published public private(set) var osFontScale: CGFloat = DesignSystemKits.currentOsFontScale()
39
+ // AI-GENERATED START: republish the font scale when the window scene is resized (iPhone Duo fold/unfold)
40
+ @Published public private(set) var windowShortSide: CGFloat = DesignSystemKits.currentWindowShortSide()
41
+ private var geometryObservations: [ObjectIdentifier: NSKeyValueObservation] = [:]
42
+ // AI-GENERATED END: republish the font scale when the window scene is resized (iPhone Duo fold/unfold)
43
+
44
+ private init() {
45
+ NotificationCenter.default.addObserver(
46
+ self,
47
+ selector: #selector(contentSizeCategoryDidChange),
48
+ name: UIContentSizeCategory.didChangeNotification,
49
+ object: nil
50
+ )
51
+ // AI-GENERATED START: republish the font scale when the window scene is resized (iPhone Duo fold/unfold)
52
+ NotificationCenter.default.addObserver(
53
+ self,
54
+ selector: #selector(sceneDidActivate(_:)),
55
+ name: UIScene.didActivateNotification,
56
+ object: nil
57
+ )
58
+ onMain {
59
+ UIApplication.shared.connectedScenes
60
+ .compactMap { $0 as? UIWindowScene }
61
+ .forEach(self.observeGeometry(of:))
62
+ }
63
+ // AI-GENERATED END: republish the font scale when the window scene is resized (iPhone Duo fold/unfold)
64
+ }
65
+
66
+ public func setConfigs(_ configs: DesignSystemKitsConfigs) {
67
+ onMain {
68
+ // Re-assigning an unchanged value would still publish and invalidate every kit subtree.
69
+ guard self.configs != configs else { return }
70
+ self.configs = configs
71
+ }
72
+ }
73
+
74
+ public func getConfigs() -> DesignSystemKitsConfigs {
75
+ configs
76
+ }
77
+
78
+ public var fontScale: FontScale {
79
+ FontScale(
80
+ userScaleRate: configs.userScaleRate,
81
+ useOSScaleRate: configs.useOSScaleRate,
82
+ osFontScale: osFontScale,
83
+ // AI-GENERATED START: republish the font scale when the window scene is resized (iPhone Duo fold/unfold)
84
+ windowShortSide: windowShortSide
85
+ // AI-GENERATED END: republish the font scale when the window scene is resized (iPhone Duo fold/unfold)
86
+ )
87
+ }
88
+
89
+ @objc private func contentSizeCategoryDidChange() {
90
+ let next = Self.currentOsFontScale()
91
+ guard next != osFontScale else { return }
92
+ osFontScale = next
93
+ }
94
+
95
+ // AI-GENERATED START: republish the font scale when the window scene is resized (iPhone Duo fold/unfold)
96
+ @objc private func sceneDidActivate(_ notification: Notification) {
97
+ guard let scene = notification.object as? UIWindowScene else { return }
98
+ observeGeometry(of: scene)
99
+ refreshWindowShortSide()
100
+ }
101
+
102
+ private func observeGeometry(of scene: UIWindowScene) {
103
+ guard #available(iOS 16.0, *) else { return }
104
+ let key = ObjectIdentifier(scene)
105
+ guard geometryObservations[key] == nil else { return }
106
+ geometryObservations[key] = scene.observe(\.effectiveGeometry, options: [.new]) { [weak self] _, _ in
107
+ // The window is resized after the scene geometry, so read it on the next turn.
108
+ DispatchQueue.main.async { self?.refreshWindowShortSide() }
109
+ }
110
+ }
111
+
112
+ private func refreshWindowShortSide() {
113
+ let next = Self.currentWindowShortSide()
114
+ guard next > 0, next != windowShortSide else { return }
115
+ windowShortSide = next
116
+ }
117
+
118
+ /// UIScreen.main stays on one display on iPhone Duo, so measure the foreground window instead.
119
+ static func currentWindowShortSide() -> CGFloat {
120
+ guard Thread.isMainThread else {
121
+ return min(UIScreen.main.bounds.width, UIScreen.main.bounds.height)
122
+ }
123
+ let scenes = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }
124
+ let scene = scenes.first { $0.activationState == .foregroundActive } ?? scenes.first
125
+ let window = scene?.windows.first { $0.isKeyWindow } ?? scene?.windows.first
126
+ let size: CGSize
127
+ if let window, window.bounds.width > 0 {
128
+ size = window.bounds.size
129
+ } else if let scene {
130
+ size = scene.coordinateSpace.bounds.size
131
+ } else {
132
+ size = UIScreen.main.bounds.size
133
+ }
134
+ return min(size.width, size.height)
135
+ }
136
+ // AI-GENERATED END: republish the font scale when the window scene is resized (iPhone Duo fold/unfold)
137
+
138
+ /// Same factor Compose's iOS `ProvideOsFontScale` derives from
139
+ /// `UIFont.preferredFont(forTextStyle: .body).pointSize / 17`, so both iOS surfaces scale alike.
140
+ static func currentOsFontScale() -> CGFloat {
141
+ let base = UIFont.systemFont(ofSize: UIFont.labelFontSize)
142
+ return UIFontMetrics.default.scaledFont(for: base).pointSize / base.pointSize
143
+ }
144
+
145
+ /// Synchronous when already on main — an async hop would defer the change by a frame.
146
+ private func onMain(_ work: @escaping () -> Void) {
147
+ if Thread.isMainThread { work() } else { DispatchQueue.main.async(execute: work) }
148
+ }
149
+ }
150
+
151
+ private struct DesignSystemKitsConfigsKey: EnvironmentKey {
152
+ /// Computed, never stored: an un-injected subtree still reads the live holder, just not reactively.
153
+ static var defaultValue: DesignSystemKitsConfigs { DesignSystemKits.shared.getConfigs() }
154
+ }
155
+
156
+ public extension EnvironmentValues {
157
+ /// Injected by `.momoFontScale()`; never set it directly (same trap as `\.momoFontScale`).
158
+ var designSystemKitsConfigs: DesignSystemKitsConfigs {
159
+ get { self[DesignSystemKitsConfigsKey.self] }
160
+ set { self[DesignSystemKitsConfigsKey.self] = newValue }
161
+ }
162
+ }
163
+ // AI-GENERATED END: app-wide design-system holder mirroring Compose's DesignSystemKits
@@ -0,0 +1,68 @@
1
+ // File: ios/Application/DesignSystemKitsPayload.swift
2
+ // Created At: 2026-10-02 15:40:00 +07:00
3
+ // Created By: AI
4
+ // AI Agent: Claude Code
5
+ // Model: claude-opus-5-5
6
+
7
+ // AI-GENERATED START: JSON entry point for hosts that can't share Swift types with the kit
8
+ import Foundation
9
+
10
+ public extension DesignSystemKits {
11
+ /// Applies configs pushed as JSON by a host that can't share Swift types with the kit (e.g. the KMP bridge).
12
+ /// Invalid JSON is ignored and the current configs are kept.
13
+ func setConfigs(json: String) {
14
+ guard let data = json.data(using: .utf8),
15
+ let payload = try? JSONDecoder().decode(DesignSystemKitsPayload.self, from: data) else { return }
16
+ setConfigs(payload.configs)
17
+ }
18
+ }
19
+
20
+ // Wire format; field names match the host's serializer (momo-app HostDesignSystemKits / DesignSystemData.kt).
21
+ private struct DesignSystemKitsPayload: Decodable {
22
+ let userScaleRate: CGFloat
23
+ let useOSScaleRate: Bool
24
+ let isWhiteList: Bool
25
+ let designSystemConfig: KitConfigPayload?
26
+
27
+ var configs: DesignSystemKitsConfigs {
28
+ DesignSystemKitsConfigs(
29
+ userScaleRate: userScaleRate,
30
+ useOSScaleRate: useOSScaleRate,
31
+ isWhiteList: isWhiteList,
32
+ designSystemConfig: designSystemConfig?.kitConfig
33
+ )
34
+ }
35
+ }
36
+
37
+ private struct KitConfigPayload: Decodable {
38
+ let trustBanner: TrustBannerPayload?
39
+ let headerBar: String?
40
+ let headerGradient: String?
41
+
42
+ var kitConfig: KitConfig {
43
+ KitConfig(trustBanner: trustBanner?.trustBannerData, headerBar: headerBar, headerGradient: headerGradient)
44
+ }
45
+ }
46
+
47
+ private struct TrustBannerPayload: Decodable {
48
+ let content: [String: String]
49
+ let subContent: [String: String]
50
+ let pciImage: String?
51
+ let sslImage: String?
52
+ let urlConfig: String?
53
+ let icons: [String]?
54
+ let momoImage: String?
55
+
56
+ var trustBannerData: TrustBannerData {
57
+ TrustBannerData(
58
+ content: content,
59
+ subContent: subContent,
60
+ pciImage: pciImage,
61
+ momoImage: momoImage,
62
+ sslImage: sslImage,
63
+ icons: icons,
64
+ urlConfig: urlConfig ?? ""
65
+ )
66
+ }
67
+ }
68
+ // AI-GENERATED END: JSON entry point for hosts that can't share Swift types with the kit
@@ -203,7 +203,9 @@ public struct BadgeRibbon: View {
203
203
  /// rotation) — the label gets the same scale applied a second time so it stays right-reading
204
204
  /// while only the ribbon shape flips.
205
205
  public struct RoundedBadgeRibbon: View {
206
+ @Environment(\.appTheme) private var theme
206
207
  @Environment(\.momoFontScale) private var fontScale
208
+ @Environment(\.designSystemKitsConfigs) private var designSystemKitsConfigs
207
209
  let text: String
208
210
  let position: RibbonPosition
209
211
 
@@ -223,7 +225,12 @@ public struct RoundedBadgeRibbon: View {
223
225
 
224
226
  private var measuredTextSize: CGSize {
225
227
  let fontSize = fontScale(TypographyStyle.labelXsMedium.fontSize)
226
- let font = UIFont.systemFont(ofSize: fontSize, weight: .medium)
228
+ let font = momoUIFont(
229
+ size: fontSize,
230
+ weight: .medium,
231
+ family: theme.font,
232
+ isWhiteList: designSystemKitsConfigs.isWhiteList
233
+ )
227
234
  return text.size(withAttributes: [.font: font])
228
235
  }
229
236
 
@@ -4,16 +4,14 @@ import Foundation
4
4
  private final class MoMoUIKitsBundleToken {}
5
5
 
6
6
  enum MoMoUIKitsResources {
7
+
7
8
  static let bundle: Bundle = {
8
9
  let bundleName = "MoMoUIKitsResources"
9
10
  let tokenBundle = Bundle(for: MoMoUIKitsBundleToken.self)
10
- let frameworkBundle = Bundle(identifier: "org.cocoapods.MoMoUIKits")
11
11
  let candidates = [
12
12
  Bundle.main.resourceURL,
13
13
  tokenBundle.resourceURL,
14
- tokenBundle.bundleURL,
15
- frameworkBundle?.resourceURL,
16
- frameworkBundle?.bundleURL
14
+ tokenBundle.bundleURL
17
15
  ]
18
16
 
19
17
  for candidate in candidates {
@@ -153,7 +153,7 @@ public struct Input: View {
153
153
  handleFocusChange(focused)
154
154
  })
155
155
  .keyboardType(keyboardType)
156
- .font(fontScale.font(size: 14, weight: fontWeight == .bold ? .bold : .regular))
156
+ .kitFont(fontWeight == .bold ? .actionSBold : .bodyDefaultRegular)
157
157
  .ignoreBoldTextSetting()
158
158
  .foregroundColor(getTextColor())
159
159
  .disabled(disabled || readOnly)
@@ -252,7 +252,9 @@ public struct Input: View {
252
252
  }
253
253
  .padding(.horizontal, Spacing.S)
254
254
  .background(theme.colors.background.surface)
255
- .alignmentGuide(.top) { $0[VerticalAlignment.center] }
255
+ // A zero-height frame on the top edge centers the label on the border, re-laid out with font scale.
256
+ .fixedSize(horizontal: false, vertical: true)
257
+ .frame(height: 0)
256
258
  .offset(x: Spacing.S)
257
259
  }
258
260
  }
@@ -345,7 +347,12 @@ private struct SecureInputField: UIViewRepresentable {
345
347
  textField.spellCheckingType = .no
346
348
  textField.delegate = context.coordinator
347
349
  textField.keyboardType = keyboardType
348
- textField.font = UIFont.systemFont(ofSize: fontSize, weight: fontWeight)
350
+ textField.font = momoUIFont(
351
+ size: fontSize,
352
+ weight: fontWeight,
353
+ family: context.environment.appTheme.font,
354
+ isWhiteList: context.environment.designSystemKitsConfigs.isWhiteList
355
+ )
349
356
  textField.textColor = textColor
350
357
  textField.isEnabled = !isDisabled
351
358
  textField.setContentHuggingPriority(.defaultLow, for: .horizontal)
@@ -370,7 +377,12 @@ private struct SecureInputField: UIViewRepresentable {
370
377
  if textField.text != text {
371
378
  textField.text = text
372
379
  }
373
- let font = UIFont.systemFont(ofSize: fontSize, weight: fontWeight)
380
+ let font = momoUIFont(
381
+ size: fontSize,
382
+ weight: fontWeight,
383
+ family: context.environment.appTheme.font,
384
+ isWhiteList: context.environment.designSystemKitsConfigs.isWhiteList
385
+ )
374
386
  if textField.font != font {
375
387
  textField.font = font
376
388
  }
@@ -104,9 +104,7 @@ public struct InputPhoneNumber: View {
104
104
  handleFocusChange(focused)
105
105
  })
106
106
  .keyboardType(.numberPad)
107
- .font(size == .small
108
- ? fontScale.font(size: 14, weight: .semibold)
109
- : fontScale.font(size: 18, weight: .bold))
107
+ .kitFont(size == .small ? .headerSSemibold : .headerMBold)
110
108
  .ignoreBoldTextSetting()
111
109
  .foregroundColor(theme.colors.text.default)
112
110
  .applyCursorColor(theme.colors.primary)
@@ -120,7 +120,6 @@ public struct InputSearchProps {
120
120
 
121
121
  public struct InputSearch: View {
122
122
  @Environment(\.appTheme) private var theme
123
- @Environment(\.momoFontScale) private var fontScale
124
123
  @Binding var text: String
125
124
  var buttonText: String = ""
126
125
  var showButtonText: Bool = false
@@ -263,7 +262,7 @@ public struct InputSearch: View {
263
262
  }, onCommit: onSubmit)
264
263
  .disabled(disabled)
265
264
  .foregroundColor(disabled ? theme.colors.text.disable : theme.colors.text.default)
266
- .font(.system(size: fontScale(14), weight: fontWeight))
265
+ .kitFont(size: 14, weight: fontWeight)
267
266
  .ignoreBoldTextSetting()
268
267
  .keyboardType(keyboardType)
269
268
  .applyCursorColor(theme.colors.primary)
@@ -41,9 +41,11 @@ struct UITextViewWrapper: UIViewRepresentable {
41
41
  uiView.tintColor = UIColor(cursorColor)
42
42
  // Read through `context.environment` rather than the global `scaleSize`: that is what makes
43
43
  // SwiftUI re-run updateUIView when the font scale changes.
44
- uiView.font = UIFont.systemFont(
45
- ofSize: context.environment.momoFontScale(16),
46
- weight: fontWeight == .bold ? .bold : .regular
44
+ uiView.font = momoUIFont(
45
+ size: context.environment.momoFontScale(16),
46
+ weight: fontWeight == .bold ? .bold : .regular,
47
+ family: context.environment.appTheme.font,
48
+ isWhiteList: context.environment.designSystemKitsConfigs.isWhiteList
47
49
  )
48
50
  uiView.isEditable = !disabled
49
51
  if uiView.keyboardType != keyboardType {
@@ -277,7 +279,9 @@ public struct InputTextArea: View {
277
279
  }
278
280
  .padding(.horizontal, Spacing.S)
279
281
  .background(theme.colors.background.surface)
280
- .alignmentGuide(.top) { $0[VerticalAlignment.center] }
282
+ // A zero-height frame on the top edge centers the label on the border, re-laid out with font scale.
283
+ .fixedSize(horizontal: false, vertical: true)
284
+ .frame(height: 0)
281
285
  .offset(x: Spacing.S)
282
286
  }
283
287
  }
@@ -356,14 +356,13 @@ private struct MoneyTextField: UIViewRepresentable {
356
356
  return numeric.isEmpty ? "" : formatNumberToMoney(numeric)
357
357
  }
358
358
 
359
- // Theme family as Compose `getFontFamily`: Momo Trust Sans only for whitelisted hosts, else system.
360
359
  private func font(_ context: Context) -> UIFont {
361
- let size = context.environment.momoFontScale(20)
362
- if KitDesignSystem.shared.isWhiteList, fontFamily == "MomoTrustSans",
363
- let font = UIFont(name: fontWeight == .bold ? "MomoTrustSans-Bold" : "MomoTrustSans-Regular", size: size) {
364
- return font
365
- }
366
- return .systemFont(ofSize: size, weight: fontWeight)
360
+ momoUIFont(
361
+ size: context.environment.momoFontScale(20),
362
+ weight: fontWeight,
363
+ family: fontFamily,
364
+ isWhiteList: context.environment.designSystemKitsConfigs.isWhiteList
365
+ )
367
366
  }
368
367
 
369
368
  final class Coordinator: NSObject, UITextFieldDelegate {