@momo-kits/native-kits 0.169.7 → 0.169.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.
- package/CLAUDE.md +2 -1
- package/ios/Application/ApplicationEnvironment.swift +4 -1
- package/ios/Navigation/BottomTab/BottomTab.swift +19 -16
- package/ios/Navigation/BottomTab/BottomTabBar.swift +19 -33
- package/ios/Navigation/BottomTab/DuoTabBar.swift +3 -4
- package/ios/Navigation/BottomTab/TabBarMetrics.swift +3 -0
- package/ios/Typography/FontScale.swift +44 -8
- package/ios/native-kits.podspec +1 -1
- package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +13 -1
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/TypographyDemo.swift +16 -0
- package/package.json +1 -1
package/CLAUDE.md
CHANGED
|
@@ -107,12 +107,13 @@ The SwiftUI port differs from Compose in one important way: **it follows the hos
|
|
|
107
107
|
|
|
108
108
|
## Font scale (`scaleSize`)
|
|
109
109
|
|
|
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`.
|
|
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.
|
|
111
111
|
|
|
112
112
|
- **Compose** — `const/Typography.kt` (`scaleSize` overloads for `Float`/`Dp`/`TextUnit`/`TextStyle`). The `TextUnit` overload divides by `density.fontScale` so Compose's own `sp` scaling isn't applied twice. Inputs: `LocalContext.current` (`MiniAppContext.userScaleRate` / `useOSScaleRate`, per-field) falling back to `DesignSystemKits.getConfigs()`. On iOS, `platform/OsFontScale.ios.kt` observes `UIContentSizeCategoryDidChangeNotification` and overrides `LocalDensity` — Compose MP otherwise reads `fontScale` once at `ComposeUIViewController` creation. Wired at `NavigationContainer`.
|
|
113
113
|
- **SwiftUI** — `ios/Typography/FontScale.swift`. `FontScale` is an immutable snapshot with `callAsFunction`, so a view reads `@Environment(\.momoFontScale) private var fontScale` and calls `fontScale(16)`. `DesignSystemKits.shared` is the `ObservableObject` holding the host inputs and the OS factor (it observes `UIContentSizeCategory.didChangeNotification`); the host pushes them with `setConfigs(_:)`.
|
|
114
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.
|
|
115
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.
|
|
116
117
|
|
|
117
118
|
## Code conventions
|
|
118
119
|
|
|
@@ -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
|
|
|
@@ -87,23 +87,26 @@ public struct BottomTab: View {
|
|
|
87
87
|
.environment(\.duoTabBarInsets, duoInsets(compression))
|
|
88
88
|
.environment(\.duoBarCompression, compression)
|
|
89
89
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
90
|
+
Group {
|
|
91
|
+
if layout.isIPhoneDuo {
|
|
92
|
+
DuoTabBar(
|
|
93
|
+
items: items,
|
|
94
|
+
floatingButton: floatingButton,
|
|
95
|
+
selectedIndex: selectedIndex,
|
|
96
|
+
onTabSelected: selectTab,
|
|
97
|
+
compression: compression
|
|
98
|
+
)
|
|
99
|
+
} else {
|
|
100
|
+
BottomTabBar(
|
|
101
|
+
items: items,
|
|
102
|
+
floatingButton: floatingButton,
|
|
103
|
+
selectedIndex: selectedIndex,
|
|
104
|
+
onTabSelected: selectTab,
|
|
105
|
+
bottomInset: bottomInset
|
|
106
|
+
)
|
|
107
|
+
}
|
|
106
108
|
}
|
|
109
|
+
.scaleSizeMaxRate(TabBarMetrics.labelMaxScale)
|
|
107
110
|
}
|
|
108
111
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
109
112
|
.ignoresSafeArea(edges: .bottom)
|
|
@@ -95,8 +95,7 @@ struct BottomTabBar: View {
|
|
|
95
95
|
layout,
|
|
96
96
|
itemCount: items.count,
|
|
97
97
|
hasCta: TabBarMetrics.hasCenterAction(floatingButton, tabCount: items.count)
|
|
98
|
-
)
|
|
99
|
-
fixedFontScale: true
|
|
98
|
+
)
|
|
100
99
|
)
|
|
101
100
|
.padding(.bottom, TabBarMetrics.bottomGap(bottomInset))
|
|
102
101
|
.frame(maxWidth: .infinity)
|
|
@@ -112,7 +111,6 @@ struct HorizontalTabBar: View {
|
|
|
112
111
|
let selectedIndex: Int
|
|
113
112
|
let onTabSelected: (Int) -> Void
|
|
114
113
|
let width: CGFloat
|
|
115
|
-
var fixedFontScale = false
|
|
116
114
|
|
|
117
115
|
private var cta: BottomTabFloatingButton? {
|
|
118
116
|
TabBarMetrics.hasCenterAction(floatingButton, tabCount: items.count) ? floatingButton : nil
|
|
@@ -147,7 +145,7 @@ struct HorizontalTabBar: View {
|
|
|
147
145
|
}
|
|
148
146
|
SwiftUI.Button { onTabSelected(index) } label: {
|
|
149
147
|
VStack(spacing: TabBarMetrics.itemIconLabelGap) {
|
|
150
|
-
TabItemContent(item: items[index], selected: index == selectedIndex
|
|
148
|
+
TabItemContent(item: items[index], selected: index == selectedIndex)
|
|
151
149
|
}
|
|
152
150
|
.frame(width: itemWidth)
|
|
153
151
|
.contentShape(Rectangle())
|
|
@@ -167,11 +165,20 @@ struct HorizontalTabBar: View {
|
|
|
167
165
|
.padding(.top, cta == nil ? 0 : TabBarMetrics.ctaLift)
|
|
168
166
|
|
|
169
167
|
if let cta {
|
|
170
|
-
CenterAction(data: cta
|
|
168
|
+
CenterAction(data: cta)
|
|
169
|
+
.offset(y: centerActionTop)
|
|
171
170
|
}
|
|
172
171
|
}
|
|
173
172
|
.frame(width: width)
|
|
174
173
|
}
|
|
174
|
+
|
|
175
|
+
/// Offset of the center action column from the bar top: the items sit at the top of the container
|
|
176
|
+
/// (which starts ctaLift down), so the column is placed for its label to start on the tab labels' line.
|
|
177
|
+
private var centerActionTop: CGFloat {
|
|
178
|
+
let itemLabelTop = TabBarMetrics.ctaLift + TabBarMetrics.paddingVertical
|
|
179
|
+
+ TabBarMetrics.indicatorHeight + TabBarMetrics.itemIconLabelGap
|
|
180
|
+
return itemLabelTop - TabBarMetrics.ctaLabelGap - TabBarMetrics.ctaSize
|
|
181
|
+
}
|
|
175
182
|
}
|
|
176
183
|
|
|
177
184
|
/// One active indicator per bar: Background/tonal with its inner light (white 12% from below) and
|
|
@@ -203,21 +210,6 @@ struct ActiveIndicator: View {
|
|
|
203
210
|
}
|
|
204
211
|
}
|
|
205
212
|
|
|
206
|
-
/// Tab labels follow the host/OS font scale but never grow past this, so the fixed-height container
|
|
207
|
-
/// and the notch stay aligned.
|
|
208
|
-
private let tabLabelMaxScale: CGFloat = 1.2
|
|
209
|
-
|
|
210
|
-
/// Compose's `CappedFontScale`: caps the label scale at `tabLabelMaxScale` when enabled.
|
|
211
|
-
struct CappedFontScale: ViewModifier {
|
|
212
|
-
let enabled: Bool
|
|
213
|
-
|
|
214
|
-
@Environment(\.momoFontScale) private var fontScale
|
|
215
|
-
|
|
216
|
-
func body(content: Content) -> some View {
|
|
217
|
-
content.environment(\.momoFontScale, enabled ? fontScale.cappedAt(tabLabelMaxScale) : fontScale)
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
213
|
// MARK: - Tab item
|
|
222
214
|
|
|
223
215
|
/// Icon in its indicator slot, label under it. The bar slides one shared active indicator behind the
|
|
@@ -227,7 +219,6 @@ struct TabItemContent: View {
|
|
|
227
219
|
let selected: Bool
|
|
228
220
|
var vertical = false
|
|
229
221
|
var showLabel = true
|
|
230
|
-
var fixedFontScale = false
|
|
231
222
|
|
|
232
223
|
@Environment(\.appTheme) private var theme
|
|
233
224
|
|
|
@@ -235,19 +226,17 @@ struct TabItemContent: View {
|
|
|
235
226
|
TabIcon(item: item, selected: selected, vertical: vertical)
|
|
236
227
|
.frame(height: vertical ? TabBarMetrics.railIndicatorHeight : TabBarMetrics.indicatorHeight)
|
|
237
228
|
if showLabel {
|
|
238
|
-
|
|
229
|
+
ZStack {
|
|
239
230
|
labelText(theme.colors.text.secondary).opacity(selected ? 0 : 1)
|
|
240
231
|
labelText(theme.colors.primary).opacity(selected ? 1 : 0)
|
|
241
232
|
}
|
|
242
233
|
.animation(TabBarMetrics.tintMotion, value: selected)
|
|
243
234
|
.frame(maxWidth: vertical ? nil : .infinity)
|
|
244
235
|
// fixed slot so a capped-scale label overflows downward and the icon above it stays put
|
|
245
|
-
|
|
246
|
-
.
|
|
247
|
-
.
|
|
248
|
-
|
|
249
|
-
alignment: .top
|
|
250
|
-
)
|
|
236
|
+
.frame(
|
|
237
|
+
height: vertical ? TabBarMetrics.railLabelHeight : TabBarMetrics.labelHeight,
|
|
238
|
+
alignment: .top
|
|
239
|
+
)
|
|
251
240
|
}
|
|
252
241
|
}
|
|
253
242
|
|
|
@@ -324,7 +313,7 @@ private struct TabBadge: View {
|
|
|
324
313
|
var body: some View {
|
|
325
314
|
MomoText(label, typography: .actionXxsBold, color: Colors.black01, maxLines: 1)
|
|
326
315
|
.truncationMode(.tail)
|
|
327
|
-
.
|
|
316
|
+
.scaleSizeMaxRate(1)
|
|
328
317
|
.padding(.horizontal, Spacing.XS)
|
|
329
318
|
.frame(minWidth: 16, maxWidth: TabBarMetrics.badgeMaxWidth, minHeight: 16, maxHeight: 16)
|
|
330
319
|
.background(Capsule().fill(isNumber ? theme.colors.error.primary : theme.colors.warning.primary))
|
|
@@ -342,7 +331,6 @@ struct CenterActionStyle: ButtonStyle {
|
|
|
342
331
|
var iconContent: AnyView? = nil
|
|
343
332
|
var labelContent: AnyView? = nil
|
|
344
333
|
let label: String
|
|
345
|
-
var fixedFontScale = false
|
|
346
334
|
|
|
347
335
|
@Environment(\.appTheme) private var theme
|
|
348
336
|
|
|
@@ -379,7 +367,6 @@ struct CenterActionStyle: ButtonStyle {
|
|
|
379
367
|
maxLines: 1
|
|
380
368
|
)
|
|
381
369
|
.truncationMode(.tail)
|
|
382
|
-
.modifier(CappedFontScale(enabled: fixedFontScale))
|
|
383
370
|
.padding(.horizontal, vertical ? Spacing.XS : Spacing.XXS)
|
|
384
371
|
.frame(minHeight: vertical ? nil : TabBarMetrics.ctaLabelHeight)
|
|
385
372
|
.overlay(labelContent?.allowsHitTesting(false))
|
|
@@ -393,13 +380,12 @@ struct CenterActionStyle: ButtonStyle {
|
|
|
393
380
|
/// Center action (.Nav/CTA): button rising out of the notch, label under it.
|
|
394
381
|
private struct CenterAction: View {
|
|
395
382
|
let data: BottomTabFloatingButton
|
|
396
|
-
var fixedFontScale = false
|
|
397
383
|
|
|
398
384
|
var body: some View {
|
|
399
385
|
SwiftUI.Button(action: data.onPress) { EmptyView() }
|
|
400
386
|
.buttonStyle(CenterActionStyle(size: TabBarMetrics.ctaSize, vertical: false, icon: data.icon,
|
|
401
387
|
iconContent: data.iconContent, labelContent: data.labelContent,
|
|
402
|
-
label: data.label
|
|
388
|
+
label: data.label))
|
|
403
389
|
.frame(width: TabBarMetrics.ctaSlotWidth, height: TabBarMetrics.ctaSize + TabBarMetrics.ctaLabelGap + TabBarMetrics.ctaLabelHeight)
|
|
404
390
|
.accessibilityLabel(data.label)
|
|
405
391
|
.accessibilityIdentifier(data.label)
|
|
@@ -131,7 +131,7 @@ private struct DuoRailTabBar: View {
|
|
|
131
131
|
compression.onTabSelected()
|
|
132
132
|
} label: {
|
|
133
133
|
VStack(spacing: 0) {
|
|
134
|
-
TabItemContent(item: items[index], selected: index == selectedIndex, vertical: true
|
|
134
|
+
TabItemContent(item: items[index], selected: index == selectedIndex, vertical: true)
|
|
135
135
|
}
|
|
136
136
|
.frame(width: TabBarMetrics.railItemWidth, height: TabBarMetrics.railItemHeight)
|
|
137
137
|
.contentShape(Rectangle())
|
|
@@ -170,8 +170,7 @@ private struct DuoFloatingTabBar: View {
|
|
|
170
170
|
layout,
|
|
171
171
|
itemCount: items.count,
|
|
172
172
|
hasCta: TabBarMetrics.hasCenterAction(floatingButton, tabCount: items.count)
|
|
173
|
-
)
|
|
174
|
-
fixedFontScale: true
|
|
173
|
+
)
|
|
175
174
|
)
|
|
176
175
|
.padding(.bottom, layout.duoFloatingTabBarBottom)
|
|
177
176
|
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottom)
|
|
@@ -187,7 +186,7 @@ private struct RailCenterAction: View {
|
|
|
187
186
|
SwiftUI.Button(action: data.onPress) { EmptyView() }
|
|
188
187
|
.buttonStyle(CenterActionStyle(size: TabBarMetrics.railCtaSize, vertical: true, icon: data.icon,
|
|
189
188
|
iconContent: data.iconContent, labelContent: data.labelContent,
|
|
190
|
-
label: data.label
|
|
189
|
+
label: data.label))
|
|
191
190
|
.frame(width: TabBarMetrics.railCtaWidth, height: TabBarMetrics.railCtaHeight)
|
|
192
191
|
.accessibilityLabel(data.label)
|
|
193
192
|
.accessibilityIdentifier(data.label)
|
|
@@ -23,6 +23,9 @@ enum TabBarMetrics {
|
|
|
23
23
|
// label overflows downward instead of pushing the icon up
|
|
24
24
|
static let labelHeight: CGFloat = 18
|
|
25
25
|
static let railLabelHeight: CGFloat = 14
|
|
26
|
+
// font scale cap for the whole bar (RN ScaleSizeProvider around renderTabBar): its text follows the
|
|
27
|
+
// OS/host scale up to 1.2× so the fixed-height container and the notch stay aligned
|
|
28
|
+
static let labelMaxScale: CGFloat = 1.2
|
|
26
29
|
static let indicatorRadius = Radius.XL
|
|
27
30
|
// home indicator / gesture bar area under the container
|
|
28
31
|
static let systemIndicatorHeight: CGFloat = 24
|
|
@@ -15,7 +15,8 @@ public struct FontScale: Equatable {
|
|
|
15
15
|
/// From the app window, not UIScreen.main (which stays on one display on iPhone Duo).
|
|
16
16
|
public let windowShortSide: CGFloat
|
|
17
17
|
/// Opt-in ceiling (Compose's `MiniAppContext.scaleSizeMaxRate`): caps the result at size × maxScaleRate
|
|
18
|
-
/// on both the userScaleRate and OS paths; nil means no cap.
|
|
18
|
+
/// on both the userScaleRate and OS paths; nil means no cap. Set it with `ScaleSizeScope` or
|
|
19
|
+
/// `MiniAppContext.scaleSizeMaxRate`.
|
|
19
20
|
public let maxScaleRate: CGFloat?
|
|
20
21
|
|
|
21
22
|
public init(
|
|
@@ -54,9 +55,8 @@ public struct FontScale: Equatable {
|
|
|
54
55
|
return cap(max(deviceScaled, osScaled))
|
|
55
56
|
}
|
|
56
57
|
|
|
57
|
-
/// A copy that caps the scale at `rate` while keeping the host/OS inputs
|
|
58
|
-
|
|
59
|
-
public func cappedAt(_ rate: CGFloat) -> FontScale {
|
|
58
|
+
/// A copy that caps the scale at `rate` (nil lifts the cap) while keeping the host/OS inputs.
|
|
59
|
+
public func cappedAt(_ rate: CGFloat?) -> FontScale {
|
|
60
60
|
FontScale(
|
|
61
61
|
userScaleRate: userScaleRate,
|
|
62
62
|
useOSScaleRate: useOSScaleRate,
|
|
@@ -74,14 +74,15 @@ public struct FontScale: Equatable {
|
|
|
74
74
|
|
|
75
75
|
/// A host-pushed mini-app context wins per field, matching Compose's
|
|
76
76
|
/// `context?.useOSScaleRate ?: DesignSystemKits.getConfigs().useOSScaleRate`.
|
|
77
|
-
public func overriding(userScaleRate: CGFloat?, useOSScaleRate: Bool?) -> FontScale {
|
|
78
|
-
|
|
77
|
+
public func overriding(userScaleRate: CGFloat?, useOSScaleRate: Bool?, maxScaleRate: CGFloat? = nil) -> FontScale {
|
|
78
|
+
let overridesAny = userScaleRate != nil || useOSScaleRate != nil || maxScaleRate != nil
|
|
79
|
+
guard overridesAny else { return self }
|
|
79
80
|
return FontScale(
|
|
80
81
|
userScaleRate: userScaleRate ?? self.userScaleRate,
|
|
81
82
|
useOSScaleRate: useOSScaleRate ?? self.useOSScaleRate,
|
|
82
83
|
osFontScale: osFontScale,
|
|
83
84
|
windowShortSide: windowShortSide,
|
|
84
|
-
maxScaleRate: maxScaleRate
|
|
85
|
+
maxScaleRate: maxScaleRate ?? self.maxScaleRate
|
|
85
86
|
)
|
|
86
87
|
}
|
|
87
88
|
}
|
|
@@ -120,9 +121,44 @@ private struct MomoFontScaleModifier: ViewModifier {
|
|
|
120
121
|
\.momoFontScale,
|
|
121
122
|
store.fontScale.overriding(
|
|
122
123
|
userScaleRate: context?.userScaleRate,
|
|
123
|
-
useOSScaleRate: context?.useOSScaleRate
|
|
124
|
+
useOSScaleRate: context?.useOSScaleRate,
|
|
125
|
+
maxScaleRate: context?.scaleSizeMaxRate
|
|
124
126
|
)
|
|
125
127
|
)
|
|
126
128
|
.environment(\.designSystemKitsConfigs, store.getConfigs())
|
|
127
129
|
}
|
|
128
130
|
}
|
|
131
|
+
|
|
132
|
+
/// Compose's `ScaleSizeScope` (RN `ScaleSizeProvider`): caps the font scale of `content` at
|
|
133
|
+
/// size × `scaleSizeMaxRate`; the nearest scope wins and nil lifts the cap.
|
|
134
|
+
public struct ScaleSizeScope<Content: View>: View {
|
|
135
|
+
private let scaleSizeMaxRate: CGFloat?
|
|
136
|
+
private let content: Content
|
|
137
|
+
|
|
138
|
+
public init(scaleSizeMaxRate: CGFloat? = nil, @ViewBuilder content: () -> Content) {
|
|
139
|
+
self.scaleSizeMaxRate = scaleSizeMaxRate
|
|
140
|
+
self.content = content()
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
public var body: some View {
|
|
144
|
+
content.scaleSizeMaxRate(scaleSizeMaxRate)
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
public extension View {
|
|
149
|
+
/// Modifier form of `ScaleSizeScope`.
|
|
150
|
+
func scaleSizeMaxRate(_ rate: CGFloat?) -> some View {
|
|
151
|
+
modifier(ScaleSizeMaxRateModifier(rate: rate))
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/// Derives from the injected snapshot, so it stays live under `.momoFontScale()`.
|
|
156
|
+
private struct ScaleSizeMaxRateModifier: ViewModifier {
|
|
157
|
+
let rate: CGFloat?
|
|
158
|
+
|
|
159
|
+
@Environment(\.momoFontScale) private var fontScale
|
|
160
|
+
|
|
161
|
+
func body(content: Content) -> some View {
|
|
162
|
+
content.environment(\.momoFontScale, fontScale.cappedAt(rate))
|
|
163
|
+
}
|
|
164
|
+
}
|
package/ios/native-kits.podspec
CHANGED
|
@@ -39,6 +39,8 @@ private struct DemoConfig: Hashable {
|
|
|
39
39
|
var initialRouteName = "Momo"
|
|
40
40
|
var compressionBehavior: DuoBarCompressionBehavior = .toolbar
|
|
41
41
|
var backToInitialTab = true
|
|
42
|
+
// a sticky footer in the tab's content body, to check it clears the floating bar
|
|
43
|
+
var footer = false
|
|
42
44
|
|
|
43
45
|
var visibleTabs: [TabConfig] { Array(tabs.prefix(tabCount)) }
|
|
44
46
|
}
|
|
@@ -107,7 +109,10 @@ struct BottomTabDemoContent: View {
|
|
|
107
109
|
icon: tab.icon,
|
|
108
110
|
showDot: tab.showDot,
|
|
109
111
|
badgeLabel: tab.badgeLabel,
|
|
110
|
-
options: NavigationOptions(
|
|
112
|
+
options: NavigationOptions(
|
|
113
|
+
headerTitle: .default(tab.label),
|
|
114
|
+
footer: config.footer ? { AnyView(demoFooter) } : nil
|
|
115
|
+
),
|
|
111
116
|
screen: { TabContent(name: tab.name, config: $config, focused: $focused) }
|
|
112
117
|
)
|
|
113
118
|
},
|
|
@@ -124,6 +129,10 @@ struct BottomTabDemoContent: View {
|
|
|
124
129
|
.onAppear { ctaLottieLoader.load() }
|
|
125
130
|
}
|
|
126
131
|
|
|
132
|
+
private var demoFooter: some View {
|
|
133
|
+
MoMoUIKits.Button(title: "Footer trong content", action: {}, isFull: true)
|
|
134
|
+
}
|
|
135
|
+
|
|
127
136
|
private var floatingButton: BottomTabFloatingButton? {
|
|
128
137
|
guard config.special else { return nil }
|
|
129
138
|
guard config.ctaLottie else {
|
|
@@ -202,6 +211,9 @@ private struct TabContent: View {
|
|
|
202
211
|
])
|
|
203
212
|
Options(title: "backToInitialTab", hint: "Back ở tab khác quay về tab đầu trước khi rời màn",
|
|
204
213
|
options: yesNo(config.backToInitialTab) { config.backToInitialTab = $0 })
|
|
214
|
+
Options(title: "footer",
|
|
215
|
+
hint: "Footer dính trong content body, kiểm tra nó nằm trên thanh tab nổi",
|
|
216
|
+
options: yesNo(config.footer) { config.footer = $0 })
|
|
205
217
|
}
|
|
206
218
|
|
|
207
219
|
Section(title: "Nút giữa (floatingButton)") {
|
|
@@ -39,6 +39,8 @@ struct TypographyDemo: View {
|
|
|
39
39
|
// MARK: - Preview
|
|
40
40
|
|
|
41
41
|
private struct TypographyPreview: View {
|
|
42
|
+
@Environment(\.appTheme) private var theme
|
|
43
|
+
|
|
42
44
|
var body: some View {
|
|
43
45
|
BasicColumnBox("Headers", alignment: .leading) {
|
|
44
46
|
MomoText("Headline Default Bold", typography: .headlineDefaultBold)
|
|
@@ -63,6 +65,20 @@ private struct TypographyPreview: View {
|
|
|
63
65
|
MomoText("Action XS Bold", typography: .actionXsBold)
|
|
64
66
|
MomoText("Action XXS Bold", typography: .actionXxsBold)
|
|
65
67
|
}
|
|
68
|
+
BasicColumnBox("ScaleSizeScope", alignment: .leading) {
|
|
69
|
+
MomoText(
|
|
70
|
+
"Increase the system font size to compare",
|
|
71
|
+
typography: .descriptionXsRegular,
|
|
72
|
+
color: theme.colors.text.secondary
|
|
73
|
+
)
|
|
74
|
+
MomoText("No scope", typography: .bodyDefaultRegular)
|
|
75
|
+
ScaleSizeScope(scaleSizeMaxRate: 1) {
|
|
76
|
+
MomoText("ScaleSizeScope(1)", typography: .bodyDefaultRegular)
|
|
77
|
+
}
|
|
78
|
+
ScaleSizeScope(scaleSizeMaxRate: 1.2) {
|
|
79
|
+
MomoText("ScaleSizeScope(1.2)", typography: .bodyDefaultRegular)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
66
82
|
}
|
|
67
83
|
}
|
|
68
84
|
|