@momo-kits/native-kits 0.162.13 → 0.162.14

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.
@@ -46,6 +46,5 @@ public class ApplicationEnvironment: ObservableObject {
46
46
  self.applicationContext = applicationContext
47
47
  self.composeApi = composeApi
48
48
  self.config = config
49
- FontScaleStore.shared.bind(composeApi)
50
49
  }
51
50
  }
@@ -1,30 +1,27 @@
1
1
  import SwiftUI
2
2
 
3
3
  public func scaleSize(_ size: CGFloat, _ scaleRate: CGFloat? = nil) -> CGFloat {
4
- let config = FontScaleStore.shared.config
5
4
  let defaultScreenSize: CGFloat = 375
6
5
  let maxFontScale: CGFloat = scaleRate ?? 1.5
7
6
  let maxDeviceScale: CGFloat = 5
8
7
 
9
- if !config.useOSFontScale {
10
- let customRate = config.userScaleRate ?? 1
11
- return customRate > 1 ? size * customRate : size
12
- }
13
-
14
- let deviceScale = UIScreen.main.bounds.width / defaultScreenSize
8
+ let deviceWidth = UIScreen.main.bounds.width
9
+ let deviceScale = deviceWidth / defaultScreenSize
15
10
 
16
11
  let defaultFont = UIFont.systemFont(ofSize: UIFont.labelFontSize)
17
12
  let scaledFont = UIFontMetrics.default.scaledFont(for: defaultFont)
18
- let osFontScale = scaledFont.pointSize / defaultFont.pointSize
13
+ let fontScale = scaledFont.pointSize / defaultFont.pointSize
19
14
 
20
15
  var fontSizeDeviceScale = size
21
16
  var fontSizeOSScale = size
22
17
 
18
+
23
19
  if deviceScale > 1 {
24
20
  fontSizeDeviceScale = min(fontSizeDeviceScale * deviceScale, fontSizeDeviceScale + maxDeviceScale)
25
21
  }
26
- if osFontScale > 1 {
27
- fontSizeOSScale = min(fontSizeOSScale * osFontScale, fontSizeOSScale * maxFontScale)
22
+
23
+ if fontScale > 1 {
24
+ fontSizeOSScale = min(fontSizeOSScale * fontScale, fontSizeOSScale * maxFontScale)
28
25
  }
29
26
 
30
27
  return max(fontSizeDeviceScale, fontSizeOSScale)
@@ -121,7 +118,6 @@ public struct MomoText: View {
121
118
  private let content: String
122
119
  private let typography: TypographyStyle
123
120
  private let color: Color
124
- @ObservedObject private var fontScale = FontScaleStore.shared
125
121
 
126
122
  public init(
127
123
  _ content: String,
@@ -134,7 +130,6 @@ public struct MomoText: View {
134
130
  }
135
131
 
136
132
  public var body: some View {
137
- _ = fontScale.config
138
133
  let text = SwiftUI.Text(content)
139
134
  .font(.system(size: scaleSize(typography.fontSize), weight: typography.fontWeight))
140
135
  .foregroundColor(color)
@@ -11,35 +11,30 @@ public extension View {
11
11
 
12
12
  public extension Font {
13
13
  static func appFont(size: CGFloat) -> Font {
14
- let config = FontScaleStore.shared.config
15
14
  let defaultScreenSize: CGFloat = 375
16
15
  let maxFontScale: CGFloat = 1.5
17
16
  let maxDeviceScale: CGFloat = 5
18
17
 
19
- if !config.useOSFontScale {
20
- let customRate = config.userScaleRate ?? 1
21
- let scaled = customRate > 1 ? size * customRate : size
22
- return Font.system(size: scaled)
23
- }
24
-
25
- let deviceScale = UIScreen.main.bounds.width / defaultScreenSize
18
+ let deviceWidth = UIScreen.main.bounds.width
19
+ let deviceScale = deviceWidth / defaultScreenSize
26
20
 
27
21
  let defaultFont = UIFont.systemFont(ofSize: UIFont.labelFontSize)
28
22
  let scaledFont = UIFontMetrics.default.scaledFont(for: defaultFont)
29
- let osFontScale = scaledFont.pointSize / defaultFont.pointSize
23
+ let fontScale = scaledFont.pointSize / defaultFont.pointSize
30
24
 
31
25
  var fontSize = size
32
26
 
33
27
  if deviceScale > 1 {
34
28
  fontSize = min(fontSize * deviceScale, fontSize + maxDeviceScale)
35
29
  }
36
- if osFontScale > 1 {
37
- fontSize = min(fontSize * osFontScale, fontSize * maxFontScale)
30
+
31
+ if fontScale > 1 {
32
+ fontSize = min(fontSize * fontScale, fontSize * maxFontScale)
38
33
  }
39
34
 
40
35
  return Font.system(size: fontSize)
41
36
  }
42
-
37
+
43
38
  // New supported typography styles
44
39
  static let headline_default_bold = appFont(size: 24).weight(.bold)
45
40
  static let header_m_bold = appFont(size: 18).weight(.bold)
@@ -57,7 +52,7 @@ public extension Font {
57
52
  static let action_s_bold = appFont(size: 14).weight(.bold)
58
53
  static let action_xs_bold = appFont(size: 12).weight(.bold)
59
54
  static let action_xxs_bold = appFont(size: 10).weight(.bold)
60
-
55
+
61
56
  // Legacy styles
62
57
  static let headline_default = appFont(size: 28).weight(.semibold)
63
58
  static let headline_s = appFont(size: 24).weight(.semibold)
@@ -82,7 +77,7 @@ public extension Font {
82
77
  static let action_xxs = appFont(size: 10).weight(.bold)
83
78
  static let action_xs = appFont(size: 12).weight(.bold)
84
79
  static let action_s = appFont(size: 15).weight(.bold)
85
-
80
+
86
81
  // deprecated
87
82
  static let h1 = appFont(size: 36).weight(.semibold) //headline_xl
88
83
  static let h2 = appFont(size: 32).weight(.semibold)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/native-kits",
3
- "version": "0.162.13",
3
+ "version": "0.162.14",
4
4
  "private": false,
5
5
  "dependencies": {},
6
6
  "devDependencies": {},
@@ -1,59 +0,0 @@
1
- import SwiftUI
2
-
3
- public struct FontScaleConfig {
4
- public var useOSFontScale: Bool
5
- public var userScaleRate: CGFloat?
6
-
7
- public init(useOSFontScale: Bool = true, userScaleRate: CGFloat? = nil) {
8
- self.useOSFontScale = useOSFontScale
9
- self.userScaleRate = userScaleRate
10
- }
11
- }
12
-
13
- public final class FontScaleStore: ObservableObject {
14
- public static let shared = FontScaleStore()
15
-
16
- @Published public private(set) var config = FontScaleConfig()
17
-
18
- private var didBind = false
19
- private var observerId: String?
20
-
21
- private init() {}
22
-
23
- public func update(_ newConfig: FontScaleConfig) {
24
- if Thread.isMainThread {
25
- config = newConfig
26
- } else {
27
- DispatchQueue.main.async { [weak self] in self?.config = newConfig }
28
- }
29
- }
30
-
31
- public func bind(_ api: KitComposeApi?) {
32
- guard let api = api, !didBind else { return }
33
- didBind = true
34
-
35
- apply(api.request(funcName: "getFontScaleConfig", params: nil))
36
- observerId = api.request(funcName: "observer", params: ["font_scale_config"]) { [weak self] response in
37
- self?.apply(response)
38
- }
39
- }
40
-
41
- private func apply(_ response: String) {
42
- guard let parsed = FontScaleStore.parse(response) else { return }
43
- update(parsed)
44
- }
45
-
46
- static func parse(_ response: String) -> FontScaleConfig? {
47
- guard
48
- let data = response.data(using: .utf8),
49
- let json = (try? JSONSerialization.jsonObject(with: data)) as? [String: Any]
50
- else { return nil }
51
-
52
- let obj = (json["response"] as? [String: Any]) ?? (json["data"] as? [String: Any]) ?? json
53
- guard obj["useOSFontScale"] != nil || obj["userScaleRate"] != nil else { return nil }
54
-
55
- let useOS = (obj["useOSFontScale"] as? Bool) ?? true
56
- let rate = (obj["userScaleRate"] as? NSNumber).map { CGFloat($0.doubleValue) }
57
- return FontScaleConfig(useOSFontScale: useOS, userScaleRate: rate)
58
- }
59
- }