-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSearchBar.swift
More file actions
58 lines (52 loc) · 1.88 KB
/
SearchBar.swift
File metadata and controls
58 lines (52 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//
// SearchBar.swift
// Food delivery
//
// Created by Usman Mukhtar on 21/07/2020.
//
import SwiftUI
struct SearchBar: View {
@Binding var text: String
@State private var isEditing = false
var body: some View {
HStack {
TextField("Search for a food", text: $text)
.padding(15)
.padding(.horizontal, 25)
.background(Color(.systemGray6))
.foregroundColor(Color("subfont"))
.cornerRadius(8)
.overlay(
HStack {
Image(systemName: "magnifyingglass")
.foregroundColor(Color("mainfont"))
.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
.padding(.leading, 15)
if isEditing {
Button(action: {
self.text = ""
}){
Image(systemName: "multiply.circle.fill")
.foregroundColor(.gray)
.padding(.trailing, 8)
}
}
}
).onTapGesture {
self.isEditing = true
}
if isEditing {
Button(action: {
self.isEditing = false
// self.text = ""
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
}){
Text("Cancel")
}
.padding(.trailing, 10)
.transition(.move(edge: .trailing))
.animation(.default)
}
}
}
}