@momo-kits/native-kits 0.162.3-fontscale.2 → 0.162.3-fontscale.3

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.
@@ -0,0 +1,20 @@
1
+ import Combine
2
+ import CoreGraphics
3
+
4
+ /// App-wide font-scale preference for the SwiftUI kit. Populated by the host container
5
+ /// (`KitContainer`), which reads `FontScaleProvider.configFlow` — the cache-backed source, same
6
+ /// as RN/Compose. `scaleSize`/`appFont` read the snapshot; `MomoText` observes it for live redraw.
7
+ /// When `useOSScaleRate` is false the kit applies `userScaleRate` instead of the OS Dynamic Type
8
+ /// factor. `update` must be called on the main thread.
9
+ public final class FontScaleStore: ObservableObject {
10
+ public static let shared = FontScaleStore()
11
+ private init() {}
12
+
13
+ @Published public private(set) var userScaleRate: CGFloat = 1
14
+ @Published public private(set) var useOSScaleRate: Bool = true
15
+
16
+ public func update(userScaleRate: CGFloat, useOSScaleRate: Bool) {
17
+ self.userScaleRate = userScaleRate
18
+ self.useOSScaleRate = useOSScaleRate
19
+ }
20
+ }
@@ -1,6 +1,9 @@
1
1
  import SwiftUI
2
2
 
3
3
  public func scaleSize(_ size: CGFloat, _ scaleRate: CGFloat? = nil) -> CGFloat {
4
+ if !FontScaleStore.shared.useOSScaleRate {
5
+ return size * FontScaleStore.shared.userScaleRate
6
+ }
4
7
  let defaultScreenSize: CGFloat = 375
5
8
  let maxFontScale: CGFloat = scaleRate ?? 1.5
6
9
  let maxDeviceScale: CGFloat = 5
@@ -115,6 +118,7 @@ public extension TypographyStyle {
115
118
  }
116
119
 
117
120
  public struct MomoText: View {
121
+ @ObservedObject private var fontScale = FontScaleStore.shared
118
122
  private let content: String
119
123
  private let typography: TypographyStyle
120
124
  private let color: Color
@@ -11,6 +11,9 @@ public extension View {
11
11
 
12
12
  public extension Font {
13
13
  static func appFont(size: CGFloat) -> Font {
14
+ if !FontScaleStore.shared.useOSScaleRate {
15
+ return Font.system(size: size * FontScaleStore.shared.userScaleRate)
16
+ }
14
17
  let defaultScreenSize: CGFloat = 375
15
18
  let maxFontScale: CGFloat = 1.5
16
19
  let maxDeviceScale: CGFloat = 5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/native-kits",
3
- "version": "0.162.3-fontscale.2",
3
+ "version": "0.162.3-fontscale.3",
4
4
  "private": false,
5
5
  "dependencies": {},
6
6
  "devDependencies": {},