Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
b3ll opened this issue Aug 22, 2022 · 1 comment

Comments

@b3ll
Copy link

b3ll commented Aug 22, 2022

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
Copy link
Owner

krzysztofzablocki commented Aug 23, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants