@momo-kits/native-kits 0.162.2-test.8-debug → 0.162.2-test.9-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.
@@ -40,7 +40,7 @@ kotlin {
40
40
  }
41
41
 
42
42
  cocoapods {
43
- version = "0.162.2-test.8-debug"
43
+ version = "0.162.2-test.9-debug"
44
44
  summary = "IOS Shared module"
45
45
  homepage = "https://momo.vn"
46
46
  ios.deploymentTarget = "15.0"
@@ -44,31 +44,28 @@ fun scaleSize(size: Float, userScaleRate: Float? = null): Float {
44
44
  // param userScaleRate overrides config; if absent -> config.userScaleRate -> 1f (no scaling)
45
45
  val customRate = userScaleRate ?: fontScaleConfig.userScaleRate ?: 1f
46
46
 
47
- val deviceWidth = getScreenDimensions().width
48
- val deviceScale = deviceWidth / DEFAULT_SCREEN_SIZE
47
+ // Read composables unconditionally (rule of Compose) before branching on the math below.
48
+ val deviceScale = getScreenDimensions().width / DEFAULT_SCREEN_SIZE
49
+ val fontScale = LocalDensity.current.fontScale
49
50
 
50
- val density = LocalDensity.current
51
- val fontScale = density.fontScale
51
+ // useOSFontScale off -> the user has full control via customRate; skip device-width scaling
52
+ // entirely and apply only the custom rate (capped at MAX_FONT_SCALE).
53
+ if (!useOSFontScale) {
54
+ return if (customRate > 1f) min(customRate * size, size * MAX_FONT_SCALE) else size
55
+ }
52
56
 
57
+ // useOSFontScale on -> device-width scale + OS font scale, take the larger.
53
58
  var fontSizeScaleDevice = size
54
59
  var fontSizeScaleOS = size
55
-
56
60
  if (deviceScale > 1) {
57
61
  fontSizeScaleDevice =
58
62
  min(deviceScale * fontSizeScaleDevice, fontSizeScaleDevice + MAX_DEVICE_SCALE)
59
63
  }
60
-
61
- // useOSFontScale on -> apply the OS scale, ignore the user's custom rate.
62
- // off -> use the user's custom rate. Both hard-capped at MAX_FONT_SCALE (150%).
63
- val appliedRate = if (useOSFontScale) fontScale else customRate
64
- if (appliedRate > 1f) {
65
- fontSizeScaleOS = min(appliedRate * fontSizeScaleOS, fontSizeScaleOS * MAX_FONT_SCALE)
64
+ if (fontScale > 1f) {
65
+ fontSizeScaleOS = min(fontScale * fontSizeScaleOS, fontSizeScaleOS * MAX_FONT_SCALE)
66
66
  }
67
67
 
68
- return max(
69
- fontSizeScaleDevice,
70
- fontSizeScaleOS
71
- )
68
+ return max(fontSizeScaleDevice, fontSizeScaleOS)
72
69
  }
73
70
 
74
71
  @Composable
package/gradle.properties CHANGED
@@ -18,7 +18,7 @@ kotlin.apple.xcodeCompatibility.nowarn=true
18
18
  name="ComposeKits"
19
19
  group=vn.momo.kits
20
20
  artifact.id=kits
21
- version=0.162.2-test.8
21
+ version=0.162.2-test.9
22
22
 
23
23
  repo=GitLab
24
24
  url=https://gitlab.mservice.com.vn/api/v4/projects/5400/packages/maven
@@ -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-debug",
3
+ "version": "0.162.2-test.9-debug",
4
4
  "private": false,
5
5
  "dependencies": {},
6
6
  "devDependencies": {},