@momo-kits/native-kits 0.168.1-beta.4 → 0.168.1-beta.40
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.
- package/CLAUDE.md +15 -10
- package/README.md +2 -10
- package/ios/Application/ApplicationEnvironment.swift +7 -6
- package/ios/Application/DesignSystemKits.swift +163 -0
- package/ios/Application/DesignSystemKitsPayload.swift +68 -0
- package/ios/Badge/BadgeRibbon.swift +8 -1
- package/ios/Extensions/Color++.swift +2 -4
- package/ios/Input/Input.swift +16 -4
- package/ios/Input/InputPhoneNumber.swift +1 -3
- package/ios/Input/InputSearch.swift +1 -2
- package/ios/Input/InputTextArea.swift +8 -4
- package/ios/InputMoney/InputMoney.swift +6 -7
- package/ios/Layout/ModalLayout.swift +152 -0
- package/ios/Layout/ScreenLayout.swift +77 -18
- package/ios/Navigation/BottomSheet.swift +56 -53
- package/ios/Navigation/BottomTab/BottomTab.swift +46 -52
- package/ios/Navigation/BottomTab/BottomTabBar.swift +281 -115
- package/ios/Navigation/BottomTab/CurvedContainer.swift +51 -47
- package/ios/Navigation/BottomTab/DuoBarCompression.swift +2 -3
- package/ios/Navigation/BottomTab/DuoTabBar.swift +64 -172
- package/ios/Navigation/BottomTab/TabBarMetrics.swift +84 -0
- package/ios/Navigation/Component/HeaderBackground.swift +22 -1
- package/ios/Navigation/Component/HeaderRight.swift +1 -1
- package/ios/Navigation/Component/SnackBar.swift +4 -0
- package/ios/Navigation/ModalScreen.swift +20 -5
- package/ios/Navigation/StackScreen.swift +6 -8
- package/ios/Popup/PopupDisplay.swift +6 -4
- package/ios/Popup/PopupInput.swift +6 -4
- package/ios/Popup/PopupLayout.swift +17 -11
- package/ios/Popup/PopupNotify.swift +32 -25
- package/ios/Stepper/Stepper.swift +1 -2
- package/ios/Template/TrustBanner/TrustBanner.swift +4 -2
- package/ios/Typography/FontScale.swift +29 -15
- package/ios/Typography/Text.swift +88 -14
- package/ios/Typography/Typography.swift +2 -2
- package/ios/native-kits.podspec +1 -1
- package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
- package/ios-demo/Resources/tabbar_scan_qr_button.json +1 -0
- package/ios-demo/Resources/tabbar_scan_qr_label.json +1 -0
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +272 -59
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/NavigationDemo.swift +103 -0
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/PopupNotifyDemo.swift +29 -1
- package/package.json +1 -1
- package/publish.sh +2 -33
- package/ios/Typography/FontScaleStore.swift +0 -58
- package/ios/Typography/KitDesignSystem.swift +0 -17
package/CLAUDE.md
CHANGED
|
@@ -7,7 +7,7 @@ Guidance for working in this repo. Keep it accurate — update it when structure
|
|
|
7
7
|
`momo-native-kits` — MoMo's design-system / UI-kit as a **Kotlin Multiplatform + Compose Multiplatform** library, published for Android (AAR/Maven) and iOS (static framework + CocoaPods). It is the Compose port of the React Native `momo-kits`. Consumed by mini-apps embedded in the host MoMo app.
|
|
8
8
|
|
|
9
9
|
- Artifact: `vn.momo.kits:kits` (version in `gradle.properties`). NPM mirror: `@momo-kits/native-kits`.
|
|
10
|
-
- Targets:
|
|
10
|
+
- Targets: `androidTarget` (JVM 17, compile/min/target SDK 36/24/36), `iosArm64`, `iosSimulatorArm64` (framework `baseName = "kits"`, `isStatic = true`).
|
|
11
11
|
- Kotlin 2.3.10, Compose MP 1.10.3.
|
|
12
12
|
|
|
13
13
|
## Modules
|
|
@@ -26,11 +26,11 @@ Guidance for working in this repo. Keep it accurate — update it when structure
|
|
|
26
26
|
|
|
27
27
|
## Build & verify
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
No unit-test suite is configured. Validate changes by compiling the relevant target(s); use the sample app for visual checks.
|
|
30
30
|
|
|
31
31
|
```bash
|
|
32
32
|
./gradlew :compose:compileCommonMainKotlinMetadata # validate commonMain (fast, do this first)
|
|
33
|
-
./gradlew :compose:
|
|
33
|
+
./gradlew :compose:compileDebugKotlinAndroid # Android target
|
|
34
34
|
./gradlew :compose:linkDebugFrameworkIosSimulatorArm64 # iOS framework (slow)
|
|
35
35
|
./gradlew :sample:androidApp:installDebug # run demo on device/emulator
|
|
36
36
|
```
|
|
@@ -48,9 +48,11 @@ Publishing is automated (`publish.sh` + GitLab CI on `[ci build]` / `main`). Do
|
|
|
48
48
|
|
|
49
49
|
- **Entry point:** wrap content in `NavigationContainer(...)` from `navigation/`. It builds the `Navigator`, takes a host-supplied `Localize` (falls back to an empty one), and provides the CompositionLocals below. The legacy `Screen` / `ApplicationContainer` / `ComposeApi` stack has been removed on both sides — don't reintroduce it.
|
|
50
50
|
- **Configuration flows via CompositionLocals**, not params. Public ones: `AppTheme`, `AppStatusBar`, `AppNavigationBar` (`const/Theme.kt`); `ApplicationContext`, `AppConfig`, `AppLanguage`, `LocalLocalize` (`application/`); `LocalNavigator`, `LocalMaxApi` (`navigation/`). Read with `X.current`.
|
|
51
|
-
-
|
|
51
|
+
- **`DesignSystemKits`** (`application/DesignSystemKits.kt`) is the single app-wide holder for the host-owned design-system inputs: font scale (`userScaleRate` / `useOSScaleRate`), whitelist (`isWhiteList`) and the remote `DesignSystemConfig`, bundled as `DesignSystemKitsConfigs`. The host calls `DesignSystemKits.init(source)` once at startup with its `DesignSystemKitsSource` (sync `getConfigs()` seed + `configsFlow`); `init` is idempotent. Without a source, call `setConfigs(...)` directly. Read with `getConfigs()` (snapshot state, recomposes); non-Compose observers use `configsFlow`.
|
|
52
|
+
- **SwiftUI twin:** `ios/Application/DesignSystemKits.swift` mirrors it field for field (`DesignSystemKitsConfigs` with `designSystemConfig: KitConfig?`, `setConfigs` / `getConfigs`), plus the OS Dynamic Type factor (`osFontScale`). There is no `init(source:)` (Swift reserves `init`): the host observes its own bridge and pushes. A host that can't share Swift types (the KMP bridge) calls `DesignSystemKits.shared.setConfigs(json:)` (`ios/Application/DesignSystemKitsPayload.swift`); the JSON field names are a contract with momo-app's serializer (`HostDesignSystemKits.observeConfigsJson`, payload classes in `DesignSystemData.kt`) — change both together. Invalid JSON is ignored. The SwiftUI kit can't link the Kotlin `kits` framework (a second Kotlin/Native runtime would hold a second, never-initialized singleton), so the render-time logic — `FontScale` formula, Dynamic Type observation — is intentionally duplicated in Swift; only values flow across.
|
|
53
|
+
- **Design-system config** (`trustBanner`, `headerBar`, `headerGradient`): `NavigationContainer` provides it as `LocalDesignSystemConfig` (param `designSystemConfig` → parent → `DesignSystemKits`) and applies `headerBar` as the header image when the theme has none.
|
|
52
54
|
- **Platform code** goes through `expect`/`actual` in `platform/` — never reference Android/iOS APIs from `commonMain` directly.
|
|
53
|
-
- **Native bridge:**
|
|
55
|
+
- **Native bridge:** `IMaxApi` (`vn.momo.maxapi`, exposed as `LocalMaxApi`) is the host-app bridge (dismiss, tracking, device info, language).
|
|
54
56
|
- Navigation uses a runtime `DynamicScreenRegistry`; overlays (modal/bottom-sheet/snackbar) go through `Navigator` + `OverplayComponentRegistry`.
|
|
55
57
|
- **iOS swipe-back:** the host owns the only edge-pan recogniser and replays it through `HostBackGestureBridge` (`navigation/HostBackGestureBridge.kt`; the kit framework is never exported, so the host reaches it through its own Koin-provided facade): `checkCanPop` / `canPopInner` / `pop` route the back into the kit stack, `started` / `progressed` / `completed` / `cancelled` seek the NavHost transition, `shouldUseFloatingArrowBack` is set by bottom tabs. `NavigationContainer` attaches itself automatically (`AttachHostBackGesture`, iOS only, detached by identity on dispose) — hosts need no wrapper and no `setNavigator`. `maxApi` is a required parameter of `NavigationContainer` — every container, nested or root, is handed its host bridge explicitly.
|
|
56
58
|
|
|
@@ -69,17 +71,20 @@ Publishing is automated (`publish.sh` + GitLab CI on `[ci build]` / `main`). Do
|
|
|
69
71
|
## Screen layout / iPhone Duo (port of RN `useScreenLayout`, momo-kits !664)
|
|
70
72
|
|
|
71
73
|
- `layout/ScreenLayout.kt`: `getScreenLayout()` returns window size, raw top/bottom + side insets, `contentWidth`, header geometry, the iPhone Duo `sideBar` and `duoTopInset`. `NavigationContainer` computes it once and provides `LocalScreenLayout`; reactive to fold/unfold and rotation (window size + `WindowInsets`). Metrics (`DuoMetrics`, 72pt iPhone header floor, 20pt status-bar threshold) mirror RN `Layout/utils.ts` — change both together.
|
|
72
|
-
- iPhone-only: everything gates on `isPhoneIdiom()` (`platform/`), never on "iOS", so iPad windows keep the regular layout. Two detectors, as in RN: `isIPhoneDuo` (window aspect < 1.6 or asymmetric side insets) drives layout; `isIPhoneDuoDevice` (
|
|
74
|
+
- iPhone-only: everything gates on `isPhoneIdiom()` (`platform/`), never on "iOS", so iPad windows keep the regular layout. Two detectors, as in RN: `isIPhoneDuo` (window aspect < 1.6 or asymmetric side insets) drives layout; `isIPhoneDuoDevice` (Apple's foldable check: a `.division` reserved region, queried with include-inactive; Swift also latches on `UIHingeInteraction`; or asymmetric side insets, since the outer display reports no hinge) drives popups, modal and bottom sheet.
|
|
73
75
|
- Header height is `headerHeight` (not `AppStatusBar + HEADER_HEIGHT`); the bar row is `headerBarHeight` and starts `headerStatusBarHeight` below the window top. When the status bar is off the top edge (iPhone landscape, iPhone Duo) `headerStatusBarHeight` is 0 so the title stays centered — except on the Duo outer display: in portrait the header is 76pt and the row starts at 14pt so the title centers on the camera punchout; in landscape the row centers on the camera when it sits at the top end of the strip (else on the back button) and the header reaches 8pt below the back button.
|
|
74
76
|
- iPhone Duo inner display in portrait (status bar on top): the header row shares the status bar band — `headerHeight` 94pt (2 × the clock digits' y 47), `headerStatusBarHeight` 0 — and `ScreenLayout.statusBarClearance` keeps it between the clock / battery clusters (from reserved regions, else 128pt on the right). Back and toolkit use the 48pt side bar controls laid out horizontally (`ToolkitLayout.SideBarRow`); the collapsed search and a centered title stay clear of the clusters. Port of momo-kits `90af33ba2`.
|
|
75
77
|
- iPhone Duo with a side strip ≥ 60pt: back + toolkit leave the bar for `HeaderSideBar` (`navigation/component/SideBar.kt`, 48pt glass controls); custom header-right stays in the bar. `sideBar.top` is 170pt in portrait, 120pt on the inner display in landscape (height ≥ 600), 24pt on the outer display in landscape, or below the header when the status bar is on top; UIKit's `statusBarFrame` is useless on Duo. Unlike RN the column is clamped above footer (24pt gap) / rail (12pt gap).
|
|
76
78
|
- Reserved regions (iOS 27.1 `reservedRegionsOfKind:`, reached through the ObjC runtime so older SDKs still build): a probe `UIView` (`platform/ReservedRegions.ios.kt` on the Compose root view; `ReservedRegionsProbe` inside SwiftUI `momoScreenLayout()`) re-reads them in `layoutSubviews`, which UIKit re-runs when they change. They push `sideBar.top` below the status cluster as it grows for calls / Live Activities, and `sideBar.bottom` (≥ 24pt) above a camera at the bottom end of the strip.
|
|
77
79
|
- Tab bar on Duo is `bottomtab/DuoTabBar.kt`: a rail in the side strip (`sideBar.bottom` above the window bottom, QR below it) or, without a side bar, a floating bar spanning 6/8 grid columns. Both overlay the content; `duoFloatingTabBarInset` pads tab content, footer and FAB.
|
|
80
|
+
- Duo tab selection motion (`bottomtab/DuoLiquidSelection.kt` / `ios/Navigation/BottomTab/DuoLiquidSelection.swift`, port of RN `useLiquidSelection.ts`, momo-kits !682): press lifts the lens, a drag past 10pt takes over (Compose: the bar's `pointerInput` consumes and so cancels the tab's clickable; SwiftUI: one `DragGesture` over the bar, tabs are not `Button`s), long press calls `BottomTab(onTabLongPress)` and release still selects, Reduce Motion (`platform/ReduceMotion`) falls back to a plain slide. SwiftUI integrates the lens spring on a display link because the stretch and the tabs' active tint read it every frame. Constants mirror RN — change both together.
|
|
78
81
|
- Bar compression (`bottomtab/DuoBarCompression.kt`, HIG "Vertical controls"): when toolbar + rail don't fit in the strip, one is compressed — the toolkit into a `navigation_menu` button, the rail into one button showing the current tab — and tapping it swaps them; `BottomTab(compressionBehavior)` picks which starts compressed. If neither fits beside the other compressed, both rest compressed and a tap opens one for a moment. Side bar columns report their full height (0 when the screen puts nothing there) so the decision follows each screen's toolkit.
|
|
79
82
|
- Glass header: on Duo with a side bar, Default/Extended headers without search and with a `ScrollState` let content scroll under the bar (`usesDuoGlassHeader`); the bar fades in a translucent surface + hairline over 16pt (Compose has no backdrop blur — RN's fallback look), the gradient leaves with the content.
|
|
80
83
|
- Quick return header: glass headers and Animated headers (with a `ScrollState`) on the Duo side bar layout slide out with the content and back in on a reverse scroll; a half-shown header settles in or out once the scroll stops. The side bar is drawn apart from the header, so it stays put.
|
|
81
|
-
- Overlays on
|
|
84
|
+
- Overlays on foldables (`layout/ModalLayout.kt` / `ios/Layout/ModalLayout.swift`, Figma "Modal - Foldable Guideline", constants shared with RN): foldable = `isIPhoneDuoDevice` or a window short side ≥ 600, so phones (landscape too) keep their look. The resolver returns the placement (safe area, so left of the Duo control column; right of an active vertical division when a Duo is half folded — Swift also needs `UIHingeInteraction` `.partiallyOpen`; Android half fold stays flat), popup geometry (width clamp(placement − 2·margin, 280, 450), margin 24 or 12 on the Duo outer display / half fold, max height min(600, placement − 48), radius 24; only the PopupNotify description scrolls) and sheet geometry (width min(placement − 24, 653) ≥ 296, bottom anchored, max height window − top inset − 12, min height 230, radius 24 top). Scrim is black 20% over the whole window on foldables (0.6 on phones). Snackbars keep clear of the strip. On every device (RN parity) popup close and sheet header back / close are `ModalIconButton`: 32pt circle on `background.surface` with a 1pt `border.default` stroke, 20pt `text.default` icon; the popup close sits inside the card 12pt from the top right (`PopupPromotion` keeps its close under the image), the default sheet header is 56 tall, 12 padding, 8 gap.
|
|
85
|
+
- Bottom sheet on Duo: stays in the placement, never on or under the side strip; back / close stay in the header row (no side column). `BottomHeader.Title(onBack)` / `.title(onBack:)` closes the sheet, then runs (RN `leftOptions.onPressIconLeft`).
|
|
82
86
|
- Font scale deliberately uses the short side (`min(w, h)`), unlike RN which reads the window width — landscape must not inflate every font.
|
|
87
|
+
- Font scale measures the **window**, never `UIScreen.main`: on iPhone Duo the main screen stays on one display while the window follows the one in use. Compose iOS `getScreenDimensions()` reads `LocalWindowInfo.containerSize` (recomposes on fold/unfold); SwiftUI `DesignSystemKits` KVO-observes each `UIWindowScene.effectiveGeometry` and republishes `windowShortSide`.
|
|
83
88
|
- `StackScreen` pads content/footer/search/FAB by the side insets and provides an inset-consumed layout to its content; a bottom-tab root stays full width (tab bar + each tab's StackScreen handle insets). Grid columns use `contentWidth`.
|
|
84
89
|
|
|
85
90
|
## i18n / Localize (port of RN `Localize`)
|
|
@@ -104,9 +109,9 @@ The SwiftUI port differs from Compose in one important way: **it follows the hos
|
|
|
104
109
|
|
|
105
110
|
One formula, both platforms: the device-width scale (`width / 375`, capped at `+5pt`) and the OS Dynamic Type scale (capped at `1.5×`) are computed independently and the **larger wins**. When `useOSScaleRate` is false neither applies — the size is just multiplied by `userScaleRate`. Max font scale is fixed at 1.5; the old per-call/per-scope override is deprecated and ignored on both sides.
|
|
106
111
|
|
|
107
|
-
- **Compose** — `const/Typography.kt` (`scaleSize` overloads for `Float`/`Dp`/`TextUnit`/`TextStyle`). The `TextUnit` overload divides by `density.fontScale` so Compose's own `sp` scaling isn't applied twice. Inputs: `LocalContext.current` (`MiniAppContext.userScaleRate` / `useOSScaleRate`, per-field) falling back to
|
|
108
|
-
- **SwiftUI** — `ios/Typography/FontScale.swift`. `FontScale` is an immutable snapshot with `callAsFunction`, so a view reads `@Environment(\.momoFontScale) private var fontScale` and calls `fontScale(16)`. `
|
|
109
|
-
- **Never set `\.momoFontScale` directly** — same trap as `\.localize`. Inject via `.momoFontScale(_:context:)`, which holds
|
|
112
|
+
- **Compose** — `const/Typography.kt` (`scaleSize` overloads for `Float`/`Dp`/`TextUnit`/`TextStyle`). The `TextUnit` overload divides by `density.fontScale` so Compose's own `sp` scaling isn't applied twice. Inputs: `LocalContext.current` (`MiniAppContext.userScaleRate` / `useOSScaleRate`, per-field) falling back to `DesignSystemKits.getConfigs()`. On iOS, `platform/OsFontScale.ios.kt` observes `UIContentSizeCategoryDidChangeNotification` and overrides `LocalDensity` — Compose MP otherwise reads `fontScale` once at `ComposeUIViewController` creation. Wired at `NavigationContainer`.
|
|
113
|
+
- **SwiftUI** — `ios/Typography/FontScale.swift`. `FontScale` is an immutable snapshot with `callAsFunction`, so a view reads `@Environment(\.momoFontScale) private var fontScale` and calls `fontScale(16)`. `DesignSystemKits.shared` is the `ObservableObject` holding the host inputs and the OS factor (it observes `UIContentSizeCategory.didChangeNotification`); the host pushes them with `setConfigs(_:)`.
|
|
114
|
+
- **Never set `\.momoFontScale` directly** — same trap as `\.localize`. Inject via `.momoFontScale(_:context:)`, which holds `DesignSystemKits` as `@ObservedObject`; that is what re-publishes the snapshot. It also injects `\.designSystemKitsConfigs`, which `MomoText` (whitelist font) and `TrustBanner` (fallback after `ApplicationEnvironment.config`) read so a host push re-renders them. `NavigationContainer` does it (passing `MiniAppContext` so the per-mini-app override applies); a bare `UIHostingController` root must too. The environment default reads the live store, so an un-injected subtree still gets correct values — just not live ones.
|
|
110
115
|
- The global `scaleSize(_:)` and `Font.appFont(size:)` remain for call sites that can't read the environment (UIKit bridges, free functions). They are **not** reactive. `Font.header_default_bold` & friends are computed `static var`s for the same reason — as stored `static let`s they froze the scale at first access. `UIViewRepresentable`s should read `context.environment.momoFontScale` instead, and re-apply the font in `updateUIView`, not only in `makeUIView`.
|
|
111
116
|
|
|
112
117
|
## Code conventions
|
package/README.md
CHANGED
|
@@ -53,7 +53,7 @@ ComposeKit là bộ UI Kit đa nền tảng phục vụ Mini App/SDK của MoMo.
|
|
|
53
53
|
---
|
|
54
54
|
|
|
55
55
|
### Yêu cầu môi trường
|
|
56
|
-
- JDK 17+
|
|
56
|
+
- JDK 17+, Gradle 8, Android Studio Hedgehog+ với Android SDK (compileSdk xem `libs.versions.toml`).
|
|
57
57
|
- Kotlin Multiplatform plugin + Compose Multiplatform (JetBrains 1.6.1+).
|
|
58
58
|
- Xcode 15, CocoaPods 1.12+ để build `iosApp` hoặc publish Pod.
|
|
59
59
|
- Truy cập mạng nội bộ GitLab Packages nếu cần publish/consume Maven repo `https://gitlab.mservice.com.vn/api/v4/projects/5400/packages/maven`.
|
|
@@ -174,12 +174,4 @@ fun SuccessState() {
|
|
|
174
174
|
```
|
|
175
175
|
|
|
176
176
|
- `shared/build.gradle.kts` đã bật `coreLibraryDesugaringEnabled` để tương thích `compottie-dot`/`compottie-network` với `minSdk = 24`.
|
|
177
|
-
- Nếu animation dùng asset/font nội bộ, kết hợp `compottie-resources` (`rememberResourcesAssetsManager`, `rememberResourcesFontManager`) để trỏ về `composeResources`.
|
|
178
|
-
### NativeMaxApi 0.3.1
|
|
179
|
-
|
|
180
|
-
Compose dùng typed `vn.momo.maxapi.IMaxApi` do host truyền vào `NavigationContainer`.
|
|
181
|
-
Toolkit dùng overload `showToolkit(ToolkitOptions, callback)` để giữ nhóm tool tùy chỉnh,
|
|
182
|
-
nhãn đa ngôn ngữ, icon, badge và `useSystemTools`. Callback trả `actionKey`; request đang chờ
|
|
183
|
-
được hủy khi composition bị gỡ. Kits không đóng client do host sở hữu.
|
|
184
|
-
|
|
185
|
-
Chạy `./gradlew :compose:testAndroidHostTest` để kiểm tra hủy request và callback đến muộn.
|
|
177
|
+
- Nếu animation dùng asset/font nội bộ, kết hợp `compottie-resources` (`rememberResourcesAssetsManager`, `rememberResourcesFontManager`) để trỏ về `composeResources`.
|
|
@@ -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
|
|
21
|
-
// MiniAppContext.userScaleRate / useOSScaleRate, which win per field over
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
public var
|
|
43
|
-
public var
|
|
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 =
|
|
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 {
|
package/ios/Input/Input.swift
CHANGED
|
@@ -153,7 +153,7 @@ public struct Input: View {
|
|
|
153
153
|
handleFocusChange(focused)
|
|
154
154
|
})
|
|
155
155
|
.keyboardType(keyboardType)
|
|
156
|
-
.
|
|
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
|
-
|
|
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 =
|
|
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 =
|
|
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
|
-
.
|
|
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
|
-
.
|
|
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 =
|
|
45
|
-
|
|
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
|
-
|
|
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
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
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 {
|