@@ -41,17 +41,12 @@ public struct SearchBar: View {
41
41
private let searchFieldPadding : CGFloat
42
42
private let searchFieldMargin : CGFloat
43
43
44
- public var hasText : Bool {
45
- !text. wrappedValue. isEmpty
46
- }
47
-
48
44
public var body : some View {
49
45
VStack ( spacing: 0 ) {
50
46
HStack {
51
47
searchField
52
48
cancelButton
53
49
} . padding ( searchFieldMargin)
54
- Divider ( )
55
50
}
56
51
}
57
52
}
@@ -61,6 +56,10 @@ public struct SearchBar: View {
61
56
62
57
private extension SearchBar {
63
58
59
+ var hasText : Bool {
60
+ !text. wrappedValue. isEmpty
61
+ }
62
+
64
63
@ViewBuilder
65
64
var cancelButton : some View {
66
65
if hasText {
@@ -75,7 +74,8 @@ private extension SearchBar {
75
74
var searchField : some View {
76
75
HStack {
77
76
Image ( systemName: " magnifyingglass " )
78
- TextField ( title, text: text) . withClearButton ( for: text)
77
+ TextField ( title, text: text)
78
+ . withClearButton ( for: text)
79
79
}
80
80
. padding ( searchFieldPadding)
81
81
. background ( searchFieldBackground)
@@ -95,11 +95,19 @@ private extension SearchBar {
95
95
}
96
96
97
97
struct SearchBar_Previews : PreviewProvider {
98
-
99
- @State static var text = " "
98
+
99
+ struct Preview : View {
100
+
101
+ @State
102
+ var text = " "
103
+
104
+ var body : some View {
105
+ SearchBar ( title: " Search " , text: $text, cancelText: " Cancel " )
106
+ }
107
+ }
100
108
101
109
static var previews : some View {
102
- SearchBar ( title : " Search " , text : $text , cancelText : " Cancel " )
110
+ Preview ( )
103
111
}
104
112
}
105
113
#endif
0 commit comments