@momo-kits/native-kits 0.159.1-beta.6 → 0.159.1-beta.7

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.
@@ -1,7 +1,30 @@
1
1
  import SwiftUI
2
2
 
3
3
  public func scaleSize(_ size: CGFloat, _ scaleRate: CGFloat? = nil) -> CGFloat {
4
- return size
4
+ let defaultScreenSize: CGFloat = 375
5
+ let maxFontScale: CGFloat = scaleRate ?? 1.2
6
+ let maxDeviceScale: CGFloat = 5
7
+
8
+ let deviceWidth = UIScreen.main.bounds.width
9
+ let deviceScale = deviceWidth / defaultScreenSize
10
+
11
+ let defaultFont = UIFont.systemFont(ofSize: UIFont.labelFontSize)
12
+ let scaledFont = UIFontMetrics.default.scaledFont(for: defaultFont)
13
+ let fontScale = scaledFont.pointSize / defaultFont.pointSize
14
+
15
+ var fontSizeDeviceScale = size
16
+ var fontSizeOSScale = size
17
+
18
+
19
+ if deviceScale > 1 {
20
+ fontSizeDeviceScale = min(fontSizeDeviceScale * deviceScale, fontSizeDeviceScale + maxDeviceScale)
21
+ }
22
+
23
+ if fontScale > 1 {
24
+ fontSizeOSScale = min(fontSizeOSScale * fontScale, fontSizeOSScale * maxFontScale)
25
+ }
26
+
27
+ return max(fontSizeDeviceScale, fontSizeOSScale)
5
28
  }
6
29
 
7
30
  public enum TypographyStyle {
@@ -2,9 +2,30 @@ import SwiftUI
2
2
 
3
3
  public extension Font {
4
4
  static func appFont(size: CGFloat) -> Font {
5
- return Font.system(size: size)
6
- }
5
+ let defaultScreenSize: CGFloat = 375
6
+ let maxFontScale: CGFloat = 1.5
7
+ let maxDeviceScale: CGFloat = 5
8
+
9
+ let deviceWidth = UIScreen.main.bounds.width
10
+ let deviceScale = deviceWidth / defaultScreenSize
11
+
12
+ let defaultFont = UIFont.systemFont(ofSize: UIFont.labelFontSize)
13
+ let scaledFont = UIFontMetrics.default.scaledFont(for: defaultFont)
14
+ let fontScale = scaledFont.pointSize / defaultFont.pointSize
15
+
16
+ var fontSize = size
17
+
18
+ if deviceScale > 1 {
19
+ fontSize = min(fontSize * deviceScale, fontSize + maxDeviceScale)
20
+ }
21
+
22
+ if fontScale > 1 {
23
+ fontSize = min(fontSize * fontScale, fontSize * maxFontScale)
24
+ }
7
25
 
26
+ return Font.system(size: fontSize)
27
+ }
28
+
8
29
  // New supported typography styles
9
30
  static let headline_default_bold = appFont(size: 24).weight(.bold)
10
31
  static let header_m_bold = appFont(size: 18).weight(.bold)
@@ -22,7 +43,7 @@ public extension Font {
22
43
  static let action_s_bold = appFont(size: 14).weight(.bold)
23
44
  static let action_xs_bold = appFont(size: 12).weight(.bold)
24
45
  static let action_xxs_bold = appFont(size: 10).weight(.bold)
25
-
46
+
26
47
  // Legacy styles
27
48
  static let headline_default = appFont(size: 28).weight(.semibold)
28
49
  static let headline_s = appFont(size: 24).weight(.semibold)
@@ -47,7 +68,7 @@ public extension Font {
47
68
  static let action_xxs = appFont(size: 10).weight(.bold)
48
69
  static let action_xs = appFont(size: 12).weight(.bold)
49
70
  static let action_s = appFont(size: 15).weight(.bold)
50
-
71
+
51
72
  // deprecated
52
73
  static let h1 = appFont(size: 36).weight(.semibold) //headline_xl
53
74
  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.159.1-beta.6",
3
+ "version": "0.159.1-beta.7",
4
4
  "private": false,
5
5
  "dependencies": {},
6
6
  "devDependencies": {},