@momo-kits/native-kits 0.162.2-test.8 → 0.162.2-test.9

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.
@@ -8,8 +8,15 @@ public func scaleSize(_ size: CGFloat, _ scaleRate: CGFloat? = nil) -> CGFloat {
8
8
  let maxFontScale: CGFloat = scaleRate ?? 1.5
9
9
  let maxDeviceScale: CGFloat = 5
10
10
 
11
- let deviceWidth = UIScreen.main.bounds.width
12
- let deviceScale = deviceWidth / defaultScreenSize
11
+ // useOSFontScale off -> the user has full control via userScaleRate; skip device-width scaling
12
+ // entirely and apply only the custom rate (capped at maxFontScale). Mirrors Compose / RN.
13
+ if !config.useOSFontScale {
14
+ let customRate = config.userScaleRate ?? 1
15
+ return customRate > 1 ? min(size * customRate, size * maxFontScale) : size
16
+ }
17
+
18
+ // useOSFontScale on -> device-width scale + OS font scale, take the larger.
19
+ let deviceScale = UIScreen.main.bounds.width / defaultScreenSize
13
20
 
14
21
  let defaultFont = UIFont.systemFont(ofSize: UIFont.labelFontSize)
15
22
  let scaledFont = UIFontMetrics.default.scaledFont(for: defaultFont)
@@ -18,16 +25,11 @@ public func scaleSize(_ size: CGFloat, _ scaleRate: CGFloat? = nil) -> CGFloat {
18
25
  var fontSizeDeviceScale = size
19
26
  var fontSizeOSScale = size
20
27
 
21
-
22
28
  if deviceScale > 1 {
23
29
  fontSizeDeviceScale = min(fontSizeDeviceScale * deviceScale, fontSizeDeviceScale + maxDeviceScale)
24
30
  }
25
-
26
- // useOSFontScale on -> follow OS Dynamic Type; off -> use the user rate (default 1 = no scaling).
27
- // Both capped at maxFontScale. Mirrors Compose scaleSize / RN useScaleSize.
28
- let appliedRate = config.useOSFontScale ? osFontScale : (config.userScaleRate ?? 1)
29
- if appliedRate > 1 {
30
- fontSizeOSScale = min(fontSizeOSScale * appliedRate, fontSizeOSScale * maxFontScale)
31
+ if osFontScale > 1 {
32
+ fontSizeOSScale = min(fontSizeOSScale * osFontScale, fontSizeOSScale * maxFontScale)
31
33
  }
32
34
 
33
35
  return max(fontSizeDeviceScale, fontSizeOSScale)
@@ -11,8 +11,16 @@ public extension Font {
11
11
  let maxFontScale: CGFloat = 1.5
12
12
  let maxDeviceScale: CGFloat = 5
13
13
 
14
- let deviceWidth = UIScreen.main.bounds.width
15
- let deviceScale = deviceWidth / defaultScreenSize
14
+ // useOSFontScale off -> the user has full control via userScaleRate; skip device-width
15
+ // scaling entirely and apply only the custom rate (capped at maxFontScale).
16
+ if !config.useOSFontScale {
17
+ let customRate = config.userScaleRate ?? 1
18
+ let scaled = customRate > 1 ? min(size * customRate, size * maxFontScale) : size
19
+ return Font.system(size: scaled)
20
+ }
21
+
22
+ // useOSFontScale on -> device-width scale, then OS font scale on top (existing behavior).
23
+ let deviceScale = UIScreen.main.bounds.width / defaultScreenSize
16
24
 
17
25
  let defaultFont = UIFont.systemFont(ofSize: UIFont.labelFontSize)
18
26
  let scaledFont = UIFontMetrics.default.scaledFont(for: defaultFont)
@@ -23,10 +31,8 @@ public extension Font {
23
31
  if deviceScale > 1 {
24
32
  fontSize = min(fontSize * deviceScale, fontSize + maxDeviceScale)
25
33
  }
26
-
27
- let appliedRate = config.useOSFontScale ? osFontScale : (config.userScaleRate ?? 1)
28
- if appliedRate > 1 {
29
- fontSize = min(fontSize * appliedRate, fontSize * maxFontScale)
34
+ if osFontScale > 1 {
35
+ fontSize = min(fontSize * osFontScale, fontSize * maxFontScale)
30
36
  }
31
37
 
32
38
  return Font.system(size: fontSize)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/native-kits",
3
- "version": "0.162.2-test.8",
3
+ "version": "0.162.2-test.9",
4
4
  "private": false,
5
5
  "dependencies": {},
6
6
  "devDependencies": {},