@momo-kits/native-kits 0.163.1-beta.1 → 0.163.1-beta.2
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/Application/ApplicationEnvironment.swift +1 -0
- package/ios/Application/Components.swift +1 -0
- package/ios/Application/FloatingButton.swift +1 -0
- package/ios/Application/FontScaleStore.swift +59 -0
- package/ios/Badge/Badge.swift +1 -0
- package/ios/Badge/BadgeRibbon.swift +2 -0
- package/ios/Button/Button.swift +1 -1
- package/ios/Checkbox/Checkbox.swift +1 -0
- package/ios/Information/Information.swift +151 -0
- package/ios/Input/Input.swift +1 -0
- package/ios/Input/InputPhoneNumber.swift +1 -0
- package/ios/Input/InputSearch.swift +3 -0
- package/ios/Input/InputTextArea.swift +1 -0
- package/ios/OTPKeyboard/KeyboardButton.swift +1 -1
- package/ios/Popup/PopupDisplay.swift +6 -0
- package/ios/Popup/PopupInput.swift +2 -0
- package/ios/Template/TrustBanner/TrustBanner.swift +2 -0
- package/ios/Typography/Text.swift +13 -7
- package/ios/Typography/Typography.swift +22 -8
- package/package.json +1 -1
|
@@ -245,6 +245,7 @@ public struct Header: View {
|
|
|
245
245
|
} else {
|
|
246
246
|
Text(title)
|
|
247
247
|
.font(.system(size: 17, weight: .bold))
|
|
248
|
+
.ignoreBoldTextSetting()
|
|
248
249
|
.foregroundColor(tintColor ?? Colors.black17)
|
|
249
250
|
.frame(maxWidth: titlePosition == .center ? UIScreen.main.bounds.width - 252 : nil)
|
|
250
251
|
.frame(maxWidth: titlePosition == .center ? .infinity : UIScreen.main.bounds.width - 172, alignment: titlePosition == .center ? .center : .leading)
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
}
|
package/ios/Badge/Badge.swift
CHANGED
|
@@ -54,6 +54,7 @@ public struct Badge: View {
|
|
|
54
54
|
public var body: some View {
|
|
55
55
|
Text(formatTitle(label))
|
|
56
56
|
.font(.system(size: scaleSize(10), weight: .bold))
|
|
57
|
+
.ignoreBoldTextSetting()
|
|
57
58
|
.foregroundColor(Colors.black01)
|
|
58
59
|
.padding(.horizontal, Spacing.XS)
|
|
59
60
|
.frame(minWidth: scaleSize(16), minHeight: scaleSize(16))
|
|
@@ -138,6 +138,7 @@ public struct BadgeRibbon: View {
|
|
|
138
138
|
HStack(spacing: 0) {
|
|
139
139
|
Text(label)
|
|
140
140
|
.font(.system(size: scaleSize(12), weight: .medium))
|
|
141
|
+
.ignoreBoldTextSetting()
|
|
141
142
|
.foregroundColor(Colors.black01)
|
|
142
143
|
.lineLimit(1)
|
|
143
144
|
.rotationEffect(rotation)
|
|
@@ -159,6 +160,7 @@ public struct BadgeRibbon: View {
|
|
|
159
160
|
HStack(spacing: 0) {
|
|
160
161
|
Text(label)
|
|
161
162
|
.font(.system(size: scaleSize(12), weight: .medium))
|
|
163
|
+
.ignoreBoldTextSetting()
|
|
162
164
|
.foregroundColor(Colors.black01)
|
|
163
165
|
.lineLimit(1)
|
|
164
166
|
.rotationEffect(rotation)
|
package/ios/Button/Button.swift
CHANGED
|
@@ -200,7 +200,7 @@ public struct Button: View {
|
|
|
200
200
|
.background(bg)
|
|
201
201
|
.overlay(
|
|
202
202
|
RoundedRectangle(cornerRadius: size.radius)
|
|
203
|
-
.
|
|
203
|
+
.strokeBorder(border ?? .clear, lineWidth: border != nil ? borderWidth : 0)
|
|
204
204
|
)
|
|
205
205
|
.clipShape(RoundedRectangle(cornerRadius: size.radius))
|
|
206
206
|
.opacity(loading ? 0.75 : 1)
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import SwiftUI
|
|
2
|
+
|
|
3
|
+
public enum InformationState {
|
|
4
|
+
case `default`
|
|
5
|
+
case warning
|
|
6
|
+
case error
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
public struct Information: View {
|
|
10
|
+
private let title: String?
|
|
11
|
+
private let description: String
|
|
12
|
+
private let state: InformationState
|
|
13
|
+
private let image: String?
|
|
14
|
+
private let onPressAction: (() -> Void)?
|
|
15
|
+
private let showIcon: Bool
|
|
16
|
+
private let action: String?
|
|
17
|
+
private let showIconClose: Bool
|
|
18
|
+
private let onPressClose: (() -> Void)?
|
|
19
|
+
|
|
20
|
+
public init(
|
|
21
|
+
title: String? = nil,
|
|
22
|
+
description: String = "Description",
|
|
23
|
+
state: InformationState = .default,
|
|
24
|
+
image: String? = nil,
|
|
25
|
+
onPressAction: (() -> Void)? = nil,
|
|
26
|
+
showIcon: Bool = true,
|
|
27
|
+
action: String? = nil,
|
|
28
|
+
showIconClose: Bool = true,
|
|
29
|
+
onPressClose: (() -> Void)? = nil
|
|
30
|
+
) {
|
|
31
|
+
self.title = title
|
|
32
|
+
self.description = description
|
|
33
|
+
self.state = state
|
|
34
|
+
self.image = image
|
|
35
|
+
self.onPressAction = onPressAction
|
|
36
|
+
self.showIcon = showIcon
|
|
37
|
+
self.action = action
|
|
38
|
+
self.showIconClose = showIconClose
|
|
39
|
+
self.onPressClose = onPressClose
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private var borderColor: Color {
|
|
43
|
+
switch state {
|
|
44
|
+
case .default: return Colors.blue07
|
|
45
|
+
case .warning: return Colors.yellow06
|
|
46
|
+
case .error: return Colors.red07
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private var backgroundColor: Color {
|
|
51
|
+
switch state {
|
|
52
|
+
case .default: return Colors.blue10
|
|
53
|
+
case .warning: return Colors.yellow09
|
|
54
|
+
case .error: return Colors.red10
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private var accentColor: Color {
|
|
59
|
+
switch state {
|
|
60
|
+
case .default: return Colors.blue03
|
|
61
|
+
case .warning: return Colors.orange03
|
|
62
|
+
case .error: return Colors.red03
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
private var iconSource: String {
|
|
67
|
+
switch state {
|
|
68
|
+
case .default: return "notifications_info"
|
|
69
|
+
case .warning: return "24_notifications_alert_triangle"
|
|
70
|
+
case .error: return "24_notifications_alert_octagon"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public var body: some View {
|
|
75
|
+
VStack(alignment: .leading, spacing: 0) {
|
|
76
|
+
HStack(alignment: .top, spacing: 0) {
|
|
77
|
+
if let image {
|
|
78
|
+
ImageView(image)
|
|
79
|
+
.frame(width: 40, height: 40)
|
|
80
|
+
.clipShape(RoundedRectangle(cornerRadius: Radius.S))
|
|
81
|
+
.padding(.trailing, Spacing.S)
|
|
82
|
+
} else if showIcon {
|
|
83
|
+
Icon(source: iconSource, size: 16, color: accentColor)
|
|
84
|
+
.padding(.trailing, Spacing.S)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
VStack(alignment: .leading, spacing: 0) {
|
|
88
|
+
if let title {
|
|
89
|
+
MomoText(title, typography: .labelDefaultMedium)
|
|
90
|
+
}
|
|
91
|
+
MomoText(description, typography: .descriptionDefaultRegular)
|
|
92
|
+
}
|
|
93
|
+
.frame(maxWidth: .infinity, alignment: .leading)
|
|
94
|
+
|
|
95
|
+
if let onPressClose, showIconClose {
|
|
96
|
+
Icon(source: "navigation_close", size: 16, color: Colors.black17)
|
|
97
|
+
.contentShape(Rectangle())
|
|
98
|
+
.onTapGesture(perform: onPressClose)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if let action, let onPressAction {
|
|
103
|
+
MomoText(action, typography: .actionXsBold, color: accentColor)
|
|
104
|
+
.frame(maxWidth: .infinity, alignment: .trailing)
|
|
105
|
+
.contentShape(Rectangle())
|
|
106
|
+
.onTapGesture(perform: onPressAction)
|
|
107
|
+
.padding(.top, Spacing.S)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
.padding(Spacing.M)
|
|
111
|
+
.background(
|
|
112
|
+
RoundedRectangle(cornerRadius: Radius.S)
|
|
113
|
+
.fill(backgroundColor)
|
|
114
|
+
)
|
|
115
|
+
.overlay(
|
|
116
|
+
RoundedRectangle(cornerRadius: Radius.S)
|
|
117
|
+
.stroke(borderColor, lineWidth: 0.5)
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// MARK: - Preview
|
|
123
|
+
#if DEBUG
|
|
124
|
+
struct Information_Previews: PreviewProvider {
|
|
125
|
+
static var previews: some View {
|
|
126
|
+
VStack(spacing: 16) {
|
|
127
|
+
Information(
|
|
128
|
+
title: "Information",
|
|
129
|
+
description: "This is a default information message."
|
|
130
|
+
)
|
|
131
|
+
Information(
|
|
132
|
+
title: "Warning",
|
|
133
|
+
description: "This is a warning message.",
|
|
134
|
+
state: .warning
|
|
135
|
+
)
|
|
136
|
+
Information(
|
|
137
|
+
title: "Error",
|
|
138
|
+
description: "This is an error message.",
|
|
139
|
+
state: .error,
|
|
140
|
+
onPressAction: {}, action: "Retry"
|
|
141
|
+
)
|
|
142
|
+
Information(
|
|
143
|
+
description: "Dismissible information.",
|
|
144
|
+
onPressClose: {}
|
|
145
|
+
)
|
|
146
|
+
}
|
|
147
|
+
.padding()
|
|
148
|
+
.previewLayout(.sizeThatFits)
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
#endif
|
package/ios/Input/Input.swift
CHANGED
|
@@ -157,6 +157,7 @@ public struct Input: View {
|
|
|
157
157
|
})
|
|
158
158
|
.keyboardType(keyboardType)
|
|
159
159
|
.font(fontWeight == .bold ? .action_s_bold : .body_default_regular)
|
|
160
|
+
.ignoreBoldTextSetting()
|
|
160
161
|
.foregroundColor(getTextColor())
|
|
161
162
|
.disabled(disabled || readOnly)
|
|
162
163
|
.applyPrimaryCursorColor()
|
|
@@ -168,6 +168,7 @@ public struct InputSearch: View {
|
|
|
168
168
|
Text(placeholder)
|
|
169
169
|
.foregroundColor(disabled ? Colors.black08 : Colors.black12)
|
|
170
170
|
.font(.system(size: 16, weight: fontWeight))
|
|
171
|
+
.ignoreBoldTextSetting()
|
|
171
172
|
}
|
|
172
173
|
TextField("", text: $text, onEditingChanged: { editing in
|
|
173
174
|
isFocused = editing
|
|
@@ -183,6 +184,7 @@ public struct InputSearch: View {
|
|
|
183
184
|
.disabled(disabled)
|
|
184
185
|
.foregroundColor(disabled ? Colors.black08 : Colors.black17)
|
|
185
186
|
.font(.system(size: 15, weight: fontWeight))
|
|
187
|
+
.ignoreBoldTextSetting()
|
|
186
188
|
.keyboardType(keyboardType)
|
|
187
189
|
}
|
|
188
190
|
|
|
@@ -212,6 +214,7 @@ public struct InputSearch: View {
|
|
|
212
214
|
Text(buttonText)
|
|
213
215
|
.foregroundColor(Colors.black17)
|
|
214
216
|
.font(.system(size: 14, weight: .medium))
|
|
217
|
+
.ignoreBoldTextSetting()
|
|
215
218
|
}
|
|
216
219
|
.padding(.leading, Spacing.L)
|
|
217
220
|
}
|
|
@@ -22,7 +22,7 @@ public struct KeyboardButton: View {
|
|
|
22
22
|
public var body: some View {
|
|
23
23
|
SwiftUI.Button(action: { self.action(key) }) {
|
|
24
24
|
HStack {
|
|
25
|
-
Text(key).font(.system(size: 24, weight: .bold))
|
|
25
|
+
Text(key).font(.system(size: 24, weight: .bold)).ignoreBoldTextSetting()
|
|
26
26
|
}.frame(maxWidth: CGFloat(width), minHeight: height)
|
|
27
27
|
.background(color)
|
|
28
28
|
.foregroundColor(textColor)
|
|
@@ -24,6 +24,7 @@ extension View {
|
|
|
24
24
|
VStack(spacing: 0) {
|
|
25
25
|
Text("A")
|
|
26
26
|
.font(font)
|
|
27
|
+
.ignoreBoldTextSetting()
|
|
27
28
|
.lineLimit(1)
|
|
28
29
|
.fixedSize()
|
|
29
30
|
.background(
|
|
@@ -35,6 +36,7 @@ extension View {
|
|
|
35
36
|
|
|
36
37
|
Text("A\nA")
|
|
37
38
|
.font(font)
|
|
39
|
+
.ignoreBoldTextSetting()
|
|
38
40
|
.lineLimit(2)
|
|
39
41
|
.fixedSize(horizontal: false, vertical: true)
|
|
40
42
|
.background(
|
|
@@ -221,12 +223,14 @@ public struct PopupDisplay: View {
|
|
|
221
223
|
SwiftUI.Button(action: onPressCloseButton) {
|
|
222
224
|
Text(closeButtonTitle)
|
|
223
225
|
.font(.action2)
|
|
226
|
+
.ignoreBoldTextSetting()
|
|
224
227
|
}.foregroundColor(Colors.black09)
|
|
225
228
|
.padding(.trailing, 12)
|
|
226
229
|
|
|
227
230
|
SwiftUI.Button(action: onPressAction) {
|
|
228
231
|
Text(actionButtonTitle)
|
|
229
232
|
.font(.action2)
|
|
233
|
+
.ignoreBoldTextSetting()
|
|
230
234
|
}.foregroundColor(Colors.primary)
|
|
231
235
|
}
|
|
232
236
|
.frame(maxWidth: .infinity, alignment: .trailing)
|
|
@@ -238,12 +242,14 @@ public struct PopupDisplay: View {
|
|
|
238
242
|
SwiftUI.Button(action: onPressAction) {
|
|
239
243
|
Text(actionButtonTitle)
|
|
240
244
|
.font(.action2)
|
|
245
|
+
.ignoreBoldTextSetting()
|
|
241
246
|
}.foregroundColor(Colors.primary)
|
|
242
247
|
.padding(.bottom, 6)
|
|
243
248
|
|
|
244
249
|
SwiftUI.Button(action: onPressCloseButton) {
|
|
245
250
|
Text(closeButtonTitle)
|
|
246
251
|
.font(.action2)
|
|
252
|
+
.ignoreBoldTextSetting()
|
|
247
253
|
}.foregroundColor(Colors.black09)
|
|
248
254
|
}
|
|
249
255
|
.frame(maxWidth: .infinity, alignment: .trailing)
|
|
@@ -38,12 +38,14 @@ public struct PopupInput: View {
|
|
|
38
38
|
Text(title)
|
|
39
39
|
.foregroundColor(.black)
|
|
40
40
|
.font(.headerText1)
|
|
41
|
+
.ignoreBoldTextSetting()
|
|
41
42
|
.padding(.top, 12)
|
|
42
43
|
.padding(.bottom, 24)
|
|
43
44
|
|
|
44
45
|
Text(description)
|
|
45
46
|
.foregroundColor(.black)
|
|
46
47
|
.font(.paragraph)
|
|
48
|
+
.ignoreBoldTextSetting()
|
|
47
49
|
.opacity(0.6)
|
|
48
50
|
.multilineTextAlignment(.leading)
|
|
49
51
|
.padding(.bottom, 20)
|
|
@@ -79,6 +79,7 @@ public struct TrustBanner: View {
|
|
|
79
79
|
.foregroundColor(Color(hex: "484848"))
|
|
80
80
|
.lineLimit(2)
|
|
81
81
|
.font(.system(size: 13, weight: Font.Weight.regular))
|
|
82
|
+
.ignoreBoldTextSetting()
|
|
82
83
|
.lineSpacing(3)
|
|
83
84
|
.padding(.bottom, 8)
|
|
84
85
|
HStack {
|
|
@@ -86,6 +87,7 @@ public struct TrustBanner: View {
|
|
|
86
87
|
Text(applicationEnvironment.config?.trustBanner?.subContent[language ?? "vi"] as? String ?? defaultBanner.subContent[language ?? "vi"])
|
|
87
88
|
.foregroundColor(Colors.pink03)
|
|
88
89
|
.font(.system(size: 13, weight: .bold))
|
|
90
|
+
.ignoreBoldTextSetting()
|
|
89
91
|
.padding(.trailing, 4)
|
|
90
92
|
|
|
91
93
|
Icon(source: "arrow_chevron_right_small", color: Colors.pink03)
|
|
@@ -1,27 +1,30 @@
|
|
|
1
1
|
import SwiftUI
|
|
2
2
|
|
|
3
3
|
public func scaleSize(_ size: CGFloat, _ scaleRate: CGFloat? = nil) -> CGFloat {
|
|
4
|
+
let config = FontScaleStore.shared.config
|
|
4
5
|
let defaultScreenSize: CGFloat = 375
|
|
5
6
|
let maxFontScale: CGFloat = scaleRate ?? 1.5
|
|
6
7
|
let maxDeviceScale: CGFloat = 5
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
10
15
|
|
|
11
16
|
let defaultFont = UIFont.systemFont(ofSize: UIFont.labelFontSize)
|
|
12
17
|
let scaledFont = UIFontMetrics.default.scaledFont(for: defaultFont)
|
|
13
|
-
let
|
|
18
|
+
let osFontScale = scaledFont.pointSize / defaultFont.pointSize
|
|
14
19
|
|
|
15
20
|
var fontSizeDeviceScale = size
|
|
16
21
|
var fontSizeOSScale = size
|
|
17
22
|
|
|
18
|
-
|
|
19
23
|
if deviceScale > 1 {
|
|
20
24
|
fontSizeDeviceScale = min(fontSizeDeviceScale * deviceScale, fontSizeDeviceScale + maxDeviceScale)
|
|
21
25
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
fontSizeOSScale = min(fontSizeOSScale * fontScale, fontSizeOSScale * maxFontScale)
|
|
26
|
+
if osFontScale > 1 {
|
|
27
|
+
fontSizeOSScale = min(fontSizeOSScale * osFontScale, fontSizeOSScale * maxFontScale)
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
return max(fontSizeDeviceScale, fontSizeOSScale)
|
|
@@ -118,6 +121,7 @@ public struct MomoText: View {
|
|
|
118
121
|
private let content: String
|
|
119
122
|
private let typography: TypographyStyle
|
|
120
123
|
private let color: Color
|
|
124
|
+
@ObservedObject private var fontScale = FontScaleStore.shared
|
|
121
125
|
|
|
122
126
|
public init(
|
|
123
127
|
_ content: String,
|
|
@@ -130,11 +134,13 @@ public struct MomoText: View {
|
|
|
130
134
|
}
|
|
131
135
|
|
|
132
136
|
public var body: some View {
|
|
137
|
+
_ = fontScale.config
|
|
133
138
|
let text = SwiftUI.Text(content)
|
|
134
139
|
.font(.system(size: scaleSize(typography.fontSize), weight: typography.fontWeight))
|
|
135
140
|
.foregroundColor(color)
|
|
136
141
|
.lineSpacing(scaleSize(typography.lineHeight) - scaleSize(typography.fontSize))
|
|
137
142
|
|
|
138
143
|
return text
|
|
144
|
+
.ignoreBoldTextSetting()
|
|
139
145
|
}
|
|
140
146
|
}
|
|
@@ -1,26 +1,40 @@
|
|
|
1
1
|
import SwiftUI
|
|
2
2
|
|
|
3
|
+
public extension View {
|
|
4
|
+
/// Forces SwiftUI to ignore the OS "Bold Text" accessibility setting so the
|
|
5
|
+
/// kit's typography weight stays fixed and matches the Compose implementation
|
|
6
|
+
/// (which does not honor that OS setting). Apply it wherever a `.font(...)` is set.
|
|
7
|
+
func ignoreBoldTextSetting() -> some View {
|
|
8
|
+
environment(\.legibilityWeight, .regular)
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
3
12
|
public extension Font {
|
|
4
13
|
static func appFont(size: CGFloat) -> Font {
|
|
14
|
+
let config = FontScaleStore.shared.config
|
|
5
15
|
let defaultScreenSize: CGFloat = 375
|
|
6
16
|
let maxFontScale: CGFloat = 1.5
|
|
7
17
|
let maxDeviceScale: CGFloat = 5
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
18
|
+
|
|
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
|
|
26
|
+
|
|
12
27
|
let defaultFont = UIFont.systemFont(ofSize: UIFont.labelFontSize)
|
|
13
28
|
let scaledFont = UIFontMetrics.default.scaledFont(for: defaultFont)
|
|
14
|
-
let
|
|
29
|
+
let osFontScale = scaledFont.pointSize / defaultFont.pointSize
|
|
15
30
|
|
|
16
31
|
var fontSize = size
|
|
17
32
|
|
|
18
33
|
if deviceScale > 1 {
|
|
19
34
|
fontSize = min(fontSize * deviceScale, fontSize + maxDeviceScale)
|
|
20
35
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
fontSize = min(fontSize * fontScale, fontSize * maxFontScale)
|
|
36
|
+
if osFontScale > 1 {
|
|
37
|
+
fontSize = min(fontSize * osFontScale, fontSize * maxFontScale)
|
|
24
38
|
}
|
|
25
39
|
|
|
26
40
|
return Font.system(size: fontSize)
|