@momo-kits/native-kits 0.167.1-beta.20 → 0.167.1-beta.21
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/Badge/BadgeRibbon.swift +2 -1
- package/ios/Input/Input.swift +2 -2
- package/ios/Input/InputPhoneNumber.swift +1 -1
- package/ios/Input/InputSearch.swift +2 -3
- package/ios/Input/InputTextArea.swift +5 -4
- package/ios/InputMoney/InputMoney.swift +10 -2
- package/ios/Stepper/Stepper.swift +1 -2
- package/ios/Typography/Text.swift +48 -0
- package/ios/native-kits.podspec +1 -1
- package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
- package/package.json +1 -1
|
@@ -204,6 +204,7 @@ public struct BadgeRibbon: View {
|
|
|
204
204
|
/// rotation) — the label gets the same scale applied a second time so it stays right-reading
|
|
205
205
|
/// while only the ribbon shape flips.
|
|
206
206
|
public struct RoundedBadgeRibbon: View {
|
|
207
|
+
@Environment(\.appTheme) private var theme
|
|
207
208
|
@Environment(\.momoFontScale) private var fontScale
|
|
208
209
|
let text: String
|
|
209
210
|
let position: RibbonPosition
|
|
@@ -224,7 +225,7 @@ public struct RoundedBadgeRibbon: View {
|
|
|
224
225
|
|
|
225
226
|
private var measuredTextSize: CGSize {
|
|
226
227
|
let fontSize = fontScale(TypographyStyle.labelXsMedium.fontSize)
|
|
227
|
-
let font =
|
|
228
|
+
let font = momoUIFont(size: fontSize, weight: .medium, family: theme.font)
|
|
228
229
|
return text.size(withAttributes: [.font: font])
|
|
229
230
|
}
|
|
230
231
|
|
package/ios/Input/Input.swift
CHANGED
|
@@ -181,7 +181,7 @@ public struct Input: View {
|
|
|
181
181
|
handleFocusChange(focused)
|
|
182
182
|
})
|
|
183
183
|
.keyboardType(keyboardType)
|
|
184
|
-
.
|
|
184
|
+
.kitFont(fontWeight == .bold ? .actionSBold : .bodyDefaultRegular)
|
|
185
185
|
.ignoreBoldTextSetting()
|
|
186
186
|
.foregroundColor(getTextColor())
|
|
187
187
|
.disabled(disabled || readOnly)
|
|
@@ -349,7 +349,7 @@ private struct SecureInputField: UIViewRepresentable {
|
|
|
349
349
|
textField.isSecureTextEntry = true
|
|
350
350
|
textField.delegate = context.coordinator
|
|
351
351
|
textField.keyboardType = keyboardType
|
|
352
|
-
textField.font =
|
|
352
|
+
textField.font = momoUIFont(size: fontSize, weight: fontWeight, family: context.environment.appTheme.font)
|
|
353
353
|
textField.textColor = textColor
|
|
354
354
|
textField.isEnabled = !isDisabled
|
|
355
355
|
textField.setContentHuggingPriority(.defaultLow, for: .horizontal)
|
|
@@ -105,7 +105,7 @@ public struct InputPhoneNumber: View {
|
|
|
105
105
|
handleFocusChange(focused)
|
|
106
106
|
})
|
|
107
107
|
.keyboardType(.numberPad)
|
|
108
|
-
.
|
|
108
|
+
.kitFont(size == .small ? .headerSSemibold : .headerMBold)
|
|
109
109
|
.ignoreBoldTextSetting()
|
|
110
110
|
.foregroundColor(theme.colors.text.default)
|
|
111
111
|
.applyCursorColor(theme.colors.primary)
|
|
@@ -104,7 +104,6 @@ public struct InputSearchProps {
|
|
|
104
104
|
|
|
105
105
|
public struct InputSearch: View {
|
|
106
106
|
@Environment(\.appTheme) private var theme
|
|
107
|
-
@Environment(\.momoFontScale) private var fontScale
|
|
108
107
|
@Binding var text: String
|
|
109
108
|
var buttonText: String = ""
|
|
110
109
|
var showButtonText: Bool = false
|
|
@@ -215,7 +214,7 @@ public struct InputSearch: View {
|
|
|
215
214
|
} else {
|
|
216
215
|
Text(placeholder)
|
|
217
216
|
.foregroundColor(disabled ? theme.colors.text.disable : theme.colors.text.hint)
|
|
218
|
-
.
|
|
217
|
+
.kitFont(size: 14, weight: fontWeight)
|
|
219
218
|
.ignoreBoldTextSetting()
|
|
220
219
|
}
|
|
221
220
|
}
|
|
@@ -232,7 +231,7 @@ public struct InputSearch: View {
|
|
|
232
231
|
}, onCommit: {})
|
|
233
232
|
.disabled(disabled)
|
|
234
233
|
.foregroundColor(disabled ? theme.colors.text.disable : theme.colors.text.default)
|
|
235
|
-
.
|
|
234
|
+
.kitFont(size: 14, weight: fontWeight)
|
|
236
235
|
.ignoreBoldTextSetting()
|
|
237
236
|
.keyboardType(keyboardType)
|
|
238
237
|
.applyCursorColor(theme.colors.primary)
|
|
@@ -39,9 +39,10 @@ struct UITextViewWrapper: UIViewRepresentable {
|
|
|
39
39
|
uiView.tintColor = UIColor(cursorColor)
|
|
40
40
|
// Read through `context.environment` rather than the global `scaleSize`: that is what makes
|
|
41
41
|
// SwiftUI re-run updateUIView when the font scale changes.
|
|
42
|
-
uiView.font =
|
|
43
|
-
|
|
44
|
-
weight: fontWeight == .bold ? .bold : .regular
|
|
42
|
+
uiView.font = momoUIFont(
|
|
43
|
+
size: context.environment.momoFontScale(16),
|
|
44
|
+
weight: fontWeight == .bold ? .bold : .regular,
|
|
45
|
+
family: context.environment.appTheme.font
|
|
45
46
|
)
|
|
46
47
|
uiView.isEditable = !disabled
|
|
47
48
|
}
|
|
@@ -210,7 +211,7 @@ public struct InputTextArea: View {
|
|
|
210
211
|
if text.isEmpty {
|
|
211
212
|
Text(placeholder)
|
|
212
213
|
.foregroundColor(disabled ? theme.colors.text.disable : theme.colors.text.hint)
|
|
213
|
-
.
|
|
214
|
+
.kitFont(size: 16, weight: fontWeight)
|
|
214
215
|
.padding(.horizontal, 16)
|
|
215
216
|
.padding(.vertical, 12)
|
|
216
217
|
}
|
|
@@ -315,7 +315,11 @@ private struct MoneyTextField: UIViewRepresentable {
|
|
|
315
315
|
let field = UITextField()
|
|
316
316
|
field.delegate = context.coordinator
|
|
317
317
|
field.keyboardType = keyboardType
|
|
318
|
-
field.font =
|
|
318
|
+
field.font = momoUIFont(
|
|
319
|
+
size: context.environment.momoFontScale(20),
|
|
320
|
+
weight: fontWeight,
|
|
321
|
+
family: context.environment.appTheme.font
|
|
322
|
+
)
|
|
319
323
|
field.textColor = textColor
|
|
320
324
|
field.isEnabled = !isDisabled
|
|
321
325
|
field.tintColor = cursorColor
|
|
@@ -328,7 +332,11 @@ private struct MoneyTextField: UIViewRepresentable {
|
|
|
328
332
|
func updateUIView(_ field: UITextField, context: Context) {
|
|
329
333
|
context.coordinator.parent = self
|
|
330
334
|
// Re-applied here, not just in makeUIView, so a font-scale change reaches an existing field.
|
|
331
|
-
field.font =
|
|
335
|
+
field.font = momoUIFont(
|
|
336
|
+
size: context.environment.momoFontScale(20),
|
|
337
|
+
weight: fontWeight,
|
|
338
|
+
family: context.environment.appTheme.font
|
|
339
|
+
)
|
|
332
340
|
field.isEnabled = !isDisabled
|
|
333
341
|
field.textColor = textColor
|
|
334
342
|
field.tintColor = cursorColor
|
|
@@ -84,7 +84,6 @@ private struct StepperButton: View {
|
|
|
84
84
|
|
|
85
85
|
private struct StepperNumberView: View {
|
|
86
86
|
@Environment(\.appTheme) private var theme
|
|
87
|
-
@Environment(\.momoFontScale) private var fontScale
|
|
88
87
|
|
|
89
88
|
@Binding var text: String
|
|
90
89
|
var size: StepperSize
|
|
@@ -106,7 +105,7 @@ private struct StepperNumberView: View {
|
|
|
106
105
|
MomoText(text, typography: .descriptionDefaultRegular, color: textColor)
|
|
107
106
|
}
|
|
108
107
|
}
|
|
109
|
-
.
|
|
108
|
+
.kitFont(size: 12)
|
|
110
109
|
.ignoreBoldTextSetting()
|
|
111
110
|
.foregroundColor(textColor)
|
|
112
111
|
.frame(minWidth: specs.numberMinWidth)
|
|
@@ -123,6 +123,54 @@ private func momoFont(size: CGFloat, weight: Font.Weight, family: String) -> Fon
|
|
|
123
123
|
return .custom(name, fixedSize: size)
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
+
/// UIKit counterpart of `momoFont`, for text that is not a `MomoText` (UITextField/UITextView, text measuring).
|
|
127
|
+
func momoUIFont(size: CGFloat, weight: UIFont.Weight, family: String) -> UIFont {
|
|
128
|
+
guard let name = momoFontName(family: family, weight: Font.Weight(weight)),
|
|
129
|
+
let font = UIFont(name: name, size: size) else {
|
|
130
|
+
return .systemFont(ofSize: size, weight: weight)
|
|
131
|
+
}
|
|
132
|
+
return font
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private extension Font.Weight {
|
|
136
|
+
init(_ weight: UIFont.Weight) {
|
|
137
|
+
switch weight {
|
|
138
|
+
case .ultraLight: self = .ultraLight
|
|
139
|
+
case .thin: self = .thin
|
|
140
|
+
case .light: self = .light
|
|
141
|
+
case .medium: self = .medium
|
|
142
|
+
case .semibold: self = .semibold
|
|
143
|
+
case .bold: self = .bold
|
|
144
|
+
case .heavy: self = .heavy
|
|
145
|
+
case .black: self = .black
|
|
146
|
+
default: self = .regular
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/// Gives input text the same family as `MomoText` (Compose's `getFontFamily`), e.g. a TextField
|
|
152
|
+
/// next to a `MomoText` placeholder. `size` is unscaled; the environment font scale is applied here.
|
|
153
|
+
private struct KitFontModifier: ViewModifier {
|
|
154
|
+
@Environment(\.appTheme) private var theme
|
|
155
|
+
@Environment(\.momoFontScale) private var fontScale
|
|
156
|
+
let size: CGFloat
|
|
157
|
+
let weight: Font.Weight
|
|
158
|
+
|
|
159
|
+
func body(content: Content) -> some View {
|
|
160
|
+
content.font(momoFont(size: fontScale(size), weight: weight, family: theme.font))
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
extension View {
|
|
165
|
+
func kitFont(_ typography: TypographyStyle) -> some View {
|
|
166
|
+
modifier(KitFontModifier(size: typography.fontSize, weight: typography.fontWeight))
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
func kitFont(size: CGFloat, weight: Font.Weight = .regular) -> some View {
|
|
170
|
+
modifier(KitFontModifier(size: size, weight: weight))
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
126
174
|
public struct MomoText: View {
|
|
127
175
|
@Environment(\.appTheme) private var theme
|
|
128
176
|
@Environment(\.momoFontScale) private var fontScale
|
package/ios/native-kits.podspec
CHANGED