File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77
88import SwiftUI
99
10-
11- /**
12- Search bar at the top of the NavigationView.
13-
14- Source: [http://blog.eppz.eu/swiftui-search-bar-in-the-navigation-bar/]( http://blog.eppz.eu/swiftui-search-bar-in-the-navigation-bar/).
15-
16- MIT License
17- */
18- internal class SearchBarConfigurator : NSObject , ObservableObject {
19-
20- /// The text inside the search bar.
21- @Published var searchText : String = " "
22-
23- /// Instance of the search controller.
24- let searchController : UISearchController = UISearchController ( searchResultsController: nil )
25-
26- override init ( ) {
27- super. init ( )
28-
29- /// Prevent a gray overlay over the list.
30- self . searchController. obscuresBackgroundDuringPresentation = false
31-
32- /// Set the delegate.
33- self . searchController. searchResultsUpdater = self
34- }
35- }
36-
37- /**
38- Delegate method of `UISearchController`
39- */
40- extension SearchBarConfigurator : UISearchResultsUpdating {
41- func updateSearchResults( for searchController: UISearchController ) {
42-
43- /// Publish search bar text changes.
44- if let searchBarText = searchController. searchBar. text {
45- self . searchText = searchBarText
46- }
47- }
48- }
49-
5010/**
5111 View Modifier for applying the search bar.
5212 */
Original file line number Diff line number Diff line change @@ -76,23 +76,33 @@ public extension SupportOptions {
7676}
7777
7878/**
79- Instantiate a search bar and set the text updating delegate.
79+ Search bar at the top of the NavigationView.
80+
81+ Source: [http://blog.eppz.eu/swiftui-search-bar-in-the-navigation-bar/]( http://blog.eppz.eu/swiftui-search-bar-in-the-navigation-bar/).
82+
83+ MIT License
8084 */
8185class SearchBarConfigurator : NSObject , ObservableObject {
8286
8387 let objectWillChange = PassthroughSubject < Void , Never > ( )
8488
89+ /// The text inside the search bar.
8590 @Published var searchText : String = " " {
8691 willSet {
8792 self . objectWillChange. send ( )
8893 }
8994 }
9095
96+ /// Instance of the search controller.
9197 let searchController : UISearchController = UISearchController ( searchResultsController: nil )
9298
9399 override init ( ) {
94100 super. init ( )
95- self . searchController. obscuresBackgroundDuringPresentation = false /// Prevent the List from being covered.
101+
102+ /// Prevent a gray overlay over the list.
103+ self . searchController. obscuresBackgroundDuringPresentation = false
104+
105+ /// Set the delegate.
96106 self . searchController. searchResultsUpdater = self
97107 }
98108}
Original file line number Diff line number Diff line change @@ -75,47 +75,6 @@ extension View {
7575 }
7676}
7777
78- /**
79- Workaround to access the parent view controller of the SwiftUI View.
80- */
81- internal final class ViewControllerResolver : UIViewControllerRepresentable {
82-
83- /// Closure to call when `didMove`
84- let onResolve : ( UIViewController ) -> Void
85-
86- init ( onResolve: @escaping ( UIViewController ) -> Void ) {
87- self . onResolve = onResolve
88- }
89-
90- func makeUIViewController( context: Context ) -> ParentResolverViewController {
91- ParentResolverViewController ( onResolve: onResolve)
92- }
93-
94- func updateUIViewController( _ uiViewController: ParentResolverViewController , context: Context ) { }
95- }
96-
97- internal class ParentResolverViewController : UIViewController {
98-
99- let onResolve : ( UIViewController ) -> Void
100-
101- init ( onResolve: @escaping ( UIViewController ) -> Void ) {
102- self . onResolve = onResolve
103- super. init ( nibName: nil , bundle: nil )
104- }
105-
106- required init ? ( coder: NSCoder ) {
107- fatalError ( " Use init(onResolve:) to instantiate ParentResolverViewController. " )
108- }
109-
110- override func didMove( toParent parent: UIViewController ? ) {
111- super. didMove ( toParent: parent)
112-
113- if let parent = parent {
114- onResolve ( parent)
115- }
116- }
117- }
118-
11978// MARK: - Other Utilities
12079
12180/**
You can’t perform that action at this time.
0 commit comments