krzysztofzablocki / Inject

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

Ability to subclass Inject.ViewControllerHost #54

Closed gcharita closed 1 year ago

gcharita commented 1 year ago

I have a case where my own view controller override properties like supportedInterfaceOrientations and preferredStatusBarStyle of UIViewController. (also my view controller implements a generic protocol)

So instead of adding Inject as SPM dependency, I added all the files in my project and made a subclass of Inject.ViewControllerHost like this:

protocol MyGenericProtocol: UIViewController {
    var isNavigationBarHidden: Bool { get }
}

class MyViewControllerHost<T: MyGenericProtocol>: Inject.ViewControllerHost<T>, MyGenericProtocol {
    // MARK: - Orientation

    override var supportedInterfaceOrientations: UIInterfaceOrientationMask { instance.supportedInterfaceOrientations }
    override var shouldAutorotate: Bool { instance.shouldAutorotate }

    // MARK: - Status bar

    override var preferredStatusBarStyle: UIStatusBarStyle { instance.preferredStatusBarStyle }

    // MARK: - MyGenericProtocol

    var isNavigationBarHidden: Bool { instance.isNavigationBarHidden }
}

Is there any consideration to make Inject.ViewControllerHost open for subclassing from other modules?

krzysztofzablocki commented 1 year ago

as much as I recommend leaving SwiftUI code paths in prod, I don't usually do the same with hosts since, too often it's extra jumps to support, and most of the time I just wrap the stuff I want to work on and make a separate commit out of it.

If you have an idea that would make your workflow easier though and wanted to put up a PR I'd be open to it, as long as it doesn't force anyone