@momo-kits/native-kits 0.159.1-beta.14-debug → 0.159.1-beta.15-debug
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/compose/build.gradle.kts +1 -1
- package/ios/Input/Input.swift +28 -4
- package/package.json +1 -1
package/compose/build.gradle.kts
CHANGED
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
|
|
@@ -92,8 +95,9 @@ public struct Input: View {
|
|
|
92
95
|
let textBinding = Binding<String>(
|
|
93
96
|
get: { self.text },
|
|
94
97
|
set: { newValue in
|
|
95
|
-
|
|
96
|
-
self.
|
|
98
|
+
let limitedText = limitText(newValue)
|
|
99
|
+
self.text = limitedText
|
|
100
|
+
self.onChangeText?(limitedText)
|
|
97
101
|
}
|
|
98
102
|
)
|
|
99
103
|
|
|
@@ -142,6 +146,7 @@ public struct Input: View {
|
|
|
142
146
|
fontWeight: fontWeight == .bold ? .bold : .regular,
|
|
143
147
|
textColor: UIColor(getTextColor()),
|
|
144
148
|
isDisabled: disabled || readOnly,
|
|
149
|
+
maxLength: maxLength,
|
|
145
150
|
onFocusChange: { focused in
|
|
146
151
|
handleFocusChange(focused)
|
|
147
152
|
},
|
|
@@ -239,6 +244,13 @@ public struct Input: View {
|
|
|
239
244
|
isPasswordHidden.toggle()
|
|
240
245
|
onRightIconPressed?()
|
|
241
246
|
}
|
|
247
|
+
|
|
248
|
+
private func limitText(_ value: String) -> String {
|
|
249
|
+
guard let maxLength = maxLength else {
|
|
250
|
+
return value
|
|
251
|
+
}
|
|
252
|
+
return String(value.prefix(maxLength))
|
|
253
|
+
}
|
|
242
254
|
|
|
243
255
|
private func borderColor() -> Color {
|
|
244
256
|
if disabled {
|
|
@@ -279,6 +291,7 @@ private struct SecureInputField: UIViewRepresentable {
|
|
|
279
291
|
var fontWeight: UIFont.Weight
|
|
280
292
|
var textColor: UIColor
|
|
281
293
|
var isDisabled: Bool
|
|
294
|
+
var maxLength: Int?
|
|
282
295
|
var onFocusChange: (Bool) -> Void
|
|
283
296
|
var onChangeText: ((String) -> Void)?
|
|
284
297
|
|
|
@@ -307,6 +320,7 @@ private struct SecureInputField: UIViewRepresentable {
|
|
|
307
320
|
}
|
|
308
321
|
|
|
309
322
|
func updateUIView(_ textField: UITextField, context: Context) {
|
|
323
|
+
context.coordinator.parent = self
|
|
310
324
|
if textField.text != text {
|
|
311
325
|
textField.text = text
|
|
312
326
|
}
|
|
@@ -342,7 +356,7 @@ private struct SecureInputField: UIViewRepresentable {
|
|
|
342
356
|
}
|
|
343
357
|
|
|
344
358
|
func textFieldDidEndEditing(_ textField: UITextField) {
|
|
345
|
-
parent.text = textField.text ?? ""
|
|
359
|
+
parent.text = limitText(textField.text ?? "")
|
|
346
360
|
parent.onFocusChange(false)
|
|
347
361
|
}
|
|
348
362
|
|
|
@@ -357,7 +371,10 @@ private struct SecureInputField: UIViewRepresentable {
|
|
|
357
371
|
|
|
358
372
|
@objc func textFieldDidChange(_ textField: UITextField) {
|
|
359
373
|
if isResettingText { return }
|
|
360
|
-
let newText = textField.text ?? ""
|
|
374
|
+
let newText = limitText(textField.text ?? "")
|
|
375
|
+
if textField.text != newText {
|
|
376
|
+
textField.text = newText
|
|
377
|
+
}
|
|
361
378
|
parent.text = newText
|
|
362
379
|
parent.onChangeText?(newText)
|
|
363
380
|
}
|
|
@@ -366,6 +383,13 @@ private struct SecureInputField: UIViewRepresentable {
|
|
|
366
383
|
textField.resignFirstResponder()
|
|
367
384
|
return true
|
|
368
385
|
}
|
|
386
|
+
|
|
387
|
+
private func limitText(_ value: String) -> String {
|
|
388
|
+
guard let maxLength = parent.maxLength else {
|
|
389
|
+
return value
|
|
390
|
+
}
|
|
391
|
+
return String(value.prefix(maxLength))
|
|
392
|
+
}
|
|
369
393
|
}
|
|
370
394
|
}
|
|
371
395
|
|