Skip to content

Commit dfa97e1

Browse files
committed
feat(TextField): allow custom styles for TextField
1 parent 466e7eb commit dfa97e1

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

ios/components/TextField/TextFieldProps.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ public final class TextFieldProps: ObservableObject, Decodable {
1414
@Published public var secure: Bool = false
1515
@Published public var multiline: Bool = false
1616
@Published public var disabled: Bool = false
17+
@Published public var style: StyleProps?
1718
// Events
1819
public var onChange: ((String) -> Void)?
1920
public var onFocus: (() -> Void)?
2021
public var onBlur: (() -> Void)?
2122

2223
enum CodingKeys: String, CodingKey {
23-
case text, label, placeholder, keyboardType, textContentType, returnKeyType, autocapitalizationType, maxLength, secure, multiline, disabled
24+
case text, label, placeholder, keyboardType, textContentType, returnKeyType, autocapitalizationType, maxLength, secure, multiline, disabled, style
2425
}
2526

2627
public required init(from decoder: Decoder) throws {
@@ -58,7 +59,7 @@ public final class TextFieldProps: ObservableObject, Decodable {
5859
// Decode autocapitalizationType
5960
if let autocapitalizationTypeString = try container.decodeIfPresent(String.self, forKey: .autocapitalizationType) {
6061
switch autocapitalizationTypeString {
61-
case "none": autocapitalizationType = .none
62+
case "none": autocapitalizationType = UITextAutocapitalizationType.none
6263
case "words": autocapitalizationType = .words
6364
case "sentences": autocapitalizationType = .sentences
6465
case "allCharacters": autocapitalizationType = .allCharacters
@@ -69,6 +70,7 @@ public final class TextFieldProps: ObservableObject, Decodable {
6970
secure = try container.decodeIfPresent(Bool.self, forKey: .secure) ?? false
7071
multiline = try container.decodeIfPresent(Bool.self, forKey: .multiline) ?? false
7172
disabled = try container.decodeIfPresent(Bool.self, forKey: .disabled) ?? false
73+
style = try container.decodeIfPresent(StyleProps.self, forKey: .style)
7274

7375
if maxLength != nil {
7476
text = enforceMaxLength(text)
@@ -94,5 +96,6 @@ public final class TextFieldProps: ObservableObject, Decodable {
9496
secure = other.secure
9597
multiline = other.multiline
9698
disabled = other.disabled
99+
style = other.style
97100
}
98101
}

ios/components/TextField/TextFieldView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public struct TextFieldView: View {
3939
}
4040
}
4141
.keyboardType(props.keyboardType)
42-
.disabled(props.disabled).foregroundColor(props.disabled ? .gray : .primary)
4342
.focused($isFocused)
4443
// .toolbar {
4544
// ToolbarItemGroup(placement: .keyboard) {
@@ -49,6 +48,8 @@ public struct TextFieldView: View {
4948
// }
5049
// }
5150
// }
51+
.applyStyles(props.style)
52+
.disabled(props.disabled).foregroundStyle(props.disabled ? .gray : .primary)
5253
.onChange(of: isFocused) { newValue in
5354
newValue ? props.onFocus?() : props.onBlur?()
5455
}

0 commit comments

Comments
 (0)