@momo-kits/native-kits 0.168.1-beta.1 → 0.168.1-beta.10
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 +7 -5
- package/ios/Application/ApplicationEnvironment.swift +7 -6
- package/ios/Application/DesignSystemKits.swift +100 -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 +13 -3
- package/ios/Input/InputPhoneNumber.swift +1 -3
- package/ios/Input/InputSearch.swift +1 -2
- package/ios/Input/InputTextArea.swift +5 -3
- package/ios/InputMoney/InputMoney.swift +6 -7
- package/ios/Layout/ScreenLayout.swift +46 -11
- package/ios/Navigation/BottomTab/DuoBarCompression.swift +2 -3
- package/ios/Navigation/BottomTab/DuoTabBar.swift +94 -69
- package/ios/Navigation/Component/HeaderBackground.swift +22 -1
- package/ios/Navigation/StackScreen.swift +3 -7
- package/ios/Popup/PopupLayout.swift +0 -2
- package/ios/Stepper/Stepper.swift +1 -2
- package/ios/Template/TrustBanner/TrustBanner.swift +4 -2
- package/ios/Typography/FontScale.swift +14 -11
- package/ios/Typography/Text.swift +86 -12
- package/ios/Typography/Typography.swift +2 -2
- package/ios/native-kits.podspec +1 -1
- package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
- package/package.json +1 -1
- package/ios/Typography/FontScaleStore.swift +0 -58
- package/ios/Typography/KitDesignSystem.swift +0 -17
package/CLAUDE.md
CHANGED
|
@@ -48,7 +48,9 @@ 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
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`.
|
|
@@ -69,7 +71,7 @@ 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`) 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).
|
|
@@ -104,9 +106,9 @@ The SwiftUI port differs from Compose in one important way: **it follows the hos
|
|
|
104
106
|
|
|
105
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.
|
|
106
108
|
|
|
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
|
|
109
|
+
- **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
|
+
- **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
|
+
- **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
112
|
- 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
113
|
|
|
112
114
|
## Code conventions
|
|
@@ -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,100 @@
|
|
|
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
|
+
|
|
40
|
+
private init() {
|
|
41
|
+
NotificationCenter.default.addObserver(
|
|
42
|
+
self,
|
|
43
|
+
selector: #selector(contentSizeCategoryDidChange),
|
|
44
|
+
name: UIContentSizeCategory.didChangeNotification,
|
|
45
|
+
object: nil
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public func setConfigs(_ configs: DesignSystemKitsConfigs) {
|
|
50
|
+
onMain {
|
|
51
|
+
// Re-assigning an unchanged value would still publish and invalidate every kit subtree.
|
|
52
|
+
guard self.configs != configs else { return }
|
|
53
|
+
self.configs = configs
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public func getConfigs() -> DesignSystemKitsConfigs {
|
|
58
|
+
configs
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public var fontScale: FontScale {
|
|
62
|
+
FontScale(
|
|
63
|
+
userScaleRate: configs.userScaleRate,
|
|
64
|
+
useOSScaleRate: configs.useOSScaleRate,
|
|
65
|
+
osFontScale: osFontScale
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
@objc private func contentSizeCategoryDidChange() {
|
|
70
|
+
let next = Self.currentOsFontScale()
|
|
71
|
+
guard next != osFontScale else { return }
|
|
72
|
+
osFontScale = next
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/// Same factor Compose's iOS `ProvideOsFontScale` derives from
|
|
76
|
+
/// `UIFont.preferredFont(forTextStyle: .body).pointSize / 17`, so both iOS surfaces scale alike.
|
|
77
|
+
static func currentOsFontScale() -> CGFloat {
|
|
78
|
+
let base = UIFont.systemFont(ofSize: UIFont.labelFontSize)
|
|
79
|
+
return UIFontMetrics.default.scaledFont(for: base).pointSize / base.pointSize
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/// Synchronous when already on main — an async hop would defer the change by a frame.
|
|
83
|
+
private func onMain(_ work: @escaping () -> Void) {
|
|
84
|
+
if Thread.isMainThread { work() } else { DispatchQueue.main.async(execute: work) }
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private struct DesignSystemKitsConfigsKey: EnvironmentKey {
|
|
89
|
+
/// Computed, never stored: an un-injected subtree still reads the live holder, just not reactively.
|
|
90
|
+
static var defaultValue: DesignSystemKitsConfigs { DesignSystemKits.shared.getConfigs() }
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
public extension EnvironmentValues {
|
|
94
|
+
/// Injected by `.momoFontScale()`; never set it directly (same trap as `\.momoFontScale`).
|
|
95
|
+
var designSystemKitsConfigs: DesignSystemKitsConfigs {
|
|
96
|
+
get { self[DesignSystemKitsConfigsKey.self] }
|
|
97
|
+
set { self[DesignSystemKitsConfigsKey.self] = newValue }
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// 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)
|
|
@@ -345,7 +345,12 @@ private struct SecureInputField: UIViewRepresentable {
|
|
|
345
345
|
textField.spellCheckingType = .no
|
|
346
346
|
textField.delegate = context.coordinator
|
|
347
347
|
textField.keyboardType = keyboardType
|
|
348
|
-
textField.font =
|
|
348
|
+
textField.font = momoUIFont(
|
|
349
|
+
size: fontSize,
|
|
350
|
+
weight: fontWeight,
|
|
351
|
+
family: context.environment.appTheme.font,
|
|
352
|
+
isWhiteList: context.environment.designSystemKitsConfigs.isWhiteList
|
|
353
|
+
)
|
|
349
354
|
textField.textColor = textColor
|
|
350
355
|
textField.isEnabled = !isDisabled
|
|
351
356
|
textField.setContentHuggingPriority(.defaultLow, for: .horizontal)
|
|
@@ -370,7 +375,12 @@ private struct SecureInputField: UIViewRepresentable {
|
|
|
370
375
|
if textField.text != text {
|
|
371
376
|
textField.text = text
|
|
372
377
|
}
|
|
373
|
-
let font =
|
|
378
|
+
let font = momoUIFont(
|
|
379
|
+
size: fontSize,
|
|
380
|
+
weight: fontWeight,
|
|
381
|
+
family: context.environment.appTheme.font,
|
|
382
|
+
isWhiteList: context.environment.designSystemKitsConfigs.isWhiteList
|
|
383
|
+
)
|
|
374
384
|
if textField.font != font {
|
|
375
385
|
textField.font = font
|
|
376
386
|
}
|
|
@@ -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 {
|
|
@@ -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 {
|
|
@@ -32,6 +32,8 @@ public struct ScreenLayout: Equatable {
|
|
|
32
32
|
public let width: CGFloat
|
|
33
33
|
public let height: CGFloat
|
|
34
34
|
public let isIPhoneDuo: Bool
|
|
35
|
+
/// The device has a hinge, folded or not, whatever the window size; drives popups, modal and bottom sheet.
|
|
36
|
+
public let isDuoDevice: Bool
|
|
35
37
|
public let insets: EdgeInsets
|
|
36
38
|
public let insetLeft: CGFloat
|
|
37
39
|
public let insetRight: CGFloat
|
|
@@ -68,8 +70,11 @@ enum DuoMetrics {
|
|
|
68
70
|
// (x 550–643 of 669, clock digits centered on y 47); its reserved region is taller than the glyphs.
|
|
69
71
|
static let innerStatusBarCenterY: CGFloat = 47
|
|
70
72
|
static let innerStatusBarWidth: CGFloat = 120
|
|
71
|
-
//
|
|
72
|
-
|
|
73
|
+
// Host app's iOS 26 tab bar on the inner display in portrait: a 62pt glass pill sized to its tabs,
|
|
74
|
+
// QR as a 62pt platter beside it, ≥ 20pt from the sides, 13pt into the home indicator inset.
|
|
75
|
+
static let floatingTabBarHeight: CGFloat = 62
|
|
76
|
+
static let floatingTabBarMargin: CGFloat = 20
|
|
77
|
+
static let floatingTabBarInsetOverlap: CGFloat = 13
|
|
73
78
|
}
|
|
74
79
|
|
|
75
80
|
enum HeaderMetrics {
|
|
@@ -104,15 +109,17 @@ extension ScreenLayout {
|
|
|
104
109
|
size: CGSize,
|
|
105
110
|
insets: EdgeInsets,
|
|
106
111
|
reservedRegions: [CGRect] = ReservedRegions.current,
|
|
107
|
-
isPhone: Bool = isPhoneIdiom
|
|
112
|
+
isPhone: Bool = isPhoneIdiom,
|
|
113
|
+
isFoldable: Bool = FoldableDevice.isFoldable(measuredIn: keyWindow)
|
|
108
114
|
) -> ScreenLayout {
|
|
109
115
|
let width = size.width
|
|
110
116
|
let height = size.height
|
|
117
|
+
let isDuoDevice = isPhone && isFoldable
|
|
111
118
|
var (headerHeight, headerStatusBarHeight) = headerGeometry(topInset: insets.top, isPhone: isPhone)
|
|
112
119
|
let isDuo = isPhone && isIPhoneDuoWindow(width: width, height: height, insets: insets)
|
|
113
120
|
guard isDuo else {
|
|
114
121
|
return ScreenLayout(
|
|
115
|
-
width: width, height: height, isIPhoneDuo: false, insets: insets,
|
|
122
|
+
width: width, height: height, isIPhoneDuo: false, isDuoDevice: isDuoDevice, insets: insets,
|
|
116
123
|
insetLeft: 0, insetRight: 0, contentWidth: width,
|
|
117
124
|
headerHeight: headerHeight, headerStatusBarHeight: headerStatusBarHeight, sideBar: nil,
|
|
118
125
|
statusBarClearance: nil
|
|
@@ -172,7 +179,7 @@ extension ScreenLayout {
|
|
|
172
179
|
}
|
|
173
180
|
|
|
174
181
|
return ScreenLayout(
|
|
175
|
-
width: width, height: height, isIPhoneDuo: true, insets: insets,
|
|
182
|
+
width: width, height: height, isIPhoneDuo: true, isDuoDevice: isDuoDevice, insets: insets,
|
|
176
183
|
insetLeft: insets.leading, insetRight: insets.trailing,
|
|
177
184
|
contentWidth: width - insets.leading - insets.trailing,
|
|
178
185
|
headerHeight: headerHeight, headerStatusBarHeight: headerStatusBarHeight, sideBar: sideBar,
|
|
@@ -251,13 +258,40 @@ extension ScreenLayout {
|
|
|
251
258
|
}
|
|
252
259
|
}
|
|
253
260
|
|
|
254
|
-
///
|
|
255
|
-
///
|
|
261
|
+
/// Snapshot for call sites without `\.screenLayout`; not reactive. `windowSize` is ignored,
|
|
262
|
+
/// kept for host call sites.
|
|
256
263
|
public func isIPhoneDuoDevice(windowSize: CGSize? = nil) -> Bool {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
264
|
+
isPhoneIdiom && FoldableDevice.isFoldable(measuredIn: keyWindow)
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/// Apple's foldable check (as the host's `SideTabRailView.isFoldableDevice`): only a device with a
|
|
268
|
+
/// hinge reports a `.division` region, inactive while flat but still there. Screen size cannot tell
|
|
269
|
+
/// it apart from a large iPhone in landscape or a narrowed window.
|
|
270
|
+
enum FoldableDevice {
|
|
271
|
+
// a hinge never goes away, so a positive answer is kept
|
|
272
|
+
private static var isKnownFoldable = false
|
|
273
|
+
|
|
274
|
+
static func isFoldable(measuredIn view: UIView?) -> Bool {
|
|
275
|
+
if isKnownFoldable { return true }
|
|
276
|
+
// compiled out on SDKs older than iOS 27.1 (UIKit 9127.0.85.28)
|
|
277
|
+
#if canImport(UIKit, _version: 9127.0.85.28)
|
|
278
|
+
guard #available(iOS 27.1, *), let view, view.window != nil || view is UIWindow else { return false }
|
|
279
|
+
isKnownFoldable = !view.reservedRegions(kind: .division, options: .includeInactive).isEmpty
|
|
280
|
+
#endif
|
|
281
|
+
return isKnownFoldable
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/// Catches the hinge when the regions were read too early (before the window had them).
|
|
285
|
+
static func observe(in view: UIView) {
|
|
286
|
+
#if canImport(UIKit, _version: 9127.0.85.28)
|
|
287
|
+
guard #available(iOS 27.1, *) else { return }
|
|
288
|
+
view.addInteraction(UIHingeInteraction { _, update in
|
|
289
|
+
guard update.hinge != nil, !isKnownFoldable else { return }
|
|
290
|
+
isKnownFoldable = true
|
|
291
|
+
NotificationCenter.default.post(name: ReservedRegions.didChange, object: nil)
|
|
292
|
+
})
|
|
293
|
+
#endif
|
|
294
|
+
}
|
|
261
295
|
}
|
|
262
296
|
|
|
263
297
|
// MARK: - Reserved regions
|
|
@@ -282,6 +316,7 @@ private final class ReservedRegionsProbe: UIView {
|
|
|
282
316
|
override init(frame: CGRect) {
|
|
283
317
|
super.init(frame: frame)
|
|
284
318
|
isUserInteractionEnabled = false
|
|
319
|
+
FoldableDevice.observe(in: self)
|
|
285
320
|
}
|
|
286
321
|
|
|
287
322
|
required init?(coder: NSCoder) { nil }
|
|
@@ -35,8 +35,6 @@ struct DuoBarCompression {
|
|
|
35
35
|
static let defaultToolbarHeight = DuoMetrics.controlSize + Spacing.M + 2 * DuoMetrics.itemPitch
|
|
36
36
|
/// Back, then the single button the toolbar folds into.
|
|
37
37
|
private static let compressedToolbarHeight = 2 * DuoMetrics.controlSize + Spacing.M
|
|
38
|
-
/// Back alone, while a rail opened from the compressed state takes the toolbar slot.
|
|
39
|
-
private static let backOnlyHeight = DuoMetrics.controlSize
|
|
40
38
|
|
|
41
39
|
/// - both fit: both stay whole
|
|
42
40
|
/// - one fits whole beside the other compressed: one is compressed, tapping it swaps them
|
|
@@ -72,7 +70,8 @@ struct DuoBarCompression {
|
|
|
72
70
|
|
|
73
71
|
let expandToolbar = { opened.wrappedValue = .toolbar }
|
|
74
72
|
let expandTabBar = { opened.wrappedValue = .tabBar }
|
|
75
|
-
|
|
73
|
+
// an opened rail always shows, even when only the group gap is short: it closes once a tab is picked
|
|
74
|
+
if opened.wrappedValue == .tabBar {
|
|
76
75
|
return DuoBarCompression(
|
|
77
76
|
toolbarCompressed: true,
|
|
78
77
|
tabBarCompressed: false,
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// MoMoUIKits
|
|
4
4
|
//
|
|
5
5
|
// iPhone Duo tab bar, port of RN `BottomTab/DuoTabBar.tsx` (Figma Fold-Design-System MT1/MT2):
|
|
6
|
-
// a
|
|
6
|
+
// a rail in the side bar, or a floating bar when unfolded portrait.
|
|
7
7
|
//
|
|
8
8
|
|
|
9
9
|
import SwiftUI
|
|
@@ -16,12 +16,15 @@ private let railGap = Spacing.XXS
|
|
|
16
16
|
// selection bubble overflows the 48 rail cell by 5 above and below (Figma MT2)
|
|
17
17
|
private let railBubbleWidth: CGFloat = 44
|
|
18
18
|
private let railBubbleHeight: CGFloat = 58
|
|
19
|
-
let
|
|
19
|
+
private let floatingHeight = DuoMetrics.floatingTabBarHeight
|
|
20
20
|
private let floatingPadding = Spacing.XS
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
private let
|
|
21
|
+
// the system bar sizes its pill to the tabs instead of stretching it across the display
|
|
22
|
+
private let floatingItemWidth: CGFloat = 80
|
|
23
|
+
// while pressed the selection bubble grows into a lens past the pill's edges
|
|
24
|
+
private let lensScaleX: CGFloat = 1.2
|
|
25
|
+
private let lensScaleY: CGFloat = 1.3
|
|
26
|
+
// Figma Home-2026 tab bar "Selection": brand pink at 8%
|
|
27
|
+
private let selectionTintOpacity: Double = 0x14 / 255
|
|
25
28
|
private let tabSpring = Animation.interpolatingSpring(mass: 0.8, stiffness: 220, damping: 18)
|
|
26
29
|
|
|
27
30
|
/// Room tab screens leave for the Duo tab bar, provided by BottomTab to its tab StackScreens.
|
|
@@ -51,47 +54,34 @@ func duoRailHeight(itemCount: Int, hasQr: Bool, compressed: Bool = false) -> CGF
|
|
|
51
54
|
}
|
|
52
55
|
|
|
53
56
|
extension ScreenLayout {
|
|
57
|
+
/// Overlaps the home indicator inset like the system tab bar (21pt above the bottom with a 34pt inset).
|
|
58
|
+
var duoFloatingTabBarBottom: CGFloat {
|
|
59
|
+
max(insets.bottom - DuoMetrics.floatingTabBarInsetOverlap, Spacing.S)
|
|
60
|
+
}
|
|
61
|
+
|
|
54
62
|
func duoTabBarInsets(itemCount: Int, hasFloatingButton: Bool, tabBarCompressed: Bool = false) -> DuoTabBarInsets {
|
|
55
63
|
guard isIPhoneDuo else { return DuoTabBarInsets() }
|
|
56
64
|
guard let sideBar else {
|
|
57
|
-
|
|
65
|
+
// overlay is measured from the bottom safe area, the bar reaches into it
|
|
66
|
+
return DuoTabBarInsets(overlay: floatingHeight + duoFloatingTabBarBottom - insets.bottom)
|
|
58
67
|
}
|
|
59
68
|
let rail = duoRailHeight(itemCount: itemCount, hasQr: hasFloatingButton, compressed: tabBarCompressed)
|
|
60
69
|
return DuoTabBarInsets(sideBarReserve: sideBar.bottom + rail + DuoBarCompression.groupGap)
|
|
61
70
|
}
|
|
62
71
|
}
|
|
63
72
|
|
|
64
|
-
///
|
|
65
|
-
struct DuoBarMaterial<S:
|
|
73
|
+
/// RN `BarMaterial`: surface with a 1pt border.
|
|
74
|
+
struct DuoBarMaterial<S: InsettableShape>: ViewModifier {
|
|
66
75
|
let shape: S
|
|
67
|
-
var visible: Bool = true
|
|
68
|
-
|
|
69
|
-
func body(content: Content) -> some View {
|
|
70
|
-
content.background(material.allowsHitTesting(false))
|
|
71
|
-
}
|
|
72
76
|
|
|
73
|
-
@
|
|
74
|
-
private var material: some View {
|
|
75
|
-
#if compiler(>=6.2)
|
|
76
|
-
if #available(iOS 26.0, *) {
|
|
77
|
-
// glass materializes by toggling its effect, it does not fade with opacity
|
|
78
|
-
Color.clear
|
|
79
|
-
.glassEffect(visible ? .regular : .identity, in: shape)
|
|
80
|
-
.shadow(color: Color.black.opacity(visible ? 0.16 : 0), radius: 16, x: 0, y: 6)
|
|
81
|
-
.animation(.easeInOut(duration: 0.25), value: visible)
|
|
82
|
-
} else {
|
|
83
|
-
blur
|
|
84
|
-
}
|
|
85
|
-
#else
|
|
86
|
-
blur
|
|
87
|
-
#endif
|
|
88
|
-
}
|
|
77
|
+
@Environment(\.appTheme) private var theme
|
|
89
78
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
.
|
|
93
|
-
|
|
94
|
-
|
|
79
|
+
func body(content: Content) -> some View {
|
|
80
|
+
content.background(
|
|
81
|
+
shape.fill(theme.colors.background.surface)
|
|
82
|
+
.overlay(shape.strokeBorder(theme.colors.border.default, lineWidth: 1))
|
|
83
|
+
.allowsHitTesting(false)
|
|
84
|
+
)
|
|
95
85
|
}
|
|
96
86
|
}
|
|
97
87
|
|
|
@@ -126,7 +116,7 @@ private struct DuoRailTabBar: View {
|
|
|
126
116
|
let onTabSelected: (Int) -> Void
|
|
127
117
|
let compression: DuoBarCompression
|
|
128
118
|
|
|
129
|
-
@
|
|
119
|
+
@State private var pressedIndex: Int?
|
|
130
120
|
|
|
131
121
|
private var isRight: Bool { sideBar.edge == .right }
|
|
132
122
|
|
|
@@ -157,15 +147,15 @@ private struct DuoRailTabBar: View {
|
|
|
157
147
|
.ignoresSafeArea()
|
|
158
148
|
}
|
|
159
149
|
|
|
160
|
-
///
|
|
150
|
+
/// Column of icon-only tab items with the sliding selection bubble.
|
|
161
151
|
private var rail: some View {
|
|
162
152
|
ZStack(alignment: .top) {
|
|
163
|
-
|
|
164
|
-
.fill(theme.colors.background.selected)
|
|
153
|
+
DuoSelectionMaterial(lens: pressedIndex != nil)
|
|
165
154
|
.frame(width: railBubbleWidth, height: railBubbleHeight)
|
|
166
155
|
.offset(y: railPadding - (railBubbleHeight - itemSize) / 2
|
|
167
|
-
+ CGFloat(selectedIndex) * (itemSize + railGap))
|
|
156
|
+
+ CGFloat(pressedIndex ?? selectedIndex) * (itemSize + railGap))
|
|
168
157
|
.animation(tabSpring, value: selectedIndex)
|
|
158
|
+
.animation(tabSpring, value: pressedIndex)
|
|
169
159
|
|
|
170
160
|
VStack(spacing: railGap) {
|
|
171
161
|
ForEach(items.indices, id: \.self) { index in
|
|
@@ -177,19 +167,19 @@ private struct DuoRailTabBar: View {
|
|
|
177
167
|
.frame(width: itemSize, height: itemSize)
|
|
178
168
|
.contentShape(Rectangle())
|
|
179
169
|
}
|
|
180
|
-
.buttonStyle(
|
|
170
|
+
.buttonStyle(DuoLensPressStyle(index: index, pressedIndex: $pressedIndex))
|
|
181
171
|
.accessibilityLabel(items[index].label)
|
|
182
172
|
}
|
|
183
173
|
}
|
|
184
174
|
.padding(.vertical, railPadding)
|
|
185
175
|
}
|
|
186
176
|
.frame(width: itemSize)
|
|
187
|
-
.modifier(DuoBarMaterial(shape:
|
|
177
|
+
.modifier(DuoBarMaterial(shape: Capsule()))
|
|
188
178
|
.accessibilityIdentifier("bottom_tab_bar")
|
|
189
179
|
}
|
|
190
180
|
}
|
|
191
181
|
|
|
192
|
-
/// Floating labelled bar for the unfolded portrait display, QR in
|
|
182
|
+
/// Floating labelled bar for the unfolded portrait display, QR pinned in its own platter beside it.
|
|
193
183
|
private struct DuoFloatingTabBar: View {
|
|
194
184
|
let items: [BottomTabItem]
|
|
195
185
|
let floatingButton: BottomTabFloatingButton?
|
|
@@ -198,45 +188,48 @@ private struct DuoFloatingTabBar: View {
|
|
|
198
188
|
|
|
199
189
|
@Environment(\.screenLayout) private var layout
|
|
200
190
|
@Environment(\.appTheme) private var theme
|
|
191
|
+
@State private var pressedIndex: Int?
|
|
201
192
|
|
|
202
193
|
private var barWidth: CGFloat {
|
|
203
|
-
let
|
|
204
|
-
|
|
194
|
+
let margins = layout.insets.leading + layout.insets.trailing + 2 * DuoMetrics.floatingTabBarMargin
|
|
195
|
+
let qr = floatingButton == nil ? 0 : floatingHeight + Spacing.S
|
|
196
|
+
let preferred = CGFloat(items.count) * floatingItemWidth + 2 * floatingPadding
|
|
197
|
+
return max(min(preferred, layout.width - margins - qr), 0)
|
|
205
198
|
}
|
|
206
199
|
|
|
207
|
-
private var
|
|
208
|
-
private var middle: Int { items.count / 2 }
|
|
209
|
-
private var cellCount: Int { items.count + (useQr ? 1 : 0) }
|
|
210
|
-
private var cellWidth: CGFloat { (barWidth - floatingPadding * 2) / CGFloat(max(cellCount, 1)) }
|
|
211
|
-
private var visualIndex: Int { useQr && selectedIndex >= middle ? selectedIndex + 1 : selectedIndex }
|
|
200
|
+
private var cellWidth: CGFloat { (barWidth - floatingPadding * 2) / CGFloat(max(items.count, 1)) }
|
|
212
201
|
|
|
213
202
|
var body: some View {
|
|
203
|
+
HStack(spacing: Spacing.S) {
|
|
204
|
+
bar
|
|
205
|
+
if let floatingButton {
|
|
206
|
+
DuoQrButton(data: floatingButton, size: floatingHeight)
|
|
207
|
+
.shadow(color: Color.black.opacity(0.16), radius: 16, x: 0, y: 6)
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
.padding(.bottom, layout.duoFloatingTabBarBottom)
|
|
211
|
+
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottom)
|
|
212
|
+
.ignoresSafeArea()
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
private var bar: some View {
|
|
214
216
|
ZStack(alignment: .leading) {
|
|
215
|
-
|
|
216
|
-
.fill(theme.colors.background.selected)
|
|
217
|
+
DuoSelectionMaterial(lens: pressedIndex != nil)
|
|
217
218
|
.frame(width: cellWidth)
|
|
218
|
-
.offset(x: CGFloat(
|
|
219
|
-
.animation(tabSpring, value:
|
|
219
|
+
.offset(x: CGFloat(pressedIndex ?? selectedIndex) * cellWidth)
|
|
220
|
+
.animation(tabSpring, value: selectedIndex)
|
|
221
|
+
.animation(tabSpring, value: pressedIndex)
|
|
220
222
|
|
|
221
223
|
HStack(spacing: 0) {
|
|
222
|
-
ForEach(
|
|
223
|
-
|
|
224
|
-
DuoQrButton(data: floatingButton, size: floatingQrSize)
|
|
225
|
-
.frame(width: cellWidth)
|
|
226
|
-
} else {
|
|
227
|
-
let index = useQr && cell > middle ? cell - 1 : cell
|
|
228
|
-
tabCell(index)
|
|
229
|
-
}
|
|
224
|
+
ForEach(items.indices, id: \.self) { index in
|
|
225
|
+
tabCell(index)
|
|
230
226
|
}
|
|
231
227
|
}
|
|
232
228
|
}
|
|
233
229
|
.padding(floatingPadding)
|
|
234
|
-
.frame(width: barWidth, height:
|
|
230
|
+
.frame(width: barWidth, height: floatingHeight)
|
|
235
231
|
.modifier(DuoBarMaterial(shape: Capsule()))
|
|
236
232
|
.accessibilityIdentifier("bottom_tab_bar")
|
|
237
|
-
.padding(.bottom, layout.insets.bottom + Spacing.M)
|
|
238
|
-
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottom)
|
|
239
|
-
.ignoresSafeArea()
|
|
240
233
|
}
|
|
241
234
|
|
|
242
235
|
private func tabCell(_ index: Int) -> some View {
|
|
@@ -247,20 +240,52 @@ private struct DuoFloatingTabBar: View {
|
|
|
247
240
|
MomoText(
|
|
248
241
|
items[index].label,
|
|
249
242
|
typography: .labelXsMedium,
|
|
250
|
-
color: selected ? theme.colors.primary : theme.colors.text.
|
|
243
|
+
color: selected ? theme.colors.primary : theme.colors.text.hint,
|
|
251
244
|
textAlign: .center,
|
|
252
245
|
maxLines: 1
|
|
253
246
|
)
|
|
247
|
+
// like the system tab bar the label keeps its design size; a constant snapshot, nothing to observe
|
|
248
|
+
.environment(\.momoFontScale, FontScale(userScaleRate: 1, useOSScaleRate: false))
|
|
254
249
|
}
|
|
255
250
|
.frame(width: cellWidth)
|
|
256
251
|
.frame(maxHeight: .infinity)
|
|
257
252
|
.contentShape(Rectangle())
|
|
258
253
|
}
|
|
259
|
-
.buttonStyle(
|
|
254
|
+
.buttonStyle(DuoLensPressStyle(index: index, pressedIndex: $pressedIndex))
|
|
260
255
|
.accessibilityLabel(items[index].label)
|
|
261
256
|
}
|
|
262
257
|
}
|
|
263
258
|
|
|
259
|
+
/// Pink tinted capsule under the selected tab; while pressed it grows into a lens (80x54 to about 96x70).
|
|
260
|
+
private struct DuoSelectionMaterial: View {
|
|
261
|
+
let lens: Bool
|
|
262
|
+
|
|
263
|
+
@Environment(\.appTheme) private var theme
|
|
264
|
+
|
|
265
|
+
var body: some View {
|
|
266
|
+
Capsule()
|
|
267
|
+
.fill(theme.colors.primary.opacity(selectionTintOpacity))
|
|
268
|
+
.scaleEffect(x: lens ? lensScaleX : 1, y: lens ? lensScaleY : 1)
|
|
269
|
+
.allowsHitTesting(false)
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/// Tracks the finger so the selection lens jumps to the pressed tab before it is selected.
|
|
274
|
+
private struct DuoLensPressStyle: ButtonStyle {
|
|
275
|
+
let index: Int
|
|
276
|
+
@Binding var pressedIndex: Int?
|
|
277
|
+
|
|
278
|
+
func makeBody(configuration: Configuration) -> some View {
|
|
279
|
+
configuration.label.onChange(of: configuration.isPressed) { pressed in
|
|
280
|
+
if pressed {
|
|
281
|
+
pressedIndex = index
|
|
282
|
+
} else if pressedIndex == index {
|
|
283
|
+
pressedIndex = nil
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
264
289
|
private struct DuoTabIcon: View {
|
|
265
290
|
let item: BottomTabItem
|
|
266
291
|
let selected: Bool
|
|
@@ -274,7 +299,7 @@ private struct DuoTabIcon: View {
|
|
|
274
299
|
}
|
|
275
300
|
|
|
276
301
|
var body: some View {
|
|
277
|
-
Icon(source: item.icon, size: iconSize, color: selected ? theme.colors.primary : theme.colors.text.
|
|
302
|
+
Icon(source: item.icon, size: iconSize, color: selected ? theme.colors.primary : theme.colors.text.hint)
|
|
278
303
|
.overlay(alignment: .topTrailing) {
|
|
279
304
|
if let badgeLabel, !badgeLabel.isEmpty {
|
|
280
305
|
Badge(label: badgeLabel).offset(x: Spacing.S, y: -Spacing.XS)
|
|
@@ -90,6 +90,27 @@ private let duoGradientExtra: CGFloat = 52
|
|
|
90
90
|
// scroll distance over which the extended gradient collapses to the header
|
|
91
91
|
private let duoExtendedCollapseDistance: CGFloat = 100
|
|
92
92
|
|
|
93
|
+
// scroll distance over which the bar fades in
|
|
94
|
+
private let duoBarFadeDistance: CGFloat = 16
|
|
95
|
+
|
|
96
|
+
/// Port of RN `DuoGlassBackground`: translucent surface with a hairline, shown once the content
|
|
97
|
+
/// scrolls `fadeStart` under the header.
|
|
98
|
+
struct DuoHeaderBar: View {
|
|
99
|
+
let scrollOffset: CGFloat
|
|
100
|
+
var fadeStart: CGFloat = 0
|
|
101
|
+
|
|
102
|
+
@Environment(\.appTheme) private var theme
|
|
103
|
+
|
|
104
|
+
var body: some View {
|
|
105
|
+
theme.colors.background.surface.opacity(0.8)
|
|
106
|
+
.overlay(alignment: .bottom) {
|
|
107
|
+
theme.colors.border.default.frame(height: 0.5)
|
|
108
|
+
}
|
|
109
|
+
.opacity(min(max((scrollOffset - fadeStart) / duoBarFadeDistance, 0), 1))
|
|
110
|
+
.allowsHitTesting(false)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
93
114
|
/// Port of RN `DuoScrollGradient`: with the glass header the content scrolls under the bar, so the
|
|
94
115
|
/// header gradient is drawn under it. Compose draws this inside `HeaderBackground`.
|
|
95
116
|
struct DuoScrollGradient: View {
|
|
@@ -114,7 +135,7 @@ struct DuoScrollGradient: View {
|
|
|
114
135
|
let progress = min(scroll / duoExtendedCollapseDistance, 1)
|
|
115
136
|
gradient
|
|
116
137
|
.frame(height: headerHeight + (extended ? duoGradientExtra * (1 - progress) : 0))
|
|
117
|
-
.opacity(1 - min(scroll / duoGradientExtra, 1))
|
|
138
|
+
.opacity(Double(1 - min(scroll / duoGradientExtra, 1)))
|
|
118
139
|
}
|
|
119
140
|
}
|
|
120
141
|
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
|
|
@@ -403,11 +403,8 @@ public struct StackScreen<Content: View>: View {
|
|
|
403
403
|
.background(alignment: .top) {
|
|
404
404
|
Group {
|
|
405
405
|
if layout.sideBar != nil {
|
|
406
|
-
//
|
|
407
|
-
|
|
408
|
-
shape: Rectangle(),
|
|
409
|
-
visible: scrollOffset > heroGlassStart(animatedHeader)
|
|
410
|
-
))
|
|
406
|
+
// the bar shows once the banner has scrolled under the header
|
|
407
|
+
DuoHeaderBar(scrollOffset: scrollOffset, fadeStart: heroGlassStart(animatedHeader))
|
|
411
408
|
} else {
|
|
412
409
|
HeaderBarBackground(opacity: opacity)
|
|
413
410
|
}
|
|
@@ -457,8 +454,7 @@ public struct StackScreen<Content: View>: View {
|
|
|
457
454
|
|
|
458
455
|
header
|
|
459
456
|
.background(
|
|
460
|
-
|
|
461
|
-
.modifier(DuoBarMaterial(shape: Rectangle(), visible: scrollOffset > 0))
|
|
457
|
+
DuoHeaderBar(scrollOffset: scrollOffset)
|
|
462
458
|
.edgesIgnoringSafeArea([.top, .horizontal])
|
|
463
459
|
)
|
|
464
460
|
.offset(y: -headerHide)
|
|
@@ -5,8 +5,6 @@ import SwiftUI
|
|
|
5
5
|
private let duoPopupMaxWidth: CGFloat = 440
|
|
6
6
|
|
|
7
7
|
extension ScreenLayout {
|
|
8
|
-
var isDuoDevice: Bool { isIPhoneDuoDevice(windowSize: CGSize(width: width, height: height)) }
|
|
9
|
-
|
|
10
8
|
/// Card width cap (Compose `popupMaxWidth`); unbounded off iPhone Duo, where the popup's own padding sets the width.
|
|
11
9
|
var popupMaxWidth: CGFloat {
|
|
12
10
|
isDuoDevice ? duoPopupMaxWidth : .infinity
|
|
@@ -84,7 +84,6 @@ private struct StepperButton: View {
|
|
|
84
84
|
|
|
85
85
|
private struct StepperNumberView: View {
|
|
86
86
|
@Environment(\.appTheme) private var theme
|
|
87
|
-
@Environment(\.momoFontScale) private var fontScale
|
|
88
87
|
|
|
89
88
|
@Binding var text: String
|
|
90
89
|
var size: StepperSize
|
|
@@ -106,7 +105,7 @@ private struct StepperNumberView: View {
|
|
|
106
105
|
MomoText(text, typography: .descriptionDefaultRegular, color: textColor)
|
|
107
106
|
}
|
|
108
107
|
}
|
|
109
|
-
.
|
|
108
|
+
.kitFont(size: 12)
|
|
110
109
|
.ignoreBoldTextSetting()
|
|
111
110
|
.foregroundColor(textColor)
|
|
112
111
|
// Compose's min width includes the horizontal padding.
|
|
@@ -11,7 +11,7 @@ import SDWebImageSwiftUI
|
|
|
11
11
|
|
|
12
12
|
let jsonUrl = "https://static.momocdn.net/app/json/component-kits/design_system.json"
|
|
13
13
|
|
|
14
|
-
public struct TrustBannerData: Decodable {
|
|
14
|
+
public struct TrustBannerData: Decodable, Equatable {
|
|
15
15
|
public let content: [String: String]
|
|
16
16
|
public let subContent: [String: String]
|
|
17
17
|
public let pciImage: String?
|
|
@@ -85,6 +85,7 @@ let defaultBanner = TrustBannerData(
|
|
|
85
85
|
public struct TrustBanner: View {
|
|
86
86
|
@Environment(\.applicationEnvironment) var applicationEnvironment
|
|
87
87
|
@Environment(\.localize) private var localize
|
|
88
|
+
@Environment(\.designSystemKitsConfigs) private var designSystemKitsConfigs
|
|
88
89
|
|
|
89
90
|
var onPress: ((String)->Void)?
|
|
90
91
|
private let serviceName: String
|
|
@@ -104,7 +105,8 @@ public struct TrustBanner: View {
|
|
|
104
105
|
}
|
|
105
106
|
|
|
106
107
|
private var banner: TrustBannerData {
|
|
107
|
-
|
|
108
|
+
// Container config wins, else the host-pushed DesignSystemKits config (Compose parity).
|
|
109
|
+
(applicationEnvironment.config ?? designSystemKitsConfigs.designSystemConfig)?.trustBanner ?? defaultBanner
|
|
108
110
|
}
|
|
109
111
|
|
|
110
112
|
func onPressSecurity() {
|
|
@@ -52,7 +52,7 @@ public struct FontScale: Equatable {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
/// A host-pushed mini-app context wins per field, matching Compose's
|
|
55
|
-
/// `context?.useOSScaleRate ?:
|
|
55
|
+
/// `context?.useOSScaleRate ?: DesignSystemKits.getConfigs().useOSScaleRate`.
|
|
56
56
|
public func overriding(userScaleRate: CGFloat?, useOSScaleRate: Bool?) -> FontScale {
|
|
57
57
|
guard userScaleRate != nil || useOSScaleRate != nil else { return self }
|
|
58
58
|
return FontScale(
|
|
@@ -66,7 +66,7 @@ public struct FontScale: Equatable {
|
|
|
66
66
|
private struct FontScaleKey: EnvironmentKey {
|
|
67
67
|
/// Computed, never stored: a bare `UIHostingController` root that never got `.momoFontScale()`
|
|
68
68
|
/// still reads the live store instead of a value frozen at first access.
|
|
69
|
-
static var defaultValue: FontScale {
|
|
69
|
+
static var defaultValue: FontScale { DesignSystemKits.shared.fontScale }
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
public extension EnvironmentValues {
|
|
@@ -77,9 +77,10 @@ public extension EnvironmentValues {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
public extension View {
|
|
80
|
-
/// Injects a Dynamic-Type-observing font scale
|
|
80
|
+
/// Injects a Dynamic-Type-observing font scale plus `\.designSystemKitsConfigs` (whitelist, remote config)
|
|
81
|
+
/// and re-renders this subtree on change.
|
|
81
82
|
/// Use at every `UIHostingController` root that is not inside a `NavigationContainer`.
|
|
82
|
-
func momoFontScale(_ store:
|
|
83
|
+
func momoFontScale(_ store: DesignSystemKits = .shared, context: MiniAppContext? = nil) -> some View {
|
|
83
84
|
modifier(MomoFontScaleModifier(store: store, context: context))
|
|
84
85
|
}
|
|
85
86
|
}
|
|
@@ -87,17 +88,19 @@ public extension View {
|
|
|
87
88
|
/// `@ObservedObject` is load-bearing, same as `MomoLocalizeModifier`: `@Environment(\.momoFontScale)`
|
|
88
89
|
/// only invalidates when the boxed snapshot changes, which requires *this* body to re-run on publish.
|
|
89
90
|
private struct MomoFontScaleModifier: ViewModifier {
|
|
90
|
-
@ObservedObject var store:
|
|
91
|
+
@ObservedObject var store: DesignSystemKits
|
|
91
92
|
let context: MiniAppContext?
|
|
92
93
|
|
|
93
94
|
func body(content: Content) -> some View {
|
|
94
|
-
content
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
content
|
|
96
|
+
.environment(
|
|
97
|
+
\.momoFontScale,
|
|
98
|
+
store.fontScale.overriding(
|
|
99
|
+
userScaleRate: context?.userScaleRate,
|
|
100
|
+
useOSScaleRate: context?.useOSScaleRate
|
|
101
|
+
)
|
|
99
102
|
)
|
|
100
|
-
|
|
103
|
+
.environment(\.designSystemKitsConfigs, store.getConfigs())
|
|
101
104
|
}
|
|
102
105
|
}
|
|
103
106
|
// AI-GENERATED END: reactive font-scale snapshot injected through the environment
|
|
@@ -4,7 +4,7 @@ import SwiftUI
|
|
|
4
4
|
/// free functions). Inside a SwiftUI view prefer `@Environment(\.momoFontScale)` so the view
|
|
5
5
|
/// re-renders when Dynamic Type or the host preference changes.
|
|
6
6
|
public func scaleSize(_ size: CGFloat) -> CGFloat {
|
|
7
|
-
|
|
7
|
+
DesignSystemKits.shared.fontScale(size)
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
@available(*, deprecated, message: "Max font scale is fixed at 1.5; this override is no longer applied. Drop the second argument.")
|
|
@@ -105,10 +105,10 @@ private enum MomoFontFace {
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
/// Port of Compose `getFontFamily`; SF Pro Text is the iOS system font, so the legacy family is `.system`.
|
|
108
|
-
private func momoFontFace(family: String, weight: Font.Weight) -> MomoFontFace? {
|
|
108
|
+
private func momoFontFace(family: String, weight: Font.Weight, isWhiteList: Bool) -> MomoFontFace? {
|
|
109
109
|
let isNewFamily = family == "MomoTrustSans" || family == headerFontFamily
|
|
110
110
|
// Outside the whitelist the new DS families drop to the legacy font, as before DS-791.
|
|
111
|
-
if family == "SFProText" || (isNewFamily && !
|
|
111
|
+
if family == "SFProText" || (isNewFamily && !isWhiteList) { return .system }
|
|
112
112
|
// single-file families (Compose maps every weight to the same .otf)
|
|
113
113
|
if family == headerFontFamily || family == "MoMoSignature" { return .named(family) }
|
|
114
114
|
guard family == "MomoTrustSans" else { return nil }
|
|
@@ -127,8 +127,14 @@ private func momoFontFace(family: String, weight: Font.Weight) -> MomoFontFace?
|
|
|
127
127
|
/// Header title family (Compose `HEADER_FONT_FAMILY`), whitelist only like the default font.
|
|
128
128
|
let headerFontFamily = "MoMoTrustDisplay"
|
|
129
129
|
|
|
130
|
-
private func momoFont(
|
|
131
|
-
|
|
130
|
+
private func momoFont(
|
|
131
|
+
size: CGFloat,
|
|
132
|
+
weight: Font.Weight,
|
|
133
|
+
family: String,
|
|
134
|
+
fallbackFamily: String? = nil,
|
|
135
|
+
isWhiteList: Bool
|
|
136
|
+
) -> Font {
|
|
137
|
+
switch momoFontFace(family: family, weight: weight, isWhiteList: isWhiteList) {
|
|
132
138
|
case .system:
|
|
133
139
|
return .system(size: size, weight: weight)
|
|
134
140
|
case .named(let name) where UIFont(name: name, size: size) != nil:
|
|
@@ -136,15 +142,15 @@ private func momoFont(size: CGFloat, weight: Font.Weight, family: String, fallba
|
|
|
136
142
|
default:
|
|
137
143
|
// Compose falls back to the default font file when a family is missing
|
|
138
144
|
if let fallbackFamily, fallbackFamily != family {
|
|
139
|
-
return momoFont(size: size, weight: weight, family: fallbackFamily)
|
|
145
|
+
return momoFont(size: size, weight: weight, family: fallbackFamily, isWhiteList: isWhiteList)
|
|
140
146
|
}
|
|
141
147
|
return .system(size: size, weight: weight)
|
|
142
148
|
}
|
|
143
149
|
}
|
|
144
150
|
|
|
145
151
|
// lineHeight is identical across weights of a family, so the regular face is enough.
|
|
146
|
-
private func momoLineHeight(size: CGFloat, family: String, fallbackFamily: String? = nil) -> CGFloat {
|
|
147
|
-
switch momoFontFace(family: family, weight: .regular) {
|
|
152
|
+
private func momoLineHeight(size: CGFloat, family: String, fallbackFamily: String? = nil, isWhiteList: Bool) -> CGFloat {
|
|
153
|
+
switch momoFontFace(family: family, weight: .regular, isWhiteList: isWhiteList) {
|
|
148
154
|
case .system:
|
|
149
155
|
break
|
|
150
156
|
case .named(let name):
|
|
@@ -152,15 +158,71 @@ private func momoLineHeight(size: CGFloat, family: String, fallbackFamily: Strin
|
|
|
152
158
|
fallthrough
|
|
153
159
|
case nil:
|
|
154
160
|
if let fallbackFamily, fallbackFamily != family {
|
|
155
|
-
return momoLineHeight(size: size, family: fallbackFamily)
|
|
161
|
+
return momoLineHeight(size: size, family: fallbackFamily, isWhiteList: isWhiteList)
|
|
156
162
|
}
|
|
157
163
|
}
|
|
158
164
|
return UIFont.systemFont(ofSize: size).lineHeight
|
|
159
165
|
}
|
|
160
166
|
|
|
167
|
+
/// UIKit counterpart of `momoFont`, for text that is not a `MomoText` (UITextField/UITextView, text measuring).
|
|
168
|
+
func momoUIFont(size: CGFloat, weight: UIFont.Weight, family: String, isWhiteList: Bool) -> UIFont {
|
|
169
|
+
guard case .named(let name) = momoFontFace(family: family, weight: Font.Weight(weight), isWhiteList: isWhiteList),
|
|
170
|
+
let font = UIFont(name: name, size: size) else {
|
|
171
|
+
return .systemFont(ofSize: size, weight: weight)
|
|
172
|
+
}
|
|
173
|
+
return font
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
private extension Font.Weight {
|
|
177
|
+
init(_ weight: UIFont.Weight) {
|
|
178
|
+
switch weight {
|
|
179
|
+
case .ultraLight: self = .ultraLight
|
|
180
|
+
case .thin: self = .thin
|
|
181
|
+
case .light: self = .light
|
|
182
|
+
case .medium: self = .medium
|
|
183
|
+
case .semibold: self = .semibold
|
|
184
|
+
case .bold: self = .bold
|
|
185
|
+
case .heavy: self = .heavy
|
|
186
|
+
case .black: self = .black
|
|
187
|
+
default: self = .regular
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/// Gives input text the same family as `MomoText` (Compose's `getFontFamily`), e.g. a TextField
|
|
193
|
+
/// next to a `MomoText` placeholder. `size` is unscaled; the environment font scale is applied here.
|
|
194
|
+
private struct KitFontModifier: ViewModifier {
|
|
195
|
+
@Environment(\.appTheme) private var theme
|
|
196
|
+
@Environment(\.momoFontScale) private var fontScale
|
|
197
|
+
@Environment(\.designSystemKitsConfigs) private var designSystemKitsConfigs
|
|
198
|
+
let size: CGFloat
|
|
199
|
+
let weight: Font.Weight
|
|
200
|
+
|
|
201
|
+
func body(content: Content) -> some View {
|
|
202
|
+
content.font(momoFont(
|
|
203
|
+
size: fontScale(size),
|
|
204
|
+
weight: weight,
|
|
205
|
+
family: theme.font,
|
|
206
|
+
isWhiteList: designSystemKitsConfigs.isWhiteList
|
|
207
|
+
))
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
extension View {
|
|
212
|
+
func kitFont(_ typography: TypographyStyle) -> some View {
|
|
213
|
+
modifier(KitFontModifier(size: typography.fontSize, weight: typography.fontWeight))
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
func kitFont(size: CGFloat, weight: Font.Weight = .regular) -> some View {
|
|
217
|
+
modifier(KitFontModifier(size: size, weight: weight))
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
161
221
|
public struct MomoText: View {
|
|
162
222
|
@Environment(\.appTheme) private var theme
|
|
163
223
|
@Environment(\.momoFontScale) private var fontScale
|
|
224
|
+
// From the environment, not DesignSystemKits.shared, so a whitelist flip re-renders the text.
|
|
225
|
+
@Environment(\.designSystemKitsConfigs) private var designSystemKitsConfigs
|
|
164
226
|
private let content: String
|
|
165
227
|
private let typography: TypographyStyle
|
|
166
228
|
private let color: Color?
|
|
@@ -236,7 +298,8 @@ public struct MomoText: View {
|
|
|
236
298
|
size: fontScale(fontSize),
|
|
237
299
|
weight: typography.fontWeight,
|
|
238
300
|
family: fontFamily ?? theme.font,
|
|
239
|
-
fallbackFamily: theme.font
|
|
301
|
+
fallbackFamily: theme.font,
|
|
302
|
+
isWhiteList: designSystemKitsConfigs.isWhiteList
|
|
240
303
|
)
|
|
241
304
|
}
|
|
242
305
|
|
|
@@ -244,7 +307,13 @@ public struct MomoText: View {
|
|
|
244
307
|
private var baseText: SwiftUI.Text {
|
|
245
308
|
let keywords = highlightText.filter { !$0.isEmpty }.sorted { $0.count > $1.count }
|
|
246
309
|
guard !keywords.isEmpty else { return SwiftUI.Text(content) }
|
|
247
|
-
let highlightFont = momoFont(
|
|
310
|
+
let highlightFont = momoFont(
|
|
311
|
+
size: fontScale(fontSize),
|
|
312
|
+
weight: TypographyStyle.headerXsSemibold.fontWeight,
|
|
313
|
+
family: fontFamily ?? theme.font,
|
|
314
|
+
fallbackFamily: theme.font,
|
|
315
|
+
isWhiteList: designSystemKitsConfigs.isWhiteList
|
|
316
|
+
)
|
|
248
317
|
func isWordChar(_ character: Character?) -> Bool {
|
|
249
318
|
guard let character else { return false }
|
|
250
319
|
return character.isLetter || character.isNumber || character == "_"
|
|
@@ -282,7 +351,12 @@ public struct MomoText: View {
|
|
|
282
351
|
|
|
283
352
|
// lineSpacing is added on top of the font's natural line height, not on top of fontSize.
|
|
284
353
|
let lineSpacing = max(0, fontScale(lineHeight)
|
|
285
|
-
- momoLineHeight(
|
|
354
|
+
- momoLineHeight(
|
|
355
|
+
size: fontScale(fontSize),
|
|
356
|
+
family: fontFamily ?? theme.font,
|
|
357
|
+
fallbackFamily: theme.font,
|
|
358
|
+
isWhiteList: designSystemKitsConfigs.isWhiteList
|
|
359
|
+
))
|
|
286
360
|
|
|
287
361
|
var text = baseText
|
|
288
362
|
.font(font)
|
|
@@ -10,12 +10,12 @@ public extension View {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
public extension Font {
|
|
13
|
-
/// Non-reactive: resolves against the current `
|
|
13
|
+
/// Non-reactive: resolves against the current `DesignSystemKits` font scale at each access. The
|
|
14
14
|
/// styles below are computed properties for that reason — as stored `static let`s they would
|
|
15
15
|
/// freeze the scale at first access and never pick up a Dynamic Type change.
|
|
16
16
|
/// Inside a view, `@Environment(\.momoFontScale)` + `fontScale.font(size:weight:)` also re-renders.
|
|
17
17
|
static func appFont(size: CGFloat) -> Font {
|
|
18
|
-
|
|
18
|
+
DesignSystemKits.shared.fontScale.font(size: size)
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
// New supported typography styles
|
package/ios/native-kits.podspec
CHANGED
package/package.json
CHANGED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import SwiftUI
|
|
2
|
-
|
|
3
|
-
/// App-wide font-scale inputs for the SwiftUI kit, and the single place they publish from.
|
|
4
|
-
/// The host writes `update(...)` at startup (from the cache-backed `FontScaleProvider`) and again
|
|
5
|
-
/// whenever the in-app font-size preference changes; the OS Dynamic Type factor is tracked here.
|
|
6
|
-
/// Mirrors Compose's `KitFontScale` + `ProvideOsFontScale` pair, including its live behaviour —
|
|
7
|
-
/// views re-render on change as long as the subtree got `.momoFontScale()` (`NavigationContainer`
|
|
8
|
-
/// applies it). When `useOSScaleRate` is false the kit applies `userScaleRate` instead of the OS factor.
|
|
9
|
-
public final class FontScaleStore: ObservableObject {
|
|
10
|
-
public static let shared = FontScaleStore()
|
|
11
|
-
|
|
12
|
-
@Published public private(set) var userScaleRate: CGFloat = 1
|
|
13
|
-
@Published public private(set) var useOSScaleRate: Bool = true
|
|
14
|
-
@Published public private(set) var osFontScale: CGFloat = FontScaleStore.currentOsFontScale()
|
|
15
|
-
|
|
16
|
-
private init() {
|
|
17
|
-
NotificationCenter.default.addObserver(
|
|
18
|
-
self,
|
|
19
|
-
selector: #selector(contentSizeCategoryDidChange),
|
|
20
|
-
name: UIContentSizeCategory.didChangeNotification,
|
|
21
|
-
object: nil
|
|
22
|
-
)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public var snapshot: FontScale {
|
|
26
|
-
FontScale(
|
|
27
|
-
userScaleRate: userScaleRate,
|
|
28
|
-
useOSScaleRate: useOSScaleRate,
|
|
29
|
-
osFontScale: osFontScale
|
|
30
|
-
)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
public func update(userScaleRate: CGFloat, useOSScaleRate: Bool) {
|
|
34
|
-
onMain {
|
|
35
|
-
// Re-assigning an unchanged value would still publish and invalidate every kit subtree.
|
|
36
|
-
if self.userScaleRate != userScaleRate { self.userScaleRate = userScaleRate }
|
|
37
|
-
if self.useOSScaleRate != useOSScaleRate { self.useOSScaleRate = useOSScaleRate }
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
@objc private func contentSizeCategoryDidChange() {
|
|
42
|
-
let next = Self.currentOsFontScale()
|
|
43
|
-
guard next != osFontScale else { return }
|
|
44
|
-
osFontScale = next
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/// Same factor Compose's iOS `ProvideOsFontScale` derives from
|
|
48
|
-
/// `UIFont.preferredFont(forTextStyle: .body).pointSize / 17`, so both iOS surfaces scale alike.
|
|
49
|
-
static func currentOsFontScale() -> CGFloat {
|
|
50
|
-
let base = UIFont.systemFont(ofSize: UIFont.labelFontSize)
|
|
51
|
-
return UIFontMetrics.default.scaledFont(for: base).pointSize / base.pointSize
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/// Synchronous when already on main — an async hop would defer the change by a frame.
|
|
55
|
-
private func onMain(_ work: @escaping () -> Void) {
|
|
56
|
-
if Thread.isMainThread { work() } else { DispatchQueue.main.async(execute: work) }
|
|
57
|
-
}
|
|
58
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import Foundation
|
|
2
|
-
|
|
3
|
-
/// Design-system rollout flag for the SwiftUI kit, mirroring Compose's `KitDesignSystem`.
|
|
4
|
-
/// The kit is sandboxed and can't read the host config, so the host writes `update(_:)` once at
|
|
5
|
-
/// startup from `DesignSystemConfig`. Startup-only and non-reactive, like `FontScaleStore` was
|
|
6
|
-
/// before it gained live updates: there is no SwiftUI navigation container to re-render from.
|
|
7
|
-
public final class KitDesignSystem {
|
|
8
|
-
public static let shared = KitDesignSystem()
|
|
9
|
-
|
|
10
|
-
public private(set) var isWhiteList: Bool = false
|
|
11
|
-
|
|
12
|
-
private init() {}
|
|
13
|
-
|
|
14
|
-
public func update(isWhiteList: Bool) {
|
|
15
|
-
self.isWhiteList = isWhiteList
|
|
16
|
-
}
|
|
17
|
-
}
|