@momo-kits/native-kits 0.169.3-debug → 0.169.4-beta.1-debug
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compose/build.gradle.kts +1 -1
- package/compose/compose.podspec +1 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +11 -5
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +28 -3
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +4 -0
- package/gradle.properties +1 -1
- package/ios/Navigation/BottomTab/BottomTabBar.swift +18 -6
- package/ios/Navigation/BottomTab/TabBarMetrics.swift +4 -0
- package/ios/Typography/FontScale.swift +28 -5
- package/ios/native-kits.podspec +1 -1
- package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
- package/package.json +1 -1
package/compose/build.gradle.kts
CHANGED
package/compose/compose.podspec
CHANGED
|
@@ -21,11 +21,15 @@ const val MAX_DEVICE_SCALE = 5
|
|
|
21
21
|
@Composable
|
|
22
22
|
fun scaleSize(size: Float): Float {
|
|
23
23
|
val context = LocalContext.current
|
|
24
|
+
// opt-in ceiling: when context.scaleSizeMaxRate is set, the result never exceeds size × capRate,
|
|
25
|
+
// in both the userScaleRate path and the OS path. Null keeps the old behavior.
|
|
26
|
+
val capRate = context?.scaleSizeMaxRate
|
|
27
|
+
fun cap(scaled: Float): Float = if (capRate != null) min(scaled, size * capRate) else scaled
|
|
24
28
|
val useOsScale = context?.useOSScaleRate ?: DesignSystemKits.getConfigs().useOSScaleRate
|
|
25
29
|
if (!useOsScale) {
|
|
26
|
-
return size * (context?.userScaleRate ?: DesignSystemKits.getConfigs().userScaleRate)
|
|
30
|
+
return cap(size * (context?.userScaleRate ?: DesignSystemKits.getConfigs().userScaleRate))
|
|
27
31
|
}
|
|
28
|
-
val scaleSizeMaxRate: Float = MAX_FONT_SCALE
|
|
32
|
+
val scaleSizeMaxRate: Float = capRate ?: MAX_FONT_SCALE
|
|
29
33
|
// Short side, not width: landscape must not inflate every font.
|
|
30
34
|
val deviceWidth = getScreenDimensions().let { minOf(it.width, it.height) }
|
|
31
35
|
val deviceScale = deviceWidth / DEFAULT_SCREEN_SIZE
|
|
@@ -45,9 +49,11 @@ fun scaleSize(size: Float): Float {
|
|
|
45
49
|
fontSizeScaleOS = min(fontScale * fontSizeScaleOS, fontSizeScaleOS * scaleSizeMaxRate)
|
|
46
50
|
}
|
|
47
51
|
|
|
48
|
-
return
|
|
49
|
-
|
|
50
|
-
|
|
52
|
+
return cap(
|
|
53
|
+
max(
|
|
54
|
+
fontSizeScaleDevice,
|
|
55
|
+
fontSizeScaleOS
|
|
56
|
+
)
|
|
51
57
|
)
|
|
52
58
|
}
|
|
53
59
|
|
|
@@ -69,6 +69,7 @@ internal fun BottomTabBar(
|
|
|
69
69
|
floatingButton = floatingButton,
|
|
70
70
|
selectedIndex = selectedIndex,
|
|
71
71
|
onTabSelected = onTabSelected,
|
|
72
|
+
fixedFontScale = true,
|
|
72
73
|
modifier = Modifier
|
|
73
74
|
.offset(x = (layout.insetLeft - layout.insetRight) / 2)
|
|
74
75
|
.width(horizontalBarWidth(layout.width, layout.height, layout.insetLeft, layout.insetRight)),
|
|
@@ -226,10 +227,19 @@ internal fun ColumnScope.TabItemContent(
|
|
|
226
227
|
textAlign = TextAlign.Center,
|
|
227
228
|
maxLines = 1,
|
|
228
229
|
overflow = TextOverflow.Ellipsis,
|
|
229
|
-
modifier = if (vertical) Modifier else Modifier.fillMaxWidth()
|
|
230
|
+
modifier = (if (vertical) Modifier else Modifier.fillMaxWidth())
|
|
231
|
+
.wrapContentHeight(Alignment.Top, unbounded = true),
|
|
230
232
|
)
|
|
231
233
|
}
|
|
232
|
-
|
|
234
|
+
// fixed slot so a capped-scale label overflows downward and the icon above it stays put
|
|
235
|
+
Box(
|
|
236
|
+
modifier = Modifier.height(
|
|
237
|
+
if (vertical) TabBarMetrics.railLabelHeight else TabBarMetrics.labelHeight
|
|
238
|
+
),
|
|
239
|
+
contentAlignment = Alignment.TopCenter,
|
|
240
|
+
) {
|
|
241
|
+
if (fixedFontScale) CappedFontScale(label) else label()
|
|
242
|
+
}
|
|
233
243
|
}
|
|
234
244
|
}
|
|
235
245
|
|
|
@@ -243,6 +253,21 @@ internal fun FixedFontScale(content: @Composable () -> Unit) {
|
|
|
243
253
|
CompositionLocalProvider(LocalContext provides fixedScale, content = content)
|
|
244
254
|
}
|
|
245
255
|
|
|
256
|
+
// Tab labels follow the OS/host font scale but never grow past this, so the fixed-height container
|
|
257
|
+
// and the notch stay aligned.
|
|
258
|
+
private const val TAB_LABEL_MAX_SCALE = 1.2f
|
|
259
|
+
|
|
260
|
+
// Caps the label scale at TAB_LABEL_MAX_SCALE: it keeps following the host/OS font scale but stops
|
|
261
|
+
// growing past 1.2× so it fits the fixed bar geometry.
|
|
262
|
+
@Composable
|
|
263
|
+
internal fun CappedFontScale(content: @Composable () -> Unit) {
|
|
264
|
+
val context = LocalContext.current
|
|
265
|
+
val capped = remember(context) {
|
|
266
|
+
(context ?: MiniAppContext()).copy(scaleSizeMaxRate = TAB_LABEL_MAX_SCALE)
|
|
267
|
+
}
|
|
268
|
+
CompositionLocalProvider(LocalContext provides capped, content = content)
|
|
269
|
+
}
|
|
270
|
+
|
|
246
271
|
// Badge value shown on a tab: null hides it, "" is a dot, numbers cap at 99+ ("0" hides it, RN parity).
|
|
247
272
|
internal fun tabBadgeLabel(item: BottomTabItem): String? {
|
|
248
273
|
val label = item.badgeLabel ?: return if (item.showDot) "" else null
|
|
@@ -359,7 +384,7 @@ internal fun CenterActionLabel(label: String, overlay: (@Composable () -> Unit)?
|
|
|
359
384
|
.padding(horizontal = if (vertical) Spacing.XS else Spacing.XXS),
|
|
360
385
|
contentAlignment = Alignment.Center,
|
|
361
386
|
) {
|
|
362
|
-
if (fixedFontScale)
|
|
387
|
+
if (fixedFontScale) CappedFontScale(text) else text()
|
|
363
388
|
overlay?.let {
|
|
364
389
|
Box(Modifier.matchParentSize().wrapContentSize(Alignment.Center, unbounded = true)) { it() }
|
|
365
390
|
}
|
|
@@ -22,6 +22,10 @@ internal object TabBarMetrics {
|
|
|
22
22
|
val itemGap = Spacing.XS
|
|
23
23
|
val iconSize = 24.dp
|
|
24
24
|
val indicatorHeight = 32.dp
|
|
25
|
+
// label_s_medium / label_xs_medium line heights: the label slot keeps this height so a scaled
|
|
26
|
+
// label overflows downward instead of pushing the icon up
|
|
27
|
+
val labelHeight = 18.dp
|
|
28
|
+
val railLabelHeight = 14.dp
|
|
25
29
|
// active indicator behind the icon: 24 icon + XS·M padding
|
|
26
30
|
val indicatorPaddingHorizontal = Spacing.M
|
|
27
31
|
val indicatorRadius = Radius.XL
|
package/gradle.properties
CHANGED
|
@@ -96,7 +96,8 @@ struct BottomTabBar: View {
|
|
|
96
96
|
floatingButton: floatingButton,
|
|
97
97
|
selectedIndex: selectedIndex,
|
|
98
98
|
onTabSelected: onTabSelected,
|
|
99
|
-
width: TabBarMetrics.horizontalBarWidth(layout)
|
|
99
|
+
width: TabBarMetrics.horizontalBarWidth(layout),
|
|
100
|
+
fixedFontScale: true
|
|
100
101
|
)
|
|
101
102
|
.padding(.bottom, TabBarMetrics.bottomGap(bottomInset))
|
|
102
103
|
.frame(maxWidth: .infinity)
|
|
@@ -203,14 +204,19 @@ struct ActiveIndicator: View {
|
|
|
203
204
|
}
|
|
204
205
|
}
|
|
205
206
|
|
|
206
|
-
///
|
|
207
|
-
|
|
207
|
+
/// Tab labels follow the host/OS font scale but never grow past this, so the fixed-height container
|
|
208
|
+
/// and the notch stay aligned.
|
|
209
|
+
private let tabLabelMaxScale: CGFloat = 1.2
|
|
210
|
+
|
|
211
|
+
/// Caps the label scale at `tabLabelMaxScale` (Compose's `CappedFontScale`): it keeps following the
|
|
212
|
+
/// host/OS font scale but stops growing past 1.2× so it fits the fixed bar geometry.
|
|
213
|
+
struct CappedFontScale: ViewModifier {
|
|
208
214
|
let enabled: Bool
|
|
209
215
|
|
|
210
216
|
@Environment(\.momoFontScale) private var fontScale
|
|
211
217
|
|
|
212
218
|
func body(content: Content) -> some View {
|
|
213
|
-
content.environment(\.momoFontScale, enabled ?
|
|
219
|
+
content.environment(\.momoFontScale, enabled ? fontScale.cappedAt(tabLabelMaxScale) : fontScale)
|
|
214
220
|
}
|
|
215
221
|
}
|
|
216
222
|
|
|
@@ -237,7 +243,13 @@ struct TabItemContent: View {
|
|
|
237
243
|
}
|
|
238
244
|
.animation(TabBarMetrics.tintMotion, value: selected)
|
|
239
245
|
.frame(maxWidth: vertical ? nil : .infinity)
|
|
240
|
-
label
|
|
246
|
+
// fixed slot so a capped-scale label overflows downward and the icon above it stays put
|
|
247
|
+
label
|
|
248
|
+
.modifier(CappedFontScale(enabled: fixedFontScale))
|
|
249
|
+
.frame(
|
|
250
|
+
height: vertical ? TabBarMetrics.railLabelHeight : TabBarMetrics.labelHeight,
|
|
251
|
+
alignment: .top
|
|
252
|
+
)
|
|
241
253
|
}
|
|
242
254
|
}
|
|
243
255
|
|
|
@@ -364,7 +376,7 @@ struct CenterActionStyle: ButtonStyle {
|
|
|
364
376
|
maxLines: 1
|
|
365
377
|
)
|
|
366
378
|
.truncationMode(.tail)
|
|
367
|
-
.modifier(
|
|
379
|
+
.modifier(CappedFontScale(enabled: fixedFontScale))
|
|
368
380
|
.padding(.horizontal, vertical ? Spacing.XS : Spacing.XXS)
|
|
369
381
|
.frame(minHeight: vertical ? nil : TabBarMetrics.ctaLabelHeight)
|
|
370
382
|
.overlay(labelContent?.allowsHitTesting(false))
|
|
@@ -18,6 +18,10 @@ enum TabBarMetrics {
|
|
|
18
18
|
static let itemGap = Spacing.XS
|
|
19
19
|
static let iconSize: CGFloat = 24
|
|
20
20
|
static let indicatorHeight: CGFloat = 32
|
|
21
|
+
// label_s_medium / label_xs_medium line heights: the label slot keeps this height so a scaled
|
|
22
|
+
// label overflows downward instead of pushing the icon up
|
|
23
|
+
static let labelHeight: CGFloat = 18
|
|
24
|
+
static let railLabelHeight: CGFloat = 14
|
|
21
25
|
static let indicatorRadius = Radius.XL
|
|
22
26
|
// home indicator / gesture bar area under the container
|
|
23
27
|
static let systemIndicatorHeight: CGFloat = 24
|
|
@@ -21,22 +21,32 @@ public struct FontScale: Equatable {
|
|
|
21
21
|
public let osFontScale: CGFloat
|
|
22
22
|
// AI-GENERATED START: device scale from the app window, not UIScreen.main (fixed to one display on iPhone Duo)
|
|
23
23
|
public let windowShortSide: CGFloat
|
|
24
|
+
/// Opt-in ceiling (Compose's `MiniAppContext.scaleSizeMaxRate`): when set, the result never
|
|
25
|
+
/// exceeds size × maxScaleRate, in both the userScaleRate path and the OS path. nil keeps the
|
|
26
|
+
/// old behavior. Used by `CappedFontScale` for the bottom-tab labels.
|
|
27
|
+
public let maxScaleRate: CGFloat?
|
|
24
28
|
|
|
25
29
|
public init(
|
|
26
30
|
userScaleRate: CGFloat = 1,
|
|
27
31
|
useOSScaleRate: Bool = true,
|
|
28
32
|
osFontScale: CGFloat = 1,
|
|
29
|
-
windowShortSide: CGFloat? = nil
|
|
33
|
+
windowShortSide: CGFloat? = nil,
|
|
34
|
+
maxScaleRate: CGFloat? = nil
|
|
30
35
|
) {
|
|
31
36
|
self.userScaleRate = userScaleRate
|
|
32
37
|
self.useOSScaleRate = useOSScaleRate
|
|
33
38
|
self.osFontScale = osFontScale
|
|
34
39
|
self.windowShortSide = windowShortSide ?? DesignSystemKits.currentWindowShortSide()
|
|
40
|
+
self.maxScaleRate = maxScaleRate
|
|
35
41
|
}
|
|
36
42
|
|
|
37
43
|
/// `callAsFunction` so call sites keep reading like Compose's `scaleSize(16)`.
|
|
38
44
|
public func callAsFunction(_ size: CGFloat) -> CGFloat {
|
|
39
|
-
|
|
45
|
+
func cap(_ scaled: CGFloat) -> CGFloat {
|
|
46
|
+
guard let maxScaleRate else { return scaled }
|
|
47
|
+
return min(scaled, size * maxScaleRate)
|
|
48
|
+
}
|
|
49
|
+
guard useOSScaleRate else { return cap(size * userScaleRate) }
|
|
40
50
|
|
|
41
51
|
// Short side, not width: landscape must not inflate every font (and so every popup's height).
|
|
42
52
|
let deviceScale = windowShortSide / Self.defaultScreenSize
|
|
@@ -48,9 +58,21 @@ public struct FontScale: Equatable {
|
|
|
48
58
|
deviceScaled = min(size * deviceScale, size + Self.maxDeviceScale)
|
|
49
59
|
}
|
|
50
60
|
if osFontScale > 1 {
|
|
51
|
-
osScaled = min(size * osFontScale, size * Self.maxFontScale)
|
|
61
|
+
osScaled = min(size * osFontScale, size * (maxScaleRate ?? Self.maxFontScale))
|
|
52
62
|
}
|
|
53
|
-
return max(deviceScaled, osScaled)
|
|
63
|
+
return cap(max(deviceScaled, osScaled))
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/// A copy that caps the scale at `rate` while keeping the host/OS inputs — the SwiftUI mirror of
|
|
67
|
+
/// Compose's `CappedFontScale` wrapper.
|
|
68
|
+
public func cappedAt(_ rate: CGFloat) -> FontScale {
|
|
69
|
+
FontScale(
|
|
70
|
+
userScaleRate: userScaleRate,
|
|
71
|
+
useOSScaleRate: useOSScaleRate,
|
|
72
|
+
osFontScale: osFontScale,
|
|
73
|
+
windowShortSide: windowShortSide,
|
|
74
|
+
maxScaleRate: rate
|
|
75
|
+
)
|
|
54
76
|
}
|
|
55
77
|
|
|
56
78
|
/// `.system(size:)` is a fixed-size font — SwiftUI does not Dynamic-Type it — so the scale has to
|
|
@@ -68,8 +90,9 @@ public struct FontScale: Equatable {
|
|
|
68
90
|
useOSScaleRate: useOSScaleRate ?? self.useOSScaleRate,
|
|
69
91
|
osFontScale: osFontScale,
|
|
70
92
|
// AI-GENERATED START: keep the window size through context overrides
|
|
71
|
-
windowShortSide: windowShortSide
|
|
93
|
+
windowShortSide: windowShortSide,
|
|
72
94
|
// AI-GENERATED END: keep the window size through context overrides
|
|
95
|
+
maxScaleRate: maxScaleRate
|
|
73
96
|
)
|
|
74
97
|
}
|
|
75
98
|
}
|
package/ios/native-kits.podspec
CHANGED