@momo-kits/native-kits 0.160.5 → 0.160.6
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/Input/Input.swift +33 -4
- package/package.json +1 -1
package/ios/Input/Input.swift
CHANGED
|
@@ -22,6 +22,7 @@ public struct Input: View {
|
|
|
22
22
|
public var leadingIconColor: Color
|
|
23
23
|
public var loading: Bool
|
|
24
24
|
public var required: Bool
|
|
25
|
+
public var maxLength: Int?
|
|
25
26
|
public var fontWeight: InputFontWeight
|
|
26
27
|
public var keyboardType: UIKeyboardType
|
|
27
28
|
public var autofocus: Bool
|
|
@@ -52,6 +53,7 @@ public struct Input: View {
|
|
|
52
53
|
leadingIconColor: Color = Colors.black12,
|
|
53
54
|
loading: Bool = false,
|
|
54
55
|
required: Bool = false,
|
|
56
|
+
maxLength: Int? = nil,
|
|
55
57
|
fontWeight: InputFontWeight = .regular,
|
|
56
58
|
keyboardType: UIKeyboardType = .default,
|
|
57
59
|
autofocus: Bool = false,
|
|
@@ -78,6 +80,7 @@ public struct Input: View {
|
|
|
78
80
|
self.leadingIconColor = leadingIconColor
|
|
79
81
|
self.loading = loading
|
|
80
82
|
self.required = required
|
|
83
|
+
self.maxLength = maxLength
|
|
81
84
|
self.fontWeight = fontWeight
|
|
82
85
|
self.keyboardType = keyboardType
|
|
83
86
|
self.autofocus = autofocus
|
|
@@ -93,10 +96,10 @@ public struct Input: View {
|
|
|
93
96
|
get: { self.text },
|
|
94
97
|
set: { newValue in
|
|
95
98
|
self.text = newValue
|
|
96
|
-
self.onChangeText?(newValue)
|
|
99
|
+
self.onChangeText?(limitText(newValue))
|
|
97
100
|
}
|
|
98
101
|
)
|
|
99
|
-
|
|
102
|
+
|
|
100
103
|
VStack(alignment: .leading, spacing: 4) {
|
|
101
104
|
ZStack(alignment: .topLeading) {
|
|
102
105
|
// Floating label
|
|
@@ -142,6 +145,7 @@ public struct Input: View {
|
|
|
142
145
|
fontWeight: fontWeight == .bold ? .bold : .regular,
|
|
143
146
|
textColor: UIColor(getTextColor()),
|
|
144
147
|
isDisabled: disabled || readOnly,
|
|
148
|
+
maxLength: maxLength,
|
|
145
149
|
onFocusChange: { focused in
|
|
146
150
|
handleFocusChange(focused)
|
|
147
151
|
},
|
|
@@ -156,6 +160,12 @@ public struct Input: View {
|
|
|
156
160
|
.foregroundColor(getTextColor())
|
|
157
161
|
.disabled(disabled || readOnly)
|
|
158
162
|
.applyPrimaryCursorColor()
|
|
163
|
+
.onChange(of: text) { newValue in
|
|
164
|
+
let limited = limitText(newValue)
|
|
165
|
+
if limited != newValue {
|
|
166
|
+
text = limited
|
|
167
|
+
}
|
|
168
|
+
}
|
|
159
169
|
}
|
|
160
170
|
}
|
|
161
171
|
|
|
@@ -239,6 +249,13 @@ public struct Input: View {
|
|
|
239
249
|
isPasswordHidden.toggle()
|
|
240
250
|
onRightIconPressed?()
|
|
241
251
|
}
|
|
252
|
+
|
|
253
|
+
private func limitText(_ value: String) -> String {
|
|
254
|
+
guard let maxLength = maxLength else {
|
|
255
|
+
return value
|
|
256
|
+
}
|
|
257
|
+
return String(value.prefix(maxLength))
|
|
258
|
+
}
|
|
242
259
|
|
|
243
260
|
private func borderColor() -> Color {
|
|
244
261
|
if disabled {
|
|
@@ -279,6 +296,7 @@ private struct SecureInputField: UIViewRepresentable {
|
|
|
279
296
|
var fontWeight: UIFont.Weight
|
|
280
297
|
var textColor: UIColor
|
|
281
298
|
var isDisabled: Bool
|
|
299
|
+
var maxLength: Int?
|
|
282
300
|
var onFocusChange: (Bool) -> Void
|
|
283
301
|
var onChangeText: ((String) -> Void)?
|
|
284
302
|
|
|
@@ -307,6 +325,7 @@ private struct SecureInputField: UIViewRepresentable {
|
|
|
307
325
|
}
|
|
308
326
|
|
|
309
327
|
func updateUIView(_ textField: UITextField, context: Context) {
|
|
328
|
+
context.coordinator.parent = self
|
|
310
329
|
if textField.text != text {
|
|
311
330
|
textField.text = text
|
|
312
331
|
}
|
|
@@ -342,7 +361,7 @@ private struct SecureInputField: UIViewRepresentable {
|
|
|
342
361
|
}
|
|
343
362
|
|
|
344
363
|
func textFieldDidEndEditing(_ textField: UITextField) {
|
|
345
|
-
parent.text = textField.text ?? ""
|
|
364
|
+
parent.text = limitText(textField.text ?? "")
|
|
346
365
|
parent.onFocusChange(false)
|
|
347
366
|
}
|
|
348
367
|
|
|
@@ -357,7 +376,10 @@ private struct SecureInputField: UIViewRepresentable {
|
|
|
357
376
|
|
|
358
377
|
@objc func textFieldDidChange(_ textField: UITextField) {
|
|
359
378
|
if isResettingText { return }
|
|
360
|
-
let newText = textField.text ?? ""
|
|
379
|
+
let newText = limitText(textField.text ?? "")
|
|
380
|
+
if textField.text != newText {
|
|
381
|
+
textField.text = newText
|
|
382
|
+
}
|
|
361
383
|
parent.text = newText
|
|
362
384
|
parent.onChangeText?(newText)
|
|
363
385
|
}
|
|
@@ -366,6 +388,13 @@ private struct SecureInputField: UIViewRepresentable {
|
|
|
366
388
|
textField.resignFirstResponder()
|
|
367
389
|
return true
|
|
368
390
|
}
|
|
391
|
+
|
|
392
|
+
private func limitText(_ value: String) -> String {
|
|
393
|
+
guard let maxLength = parent.maxLength else {
|
|
394
|
+
return value
|
|
395
|
+
}
|
|
396
|
+
return String(value.prefix(maxLength))
|
|
397
|
+
}
|
|
369
398
|
}
|
|
370
399
|
}
|
|
371
400
|
|