-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ronan
committed
Mar 13, 2020
1 parent
52f3b14
commit dcee16e
Showing
5 changed files
with
113 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import Foundation | ||
import UIKit | ||
import SwiftUI | ||
|
||
struct SearchBar: UIViewRepresentable { | ||
|
||
@Binding var text: String | ||
|
||
class Coordinator: NSObject, UISearchBarDelegate { | ||
|
||
@Binding var text: String | ||
|
||
init(text: Binding<String>) { | ||
_text = text | ||
} | ||
|
||
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) { | ||
text = searchText | ||
} | ||
} | ||
func makeCoordinator() -> SearchBar.Coordinator { | ||
return Coordinator(text: $text) | ||
} | ||
|
||
func makeUIView(context: UIViewRepresentableContext<SearchBar>) -> UISearchBar { | ||
let searchBar = UISearchBar(frame: .zero) | ||
searchBar.searchBarStyle = .minimal | ||
searchBar.placeholder = "Search for a station" | ||
searchBar.delegate = context.coordinator | ||
searchBar.autocapitalizationType = .none | ||
searchBar.layoutMargins = UIEdgeInsets(top: 0.0, left: 5.0, bottom: 0.0, right: 0.0) | ||
return searchBar | ||
} | ||
|
||
func updateUIView(_ uiView: UISearchBar, context: UIViewRepresentableContext<SearchBar>) { | ||
uiView.text = text | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters