@@ -3,26 +3,26 @@ import SwiftUI
3
3
4
4
struct KeyValueFormViewExample : View {
5
5
var key1 : AttributedString {
6
- var aString = AttributedString ( " Key 1 " )
6
+ let aString = AttributedString ( " Key 1 " )
7
7
return aString
8
8
}
9
9
10
10
var key1Long : AttributedString {
11
- var aString = AttributedString ( " Long Key 1 Long Key 1 Long Key 1 Long Key 1 Long Key 1 Long Key 1 Long Key 1 Long Key 1 Long Key 1 Long Key 1 " )
11
+ let aString = AttributedString ( " Long Key 1 Long Key 1 Long Key 1 Long Key 1 Long Key 1 Long Key 1 Long Key 1 Long Key 1 Long Key 1 Long Key 1 " )
12
12
return aString
13
13
}
14
14
15
15
@State var valueText1 : String = " 1234567890 12345678 "
16
16
17
17
var key2 : AttributedString {
18
- var aString = AttributedString ( " Key 2 " )
18
+ let aString = AttributedString ( " Key 2 " )
19
19
return aString
20
20
}
21
21
22
22
@State var valueText2 : String = " This is a test "
23
23
24
24
var key3 : AttributedString {
25
- var aString = AttributedString ( " Key 3 " )
25
+ let aString = AttributedString ( " Key 3 " )
26
26
return aString
27
27
}
28
28
@@ -65,8 +65,13 @@ struct KeyValueFormViewExample: View {
65
65
Toggle ( " Mandatory Field " , isOn: self . $isRequired)
66
66
. padding ( . leading, 16 )
67
67
. padding ( . trailing, 16 )
68
+ Button ( " Dismiss Keyboard " ) {
69
+ hideKeyboard ( )
70
+ }
71
+ . padding ( . leading, 16 )
72
+ . padding ( . trailing, 16 )
68
73
69
- Text ( " Default KeyValueFormView " )
74
+ Text ( " Default KeyValueForm " )
70
75
KeyValueFormView ( title: self . key1, text: self . $valueText1, placeholder: " KeyValueFormView " , errorMessage: self . getErrorMessage ( ) , maxTextLength: self . getMaxTextLength ( ) , hintText: self . getHintText ( ) , isCharCountEnabled: self . showsCharCount, allowsBeyondLimit: self . allowsBeyondLimit, isRequired: self . isRequired)
71
76
72
77
Text ( " Existing Text " )
@@ -104,6 +109,14 @@ struct KeyValueFormViewExample: View {
104
109
}
105
110
}
106
111
112
+ #if canImport(UIKit)
113
+ extension View {
114
+ func hideKeyboard( ) {
115
+ UIApplication . shared. sendAction ( #selector( UIResponder . resignFirstResponder) , to: nil , from: nil , for: nil )
116
+ }
117
+ }
118
+ #endif
119
+
107
120
// #Preview {
108
121
// KeyValueFormViewExample()
109
122
// }
0 commit comments