@momo-kits/native-kits 0.157.11 → 0.157.12
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.
- package/ios/Typography/Text.swift +11 -11
- package/package.json +1 -1
|
@@ -2,28 +2,28 @@ import SwiftUI
|
|
|
2
2
|
|
|
3
3
|
public func scaleSize(_ size: CGFloat, _ scaleRate: CGFloat? = nil) -> CGFloat {
|
|
4
4
|
let defaultScreenSize: CGFloat = 375
|
|
5
|
-
let maxFontScale: CGFloat = scaleRate ?? 1.
|
|
5
|
+
let maxFontScale: CGFloat = scaleRate ?? 1.2
|
|
6
6
|
let maxDeviceScale: CGFloat = 5
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
let deviceWidth = UIScreen.main.bounds.width
|
|
9
9
|
let deviceScale = deviceWidth / defaultScreenSize
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
let defaultFont = UIFont.systemFont(ofSize: UIFont.labelFontSize)
|
|
12
12
|
let scaledFont = UIFontMetrics.default.scaledFont(for: defaultFont)
|
|
13
13
|
let fontScale = scaledFont.pointSize / defaultFont.pointSize
|
|
14
|
-
|
|
14
|
+
|
|
15
15
|
var fontSizeDeviceScale = size
|
|
16
16
|
var fontSizeOSScale = size
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
|
|
18
|
+
|
|
19
19
|
if deviceScale > 1 {
|
|
20
20
|
fontSizeDeviceScale = min(fontSizeDeviceScale * deviceScale, fontSizeDeviceScale + maxDeviceScale)
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
if fontScale > 1 {
|
|
24
24
|
fontSizeOSScale = min(fontSizeOSScale * fontScale, fontSizeOSScale * maxFontScale)
|
|
25
25
|
}
|
|
26
|
-
|
|
26
|
+
|
|
27
27
|
return max(fontSizeDeviceScale, fontSizeOSScale)
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -118,7 +118,7 @@ public struct MomoText: View {
|
|
|
118
118
|
private let content: String
|
|
119
119
|
private let typography: TypographyStyle
|
|
120
120
|
private let color: Color
|
|
121
|
-
|
|
121
|
+
|
|
122
122
|
public init(
|
|
123
123
|
_ content: String,
|
|
124
124
|
typography: TypographyStyle = .bodyDefaultRegular,
|
|
@@ -128,13 +128,13 @@ public struct MomoText: View {
|
|
|
128
128
|
self.typography = typography
|
|
129
129
|
self.color = color
|
|
130
130
|
}
|
|
131
|
-
|
|
131
|
+
|
|
132
132
|
public var body: some View {
|
|
133
133
|
let text = SwiftUI.Text(content)
|
|
134
134
|
.font(.system(size: scaleSize(typography.fontSize), weight: typography.fontWeight))
|
|
135
135
|
.foregroundColor(color)
|
|
136
136
|
.lineSpacing(scaleSize(typography.lineHeight) - scaleSize(typography.fontSize))
|
|
137
|
-
|
|
137
|
+
|
|
138
138
|
return text
|
|
139
139
|
}
|
|
140
140
|
}
|