krzysztofzablocki / Inject

Hot Reloading for Swift applications!
MIT License
2.1k stars 114 forks source link

UISearchBar Doesn't Show with UINavigationController + Inject.ViewControllerHost #49

Closed b3ll closed 1 year ago

b3ll commented 2 years ago
class ViewController: UIViewController, UISearchResultsUpdating {

    let searchController: UISearchController

    init() {
        self.searchController = UISearchController(searchResultsController: nil)

        super.init(nibName: nil, bundle: nil)

        searchController.searchResultsUpdater = self
        searchController.obscuresBackgroundDuringPresentation = false
        searchController.searchBar.placeholder = NSLocalizedString("Search", comment: "")
        searchController.searchBar.searchBarStyle = .minimal

        navigationItem.searchController = searchController
        navigationItem.title = "Hello"
        navigationItem.hidesSearchBarWhenScrolling = false

        self.definesPresentationContext = true
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    func updateSearchResults(for searchController: UISearchController) {

    }

}

// elsewhere

let injectVC = Inject.ViewControllerHost(ViewController())
let root = UINavigationController(rootViewController: injectVC)
window.rootViewController = root

self.window = window
window.makeKeyAndVisible()

Doing something like the following results in the search bar never showing with iOS 16 (I haven't tried iOS 15 yet). Removing the Inject.ViewControllerHost and just using ViewController directly works just fine, so I'm not sure if ViewControllerHost is messing with UIKit's ability to detect where to put the search bar or forwarding or something ¯_(ツ)_/¯

Any idea for a workaround? For now I've just decided to not use Inject. Tried it with and without Injection app running

Sorry if you aren't working on iOS 16 support yet, disregard for now if so!

krzysztofzablocki commented 2 years ago

hey @b3ll, the way this works at host level is that it wraps the real VC as a child view controller and acts as a proxy so that the injected VC version can be swapped out.

That being said I think we'd just need to forward those properties you are setting in here, would you have few minutes to try that? if not just let me know and I'll try to find some time for it on the weekend