@momo-kits/native-kits 0.300.7 → 0.300.8-beta.1

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 (107) hide show
  1. package/CLAUDE.md +12 -8
  2. package/README.md +8 -7
  3. package/ios/Application/ApplicationEnvironment.swift +6 -4
  4. package/ios/Application/DesignSystemKits.swift +59 -13
  5. package/ios/Application/DesignSystemKitsPayload.swift +0 -8
  6. package/ios/Application/LanguageSource.swift +2 -11
  7. package/ios/Application/Localize.swift +8 -35
  8. package/ios/Application/LocalizeModifier.swift +2 -11
  9. package/ios/Application/MaxApi.swift +3 -11
  10. package/ios/Avatar/Avatar.swift +0 -1
  11. package/ios/Badge/Badge.swift +5 -8
  12. package/ios/Badge/BadgeRibbon.swift +2 -5
  13. package/ios/Button/Button.swift +4 -8
  14. package/ios/CalculatorKeyboard/CalculatorKeyboard.swift +5 -7
  15. package/ios/Carousel/Carousel.swift +4 -17
  16. package/ios/Checkbox/Checkbox.swift +0 -2
  17. package/ios/Collapse/Collapse.swift +17 -11
  18. package/ios/Colors+Radius+Spacing/Theme.swift +0 -7
  19. package/ios/DateTimePicker/DateTimePicker.swift +4 -10
  20. package/ios/DateTimePicker/DateTimePickerTypes.swift +1 -3
  21. package/ios/DateTimePicker/DateTimePickerUtils.swift +0 -3
  22. package/ios/DateTimePicker/WheelPicker.swift +2 -4
  23. package/ios/Extensions/ActiveOpacityButtonStyle.swift +2 -3
  24. package/ios/Extensions/Color++.swift +2 -4
  25. package/ios/Extensions/SkeletonUICompat.swift +0 -8
  26. package/ios/Icon/Icon.swift +3 -6
  27. package/ios/IconButton/IconButton.swift +2 -5
  28. package/ios/Input/ErrorView.swift +0 -7
  29. package/ios/Input/Input.swift +9 -20
  30. package/ios/Input/InputPhoneNumber.swift +37 -20
  31. package/ios/Input/InputSearch.swift +23 -12
  32. package/ios/Input/InputTextArea.swift +4 -13
  33. package/ios/InputDropDown/InputDropDown.swift +1 -11
  34. package/ios/InputMoney/InputMoney.swift +9 -28
  35. package/ios/InputOTP/InputOTP.swift +2 -9
  36. package/ios/Layout/HeaderLayout.swift +72 -0
  37. package/ios/Layout/Item.swift +1 -2
  38. package/ios/Layout/ModalLayout.swift +144 -0
  39. package/ios/Layout/ScreenLayout.swift +48 -31
  40. package/ios/Layout/Section.swift +2 -3
  41. package/ios/Loader/Loader.swift +3 -12
  42. package/ios/Lottie/LottieView.swift +0 -11
  43. package/ios/Navigation/BottomSheet.swift +73 -94
  44. package/ios/Navigation/BottomTab/BottomTab.swift +58 -73
  45. package/ios/Navigation/BottomTab/BottomTabBar.swift +286 -121
  46. package/ios/Navigation/BottomTab/CurvedContainer.swift +52 -54
  47. package/ios/Navigation/BottomTab/DuoBarCompression.swift +5 -12
  48. package/ios/Navigation/BottomTab/DuoTabBar.swift +67 -202
  49. package/ios/Navigation/BottomTab/TabBarMetrics.swift +97 -0
  50. package/ios/Navigation/Component/FloatingButton.swift +4 -11
  51. package/ios/Navigation/Component/Header.swift +35 -54
  52. package/ios/Navigation/Component/HeaderBackground.swift +2 -8
  53. package/ios/Navigation/Component/HeaderJourney.swift +4 -8
  54. package/ios/Navigation/Component/HeaderLocation.swift +4 -8
  55. package/ios/Navigation/Component/HeaderRight.swift +20 -22
  56. package/ios/Navigation/Component/HeaderTitle.swift +1 -6
  57. package/ios/Navigation/Component/HeaderUser.swift +4 -10
  58. package/ios/Navigation/Component/SideBar.swift +6 -21
  59. package/ios/Navigation/Component/SnackBar.swift +9 -13
  60. package/ios/Navigation/HostBackGestureBridge.swift +2 -9
  61. package/ios/Navigation/ModalScreen.swift +24 -13
  62. package/ios/Navigation/Navigation.swift +35 -19
  63. package/ios/Navigation/NavigationContainer.swift +4 -15
  64. package/ios/Navigation/Navigator.swift +21 -39
  65. package/ios/Navigation/StackScreen.swift +64 -51
  66. package/ios/Navigation/StackTransition.swift +7 -14
  67. package/ios/Navigation/SwipeBackHaptic.swift +2 -7
  68. package/ios/Navigation/Tracking/ScreenTracker.swift +2 -7
  69. package/ios/Pagination/PaginationDot.swift +0 -9
  70. package/ios/Pagination/PaginationNumber.swift +1 -9
  71. package/ios/Pagination/PaginationScroll.swift +2 -14
  72. package/ios/Pagination/PaginationWhiteDot.swift +1 -10
  73. package/ios/Popup/PopupDisplay.swift +7 -5
  74. package/ios/Popup/PopupInput.swift +6 -4
  75. package/ios/Popup/PopupLayout.swift +17 -9
  76. package/ios/Popup/PopupNotify.swift +32 -25
  77. package/ios/PopupView/FullscreenPopup.swift +3 -4
  78. package/ios/PopupView/PopupView.swift +2 -2
  79. package/ios/PopupView/Utils++.swift +1 -2
  80. package/ios/ProgressInfo/ProgressInfo.swift +2 -13
  81. package/ios/Skeleton/Skeleton.swift +5 -16
  82. package/ios/Slider/Slider.swift +5 -12
  83. package/ios/StatusBarTap/StatusBarTap.h +2 -3
  84. package/ios/StatusBarTap/StatusBarTap.m +3 -16
  85. package/ios/Stepper/Stepper.swift +8 -27
  86. package/ios/Steps/Steps.swift +29 -26
  87. package/ios/Swipeable/SwipeCell.swift +2 -2
  88. package/ios/Swipeable/SwipeCellModel.swift +3 -6
  89. package/ios/TabView/TabView.swift +14 -28
  90. package/ios/Template/TrustBanner/TrustBanner.swift +2 -9
  91. package/ios/Title/Title.swift +1 -3
  92. package/ios/Tooltip/Tooltip.swift +4 -9
  93. package/ios/Typography/FontScale.swift +79 -24
  94. package/ios/Typography/Text.swift +6 -12
  95. package/ios/Typography/Typography.swift +8 -11
  96. package/ios/Uploader/Uploader.swift +2 -17
  97. package/ios-demo/Resources/tabbar_scan_qr_button.json +1 -0
  98. package/ios-demo/Resources/tabbar_scan_qr_label.json +1 -0
  99. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/AnimatedHeaderDemo.swift +11 -2
  100. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +296 -59
  101. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/InputPhoneNumberDemo.swift +15 -4
  102. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/LocalizeDemo.swift +0 -8
  103. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/NavigationDemo.swift +114 -0
  104. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/PopupNotifyDemo.swift +29 -1
  105. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/TypographyDemo.swift +16 -0
  106. package/package.json +1 -1
  107. package/publish.sh +8 -2
package/CLAUDE.md CHANGED
@@ -42,19 +42,19 @@ xcodebuild -project sample/iosApp/Pods/Pods.xcodeproj -scheme MoMoUIKits -sdk ip
42
42
  -destination 'generic/platform=iOS Simulator' build
43
43
  ```
44
44
 
45
- Publishing is automated (`publish.sh` + GitLab CI on `[ci build]` / `main`). Do not publish manually unless asked: `sh publish.sh beta` / `sh publish.sh release` (Maven→GitLab + NPM).
45
+ Publishing is automated (`.gitlab-ci.yml` → `publish.sh`; see `PUBLISH_GUIDE.md`): `main` → npm latest + 1 patch (tag `latest`; a manual run with `RELEASE_VERSION` sets the sprint version), other branches on `[ci build]` → `<npm latest + 1 patch>-beta.N`. The version is never stored in the repo — `scripts/ci/resolve-version.mjs` bases it on npm and only takes a number free on **both** npm (incl. `-debug`) and GitLab Maven. Locally, `bash publish.sh local` publishes a beta of the working tree as is (uncommitted changes too, any branch; same beta numbering); `release` is CI-only. Do not publish unless asked; `bash publish.sh local --dry-run` shows the version and packs the tarballs without uploading.
46
46
 
47
47
  ## Architecture essentials
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
- - **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`.
50
+ - **Configuration flows via CompositionLocals**, not params. Public ones: `AppTheme`, `AppStatusBar`, `AppNavigationBar` (`const/Theme.kt`); `ApplicationContext`, `AppConfig`, `AppLanguage`, `LocalLocalize` (`application/`); `LocalNavigator`, `LocalKitsBinding` (`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
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
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.
54
54
  - **Platform code** goes through `expect`/`actual` in `platform/` — never reference Android/iOS APIs from `commonMain` directly.
55
- - **Native bridge:** typed `IMaxApi` from NativeMaxApi `0.3.1` (`vn.momo.maxapi`, exposed as `LocalMaxApi`) is the host-app bridge. Toolkit uses `ToolkitOptions` to preserve custom groups and system-tool policy; pending callbacks are cancelled when their composition is disposed. Containers borrow the host client and must not close it.
55
+ - **Host bridge:** `KitsBinding` (`application/KitsBinding.kt`, exposed as `LocalKitsBinding`) lists the only host services the kit calls; the host adapts its MaxApi to it. The kit must not depend on NativeMaxApi, common-model or foundation-model — add a binding method with kit-owned types instead. Callbacks fire on success only; pending `KitsRequest`s are cancelled when their composition is disposed. Containers borrow the binding and must not close it.
56
56
  - Navigation uses a runtime `DynamicScreenRegistry`; overlays (modal/bottom-sheet/snackbar) go through `Navigator` + `OverplayComponentRegistry`.
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.
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`. `binding` is optional: a container uses the one passed in, then the enclosing container's, then `KitsHost.binding` — the host installs it once with `KitsHost.install`, and packages that only render kit screens pass none (before an install it does nothing).
58
58
 
59
59
  ## SwiftUI kit (`ios/`)
60
60
 
@@ -71,17 +71,20 @@ Publishing is automated (`publish.sh` + GitLab CI on `[ci build]` / `main`). Do
71
71
  ## Screen layout / iPhone Duo (port of RN `useScreenLayout`, momo-kits !664)
72
72
 
73
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.
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`) drives popups, modal and bottom sheet.
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.
75
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.
76
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`.
77
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).
78
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.
79
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.
80
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.
81
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.
82
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.
83
- - Overlays on Duo: popups cap at 440pt wide and the room between `duoTopInset` and the bottom inset (body scrolls, actions stay); modal centers inside that room; bottom sheet uses the window height, centers at width ≥ 600 and pads by side insets in landscape.
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`).
84
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`.
85
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`.
86
89
 
87
90
  ## i18n / Localize (port of RN `Localize`)
@@ -104,12 +107,13 @@ The SwiftUI port differs from Compose in one important way: **it follows the hos
104
107
 
105
108
  ## Font scale (`scaleSize`)
106
109
 
107
- 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.
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`. The OS scale is capped at 1.5 by default; `MiniAppContext.scaleSizeMaxRate` (both sides) or `ScaleSizeScope(rate)` (Compose; SwiftUI also `.scaleSizeMaxRate(_:)`) caps a subtree at size × rate on both paths, nearest scope wins, null/nil lifts it (RN `ScaleSizeProvider`). The `ScaleSizeMaxRate` CompositionLocal is deprecated and not read.
108
111
 
109
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`.
110
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(_:)`.
111
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.
112
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`.
116
+ - **Bottom tab bar** — `BottomTab` caps the whole bar once at its root at `TabBarMetrics.LABEL_MAX_SCALE` / `labelMaxScale` (1.2, RN wraps `renderTabBar` in `ScaleSizeProvider`), so labels fit the fixed-height slots and the notch; the tab badge nests a scope of 1 to keep its design size. Consumer `iconContent` / `labelContent` sit under the same cap.
113
117
 
114
118
  ## Code conventions
115
119
 
@@ -132,7 +136,7 @@ Prefer one tight line at the surprising spot over a paragraph. Match the (low) c
132
136
  ## Gotchas
133
137
 
134
138
  - **Resource qualifier drift:** the generated Compose `Res` namespace is `vn.momo.uikits.resources`, but `utils/Resources.kt` and `platform/Platform.ios.kt` reference `vn.momo.compose.resources`. Keep bundled strings/dictionaries as plain Kotlin (the `defaultLanguage` map in `Localize.kt`), not `composeResources/values`, to avoid iOS framework resource-loading issues.
135
- - `LiteScreen` keeps its own `application.HeaderType` enum (`DEFAULT`/`EXTENDED`/`NONE`), unrelated to the sealed `navigation.component.HeaderType`; its toolkit is the navigation `Toolkit` (through `LocalMaxApi`).
139
+ - `LiteScreen` keeps its own `application.HeaderType` enum (`DEFAULT`/`EXTENDED`/`NONE`), unrelated to the sealed `navigation.component.HeaderType`; its toolkit is the navigation `Toolkit` (through `LocalKitsBinding`).
136
140
  - iOS strings/maps must survive Kotlin/Native framework packaging — keep them compiled-in, not loaded from resource bundles.
137
141
 
138
142
  ## Code comments
package/README.md CHANGED
@@ -114,7 +114,6 @@ NavigationContainer(
114
114
  options = NavigationOptions(headerTitle = HeaderTitle.Default("Home")),
115
115
  applicationContext = miniAppContext,
116
116
  config = KitConfig(trustBanner = defaultBanner),
117
- maxApi = maxApi, // IMaxApi implementation từ host
118
117
  setNavigator = { navigator = it }
119
118
  )
120
119
  ```
@@ -175,11 +174,13 @@ fun SuccessState() {
175
174
 
176
175
  - `shared/build.gradle.kts` đã bật `coreLibraryDesugaringEnabled` để tương thích `compottie-dot`/`compottie-network` với `minSdk = 24`.
177
176
  - 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.
177
+ ### KitsBinding (host bridge)
178
+
179
+ Kits không phụ thuộc NativeMaxApi hay model của host. Host cài `KitsBinding` một lần bằng
180
+ `KitsHost.install(binding)` (`vn.momo.kits.application`); `NavigationContainer` / `WidgetContainer`
181
+ dùng binding truyền vào, rồi của container bao ngoài, rồi `KitsHost.binding` (chưa cài thì không làm gì),
182
+ nên package chỉ dùng kits không cần binding riêng. Host tự chuyển sang bridge của mình (MaxApi): dismiss, trackEvent, getLanguage, haptic, toolkit (favorite,
183
+ `showToolkit(tools, useSystemTools)` trả `actionKey`), Help Center và log lỗi. Callback chỉ gọi khi
184
+ thành công; request đang chờ (`KitsRequest`) được hủy khi composition bị gỡ. Kits không đóng binding.
184
185
 
185
186
  Chạy `./gradlew :compose:testAndroidHostTest` để kiểm tra hủy request và callback đến muộn.
@@ -21,8 +21,10 @@ public class MiniAppContext {
21
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
+ // Caps the font scale at size × rate, nil means no cap (Compose MiniAppContext.scaleSizeMaxRate).
25
+ public var scaleSizeMaxRate: CGFloat? = nil
24
26
 
25
- public init(appId: String, appCode: String, appName: Any? = nil, appIcon: String, description: Any? = nil, support: [String: Any] = [:], toolkitConfig: [String: Any] = [:], providerId: String = "momo", permissions: [[String: Any]] = [], userScaleRate: CGFloat? = nil, useOSScaleRate: Bool? = nil) {
27
+ public init(appId: String, appCode: String, appName: Any? = nil, appIcon: String, description: Any? = nil, support: [String: Any] = [:], toolkitConfig: [String: Any] = [:], providerId: String = "momo", permissions: [[String: Any]] = [], userScaleRate: CGFloat? = nil, useOSScaleRate: Bool? = nil, scaleSizeMaxRate: CGFloat? = nil) {
26
28
  self.appId = appId
27
29
  self.appCode = appCode
28
30
  self.appName = appName
@@ -34,6 +36,7 @@ public class MiniAppContext {
34
36
  self.permissions = permissions
35
37
  self.userScaleRate = userScaleRate
36
38
  self.useOSScaleRate = useOSScaleRate
39
+ self.scaleSizeMaxRate = scaleSizeMaxRate
37
40
  }
38
41
  }
39
42
 
@@ -51,12 +54,11 @@ public struct KitConfig: Equatable {
51
54
  }
52
55
 
53
56
  public class ApplicationEnvironment: ObservableObject {
54
- // AI-GENERATED START: expose the host bridge to modules outside MoMoUIKits (e.g. the demo pod)
57
+ // Public so modules outside MoMoUIKits (e.g. the demo pod) can reach the host bridge.
55
58
  public let applicationContext: MiniAppContext?
56
59
  public let composeApi: KitComposeApi?
57
60
  public let config: KitConfig?
58
61
  public let maxApi: MaxApi?
59
- // AI-GENERATED END: expose the host bridge to modules outside MoMoUIKits (e.g. the demo pod)
60
62
 
61
63
  public init(applicationContext: MiniAppContext? = nil, composeApi: KitComposeApi? = nil, config: KitConfig? = nil, maxApi: MaxApi? = nil) {
62
64
  self.applicationContext = applicationContext
@@ -67,7 +69,7 @@ public class ApplicationEnvironment: ObservableObject {
67
69
  }
68
70
 
69
71
  extension ApplicationEnvironment {
70
- /// Closes the mini app: through `composeApi` as before, else `maxApi` (Compose `maxApi.dismiss`).
72
+ /// Closes the mini app through `composeApi`, else `maxApi` (Compose `maxApi.dismiss`).
71
73
  func requestDismiss() {
72
74
  if let composeApi {
73
75
  composeApi.requestCallback(funcName: "dismiss", params: nil, onResponse: nil)
@@ -1,10 +1,3 @@
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
1
  import SwiftUI
9
2
 
10
3
  /// Host-owned design-system inputs; mirrors Compose's `DesignSystemKitsConfigs` field for field.
@@ -27,15 +20,16 @@ public struct DesignSystemKitsConfigs: Equatable {
27
20
  }
28
21
  }
29
22
 
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.
23
+ /// Compose's `DesignSystemKits` without `init(source:)` (Swift reserves `init`): the host pushes `setConfigs(_:)` at
24
+ /// startup and on every change. Also tracks Dynamic Type; views re-render only under `.momoFontScale()`.
34
25
  public final class DesignSystemKits: ObservableObject {
35
26
  public static let shared = DesignSystemKits()
36
27
 
37
28
  @Published private var configs = DesignSystemKitsConfigs()
38
29
  @Published public private(set) var osFontScale: CGFloat = DesignSystemKits.currentOsFontScale()
30
+ /// Republished when the window scene resizes (iPhone Duo fold/unfold) so the font scale follows.
31
+ @Published public private(set) var windowShortSide: CGFloat = DesignSystemKits.currentWindowShortSide()
32
+ private var geometryObservations: [ObjectIdentifier: NSKeyValueObservation] = [:]
39
33
 
40
34
  private init() {
41
35
  NotificationCenter.default.addObserver(
@@ -44,6 +38,17 @@ public final class DesignSystemKits: ObservableObject {
44
38
  name: UIContentSizeCategory.didChangeNotification,
45
39
  object: nil
46
40
  )
41
+ NotificationCenter.default.addObserver(
42
+ self,
43
+ selector: #selector(sceneDidActivate(_:)),
44
+ name: UIScene.didActivateNotification,
45
+ object: nil
46
+ )
47
+ onMain {
48
+ UIApplication.shared.connectedScenes
49
+ .compactMap { $0 as? UIWindowScene }
50
+ .forEach(self.observeGeometry(of:))
51
+ }
47
52
  }
48
53
 
49
54
  public func setConfigs(_ configs: DesignSystemKitsConfigs) {
@@ -62,7 +67,8 @@ public final class DesignSystemKits: ObservableObject {
62
67
  FontScale(
63
68
  userScaleRate: configs.userScaleRate,
64
69
  useOSScaleRate: configs.useOSScaleRate,
65
- osFontScale: osFontScale
70
+ osFontScale: osFontScale,
71
+ windowShortSide: windowShortSide
66
72
  )
67
73
  }
68
74
 
@@ -72,6 +78,47 @@ public final class DesignSystemKits: ObservableObject {
72
78
  osFontScale = next
73
79
  }
74
80
 
81
+ @objc private func sceneDidActivate(_ notification: Notification) {
82
+ guard let scene = notification.object as? UIWindowScene else { return }
83
+ observeGeometry(of: scene)
84
+ refreshWindowShortSide()
85
+ }
86
+
87
+ private func observeGeometry(of scene: UIWindowScene) {
88
+ guard #available(iOS 16.0, *) else { return }
89
+ let key = ObjectIdentifier(scene)
90
+ guard geometryObservations[key] == nil else { return }
91
+ geometryObservations[key] = scene.observe(\.effectiveGeometry, options: [.new]) { [weak self] _, _ in
92
+ // The window is resized after the scene geometry, so read it on the next turn.
93
+ DispatchQueue.main.async { self?.refreshWindowShortSide() }
94
+ }
95
+ }
96
+
97
+ private func refreshWindowShortSide() {
98
+ let next = Self.currentWindowShortSide()
99
+ guard next > 0, next != windowShortSide else { return }
100
+ windowShortSide = next
101
+ }
102
+
103
+ /// UIScreen.main stays on one display on iPhone Duo, so measure the foreground window instead.
104
+ static func currentWindowShortSide() -> CGFloat {
105
+ guard Thread.isMainThread else {
106
+ return min(UIScreen.main.bounds.width, UIScreen.main.bounds.height)
107
+ }
108
+ let scenes = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }
109
+ let scene = scenes.first { $0.activationState == .foregroundActive } ?? scenes.first
110
+ let window = scene?.windows.first { $0.isKeyWindow } ?? scene?.windows.first
111
+ let size: CGSize
112
+ if let window, window.bounds.width > 0 {
113
+ size = window.bounds.size
114
+ } else if let scene {
115
+ size = scene.coordinateSpace.bounds.size
116
+ } else {
117
+ size = UIScreen.main.bounds.size
118
+ }
119
+ return min(size.width, size.height)
120
+ }
121
+
75
122
  /// Same factor Compose's iOS `ProvideOsFontScale` derives from
76
123
  /// `UIFont.preferredFont(forTextStyle: .body).pointSize / 17`, so both iOS surfaces scale alike.
77
124
  static func currentOsFontScale() -> CGFloat {
@@ -97,4 +144,3 @@ public extension EnvironmentValues {
97
144
  set { self[DesignSystemKitsConfigsKey.self] = newValue }
98
145
  }
99
146
  }
100
- // AI-GENERATED END: app-wide design-system holder mirroring Compose's DesignSystemKits
@@ -1,10 +1,3 @@
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
1
  import Foundation
9
2
 
10
3
  public extension DesignSystemKits {
@@ -65,4 +58,3 @@ private struct TrustBannerPayload: Decodable {
65
58
  )
66
59
  }
67
60
  }
68
- // AI-GENERATED END: JSON entry point for hosts that can't share Swift types with the kit
@@ -1,10 +1,3 @@
1
- // File: ios/Application/LanguageSource.swift
2
- // Created At: 2026-07-29 10:00:00 +07:00
3
- // Created By: AI
4
- // AI Agent: Claude Code
5
- // Model: claude-opus-5[1m]
6
-
7
- // AI-GENERATED START: observe the host app's active language so Localize can follow it
8
1
  import Foundation
9
2
 
10
3
  /// Read-only view of the host app's active language, plus change delivery.
@@ -16,9 +9,8 @@ public protocol LanguageSource: AnyObject {
16
9
  func stopObserving()
17
10
  }
18
11
 
19
- /// Reads the language the MoMo host app persists in `UserDefaults`. All three host writers
20
- /// (the `RNResource` RN bridge, `JSONLocalization`, and the KMP `LocalizationProvider`) write the
21
- /// same key on `UserDefaults.standard` in-process, so KVO on it sees every one of them.
12
+ /// All three host writers (RN bridge `RNResource`, `JSONLocalization`, KMP `LocalizationProvider`) write the same
13
+ /// `UserDefaults.standard` key in-process, so KVO on it sees every language change.
22
14
  public final class UserDefaultsLanguageSource: NSObject, LanguageSource {
23
15
  public static let defaultKey = "language"
24
16
 
@@ -90,4 +82,3 @@ public final class UserDefaultsLanguageSource: NSObject, LanguageSource {
90
82
  onChange?(currentLanguage)
91
83
  }
92
84
  }
93
- // AI-GENERATED END: observe the host app's active language so Localize can follow it
@@ -1,14 +1,5 @@
1
- //
2
- // Localize.swift
3
- // MoMoUIKits
4
- //
5
- // SwiftUI mirror of Compose's `application/Localize.kt`, itself a port of
6
- // momo-kits React Native's `Application/Localize.ts`. Holds the merged
7
- // dictionary (kit defaults + host overrides) and the active language,
8
- // switched at runtime via `changeLanguage`. `Localize` is an `ObservableObject`
9
- // so a language switch republishes to consumers of `translate`/`translateData`,
10
- // mirroring Compose's snapshot-state-backed `language`.
11
- //
1
+ // SwiftUI mirror of Compose's `application/Localize.kt` (port of RN `Application/Localize.ts`):
2
+ // kit defaults + host overrides and the active language, published like Compose's snapshot state.
12
3
 
13
4
  import Foundation
14
5
  import SwiftUI
@@ -28,16 +19,13 @@ public final class Localize: ObservableObject {
28
19
  public static let VI = "vi"
29
20
  public static let EN = "en"
30
21
 
31
- // AI-GENERATED START: follow the host app language and publish dictionary changes
32
22
  /// App-wide instance bound to the host language; the environment default uses it too,
33
23
  /// so every screen agrees on one language.
34
24
  public static let shared = Localize()
35
- // AI-GENERATED END: follow the host app language and publish dictionary changes
36
25
 
37
26
  private var assets: LocalizationObject
38
27
  @Published public private(set) var currentLanguage: String = Localize.VI
39
28
 
40
- // AI-GENERATED START: follow the host app language and publish dictionary changes
41
29
  /// Bumped by `addTranslations` — `assets` is not published, so without this the dictionary
42
30
  /// can change without any consumer re-rendering.
43
31
  @Published public private(set) var revision: Int = 0
@@ -47,7 +35,7 @@ public final class Localize: ObservableObject {
47
35
  /// `NavigationContainer` uses this to skip its legacy one-shot `MaxApi` pull.
48
36
  var observesAppLanguage: Bool { languageSource != nil }
49
37
 
50
- /// Pass `languageSource: nil` to opt out and keep the old "starts at vi" behavior.
38
+ /// `languageSource: nil` opts out: the language starts at `vi` and moves only on `changeLanguage`.
51
39
  public init(
52
40
  _ translations: LocalizationObject = LocalizationObject(),
53
41
  languageSource: LanguageSource? = UserDefaultsLanguageSource()
@@ -90,7 +78,6 @@ public final class Localize: ObservableObject {
90
78
  public func changeLanguage(_ language: String?) {
91
79
  apply(Localize.normalize(language))
92
80
  }
93
- // AI-GENERATED END: follow the host app language and publish dictionary changes
94
81
 
95
82
  public func translate(_ key: String) -> String {
96
83
  let dictionary = currentLanguage == Localize.EN ? assets.en : assets.vi
@@ -111,9 +98,7 @@ public final class Localize: ObservableObject {
111
98
  /// Existing keys win (mirrors Compose: `merge(translations, assets)`).
112
99
  public func addTranslations(_ translations: LocalizationObject) {
113
100
  assets = Localize.merge(base: translations, override: assets)
114
- // AI-GENERATED START: publish dictionary changes so consumers re-render
115
101
  onMain { self.revision &+= 1 }
116
- // AI-GENERATED END: publish dictionary changes so consumers re-render
117
102
  }
118
103
 
119
104
  private static func merge(base: LocalizationObject, override: LocalizationObject) -> LocalizationObject {
@@ -333,41 +318,29 @@ public final class Localize: ObservableObject {
333
318
  )
334
319
  }
335
320
 
336
- /// Snapshots `currentLanguage` alongside the instance so SwiftUI sees an environment
337
- /// *change* on `changeLanguage`: the `Localize` reference alone never changes, and
338
- /// `@Environment` does not subscribe to `@Published` the way `@EnvironmentObject` does.
321
+ /// Snapshots `currentLanguage` so `changeLanguage` is an environment *change*: the reference never changes, and
322
+ /// `@Environment` doesn't subscribe to `@Published` the way `@EnvironmentObject` does.
339
323
  private struct LocalizeBox: Equatable {
340
324
  let localize: Localize
341
325
  let language: String
342
- // AI-GENERATED START: invalidate consumers when the dictionary changes, not just the language
326
+ // Invalidates consumers on dictionary changes too, not just language switches.
343
327
  let revision: Int
344
- // AI-GENERATED END: invalidate consumers when the dictionary changes, not just the language
345
328
 
346
329
  init(_ localize: Localize) {
347
330
  self.localize = localize
348
331
  self.language = localize.currentLanguage
349
- // AI-GENERATED START: invalidate consumers when the dictionary changes, not just the language
350
332
  self.revision = localize.revision
351
- // AI-GENERATED END: invalidate consumers when the dictionary changes, not just the language
352
333
  }
353
334
 
354
335
  static func == (lhs: LocalizeBox, rhs: LocalizeBox) -> Bool {
355
- // AI-GENERATED START: invalidate consumers when the dictionary changes, not just the language
356
336
  lhs.localize === rhs.localize && lhs.language == rhs.language && lhs.revision == rhs.revision
357
- // AI-GENERATED END: invalidate consumers when the dictionary changes, not just the language
358
337
  }
359
338
  }
360
339
 
361
340
  private struct LocalizeKey: EnvironmentKey {
362
- /// A default-constructed `Localize` already carries the full kit dictionary, so a
363
- /// consumer that never injects one renders untranslated-but-correct text instead of
364
- /// trapping the way `@EnvironmentObject` does.
365
- // AI-GENERATED START: default to the app-language-observing shared instance
366
- /// `defaultValue` is a `static let`, so this box is never rebuilt: without a provider the
367
- /// language is right on first render but does not live-update. Wrap the root in
368
- /// `.momoLocalize()` (or use `NavigationContainer`) to get updates.
341
+ /// Never traps like `@EnvironmentObject`, but as a `static let` it is never rebuilt: without `.momoLocalize()`
342
+ /// (or `NavigationContainer`) the language is right on first render but does not live-update.
369
343
  static let defaultValue = LocalizeBox(Localize.shared)
370
- // AI-GENERATED END: default to the app-language-observing shared instance
371
344
  }
372
345
 
373
346
  public extension EnvironmentValues {
@@ -1,10 +1,3 @@
1
- // File: ios/Application/LocalizeModifier.swift
2
- // Created At: 2026-07-29 10:00:00 +07:00
3
- // Created By: AI
4
- // AI Agent: Claude Code
5
- // Model: claude-opus-5[1m]
6
-
7
- // AI-GENERATED START: inject a language-observing Localize into any SwiftUI subtree
8
1
  import SwiftUI
9
2
 
10
3
  public extension View {
@@ -15,9 +8,8 @@ public extension View {
15
8
  }
16
9
  }
17
10
 
18
- /// `@ObservedObject` is load-bearing: `@Environment(\.localize)` only invalidates when the boxed
19
- /// value changes, which requires *this* body to re-run on every publish. A plain helper that just
20
- /// set `\.localize` would inject a snapshot that never updates.
11
+ /// `@ObservedObject` is load-bearing: `@Environment(\.localize)` invalidates only when *this* body re-runs on a
12
+ /// publish; a helper that just set `\.localize` would inject a snapshot that never updates.
21
13
  private struct MomoLocalizeModifier: ViewModifier {
22
14
  @ObservedObject var localize: Localize
23
15
 
@@ -27,4 +19,3 @@ private struct MomoLocalizeModifier: ViewModifier {
27
19
  .environment(\.localize, localize)
28
20
  }
29
21
  }
30
- // AI-GENERATED END: inject a language-observing Localize into any SwiftUI subtree
@@ -1,13 +1,5 @@
1
- //
2
- // MaxApi.swift
3
- // MoMoUIKits
4
- //
5
- // Swift mirror of the host-app bridge exposed on Kotlin as `vn.momo.maxapi.IMaxApi`
6
- // (`LocalMaxApi`). `IMaxApi` itself is an external compiled dependency with no
7
- // source in this repo, so this protocol intentionally exposes only the methods
8
- // this kit's Kotlin source actually calls — not a full guess at IMaxApi's real surface.
9
- // Callbacks carry IMaxApi's `["response": …]` payload.
10
- //
1
+ // Swift mirror of the host bridge `vn.momo.maxapi.IMaxApi` (`LocalMaxApi`). IMaxApi is an external
2
+ // binary, so only the methods the kit calls are declared; callbacks carry its `["response": …]` payload.
11
3
 
12
4
  import UIKit
13
5
 
@@ -32,7 +24,7 @@ public extension MaxApi {
32
24
  UIImpactFeedbackGenerator(style: .light).impactOccurred()
33
25
  }
34
26
 
35
- // Hosts that don't bridge the toolkit keep it inert, as before these joined the protocol.
27
+ // Hosts that don't bridge the toolkit keep it inert.
36
28
  func isFavoriteApp(_ params: [String: Any?], callback: @escaping ([String: Any?]?) -> Void) {}
37
29
  func onToolAction(_ params: [String: Any?], callback: @escaping ([String: Any?]?) -> Void) {}
38
30
  func showTools(_ params: [String: Any?], callback: @escaping ([String: Any?]?) -> Void) {}
@@ -65,7 +65,6 @@ public struct Avatar: View {
65
65
 
66
66
  public var body: some View {
67
67
  ZStack {
68
- // Inner content clipped by shape with border
69
68
  ZStack {
70
69
  content
71
70
  }
@@ -41,17 +41,14 @@ public struct Badge: View {
41
41
  }
42
42
 
43
43
  private var badgeColor: Color {
44
- // Default colors based on label type
45
- let defaultColor: Color = isNumber(label)
46
- ? theme.colors.error.primary
47
- : theme.colors.warning.primary
48
-
49
- // Mirror Compose: only apply backgroundColor when it is one of the
50
- // allowed primaryColors; otherwise fall back to the label-based default.
44
+ // Mirrors Compose: backgroundColor applies only when it is one of primaryColors.
51
45
  if let bgColor = backgroundColor, primaryColors.contains(bgColor) {
52
46
  return bgColor
53
47
  }
54
- return defaultColor
48
+ if isNumber(label) {
49
+ return theme.colors.error.primary
50
+ }
51
+ return theme.colors.warning.primary
55
52
  }
56
53
 
57
54
  public var body: some View {
@@ -198,10 +198,8 @@ public struct BadgeRibbon: View {
198
198
  }
199
199
  }
200
200
 
201
- /// Ported from Compose's `RoundedBadgeRibbon` (BadgeRibbon.kt:164-326): a canvas-drawn
202
- /// ribbon shape sized to its text, mirrored per corner via scaleX/scaleY (never an actual
203
- /// rotation) — the label gets the same scale applied a second time so it stays right-reading
204
- /// while only the ribbon shape flips.
201
+ /// Compose's `RoundedBadgeRibbon`: a ribbon sized to its text, mirrored per corner with
202
+ /// scaleX/scaleY (never rotated); the label is scaled again so only the shape flips.
205
203
  public struct RoundedBadgeRibbon: View {
206
204
  @Environment(\.appTheme) private var theme
207
205
  @Environment(\.momoFontScale) private var fontScale
@@ -312,7 +310,6 @@ extension String {
312
310
  struct BadgeRibbon_Previews: PreviewProvider {
313
311
  static var previews: some View {
314
312
  VStack(spacing: 30) {
315
- // Basic ribbon examples
316
313
  BadgeRibbon(position: .topRight, label: "New")
317
314
  BadgeRibbon(position: .topLeft, label: "Hot", isRound: true)
318
315
  BadgeRibbon(position: .bottomLeft, label: "Sale")
@@ -229,9 +229,8 @@ public struct Button: View {
229
229
  }
230
230
  }
231
231
 
232
- /// Mirrors Compose's press feedback: the background shrinks via an animated
233
- /// horizontal inset and the whole button (background included) fades to 0.5,
234
- /// matching `animatedPadding`/`alpha` in Button.kt.
232
+ /// Compose's press feedback (`animatedPadding` / `alpha` in Button.kt): the background shrinks by an animated
233
+ /// horizontal inset and the whole button fades to 0.5.
235
234
  private struct ButtonPressFeedbackStyle: ButtonStyle {
236
235
  let isEnabled: Bool
237
236
  let background: Color
@@ -264,11 +263,8 @@ private struct ButtonPressFeedbackStyle: ButtonStyle {
264
263
  }
265
264
  }
266
265
 
267
- /// `ButtonStyleConfiguration.Label` is greedy on iOS 16 and earlier — it accepts
268
- /// the full proposed width, so the background drawn in `makeBody` stretches past
269
- /// the content even when `isFull == false`. iOS 17 fixed the label to hug its
270
- /// content, so only legacy OSes need the `fixedSize` clamp (kept off on 17+ to
271
- /// preserve tail truncation of long titles).
266
+ /// The style label takes the full proposed width before iOS 17, stretching the background
267
+ /// past the content; `fixedSize` there only, as on 17+ it would stop long titles truncating.
272
268
  private struct HugContentOnLegacyOS: ViewModifier {
273
269
  let isFull: Bool
274
270
 
@@ -52,8 +52,8 @@ public struct CalculatorKeyboard: View {
52
52
  }
53
53
  }
54
54
 
55
- /// Integer `+ - * /` with the usual precedence, as NSExpression did, but nil instead of a
56
- /// crash when a number or result leaves `Int` range.
55
+ /// Integer `+ - * /` with the usual precedence. Not NSExpression: it crashes when a number or
56
+ /// result leaves `Int` range, where this returns nil.
57
57
  static func evaluate(_ expression: String) -> Int? {
58
58
  var numbers: [Int] = []
59
59
  var operators: [Character] = []
@@ -92,11 +92,9 @@ public struct CalculatorKeyboard: View {
92
92
 
93
93
  var result = terms[0]
94
94
  for (sign, term) in zip(signs, terms.dropFirst()) {
95
- let (next, overflow) = sign == "+"
96
- ? result.addingReportingOverflow(term)
97
- : result.subtractingReportingOverflow(term)
98
- if overflow { return nil }
99
- result = next
95
+ let step = sign == "+" ? result.addingReportingOverflow(term) : result.subtractingReportingOverflow(term)
96
+ if step.overflow { return nil }
97
+ result = step.partialValue
100
98
  }
101
99
  return result
102
100
  }