ViewControllerFactoryRegistry

The IdsvrHaapiUIKit is able to present and navigate the user through an authentication flow by rendering the server responses after they are transformed into one of the bundled UIModel type hierarchy. The UI contents are dynamically loaded by resolving the HaapiUIViewController that is registered to handle a model.

Customizing the UI

It is possible to provide custom client UI implementation that overrides the framework's bundled UI, and the requirements are:

The following snippet illustrates a few different examples for a custom UI implementation registration into the UI resolution engine.

@available(iOS 14.0, *)
class SubclassingFormViewController: FormViewController {
    // Custom code here
}

@available(iOS 14.0, *)
class SubclassingBaseViewController: BaseViewController<SelectorModel, BaseViewControllerStyle> {
    // Custom code here
}

@available(iOS 14.0, *)
class FullCustomViewController: UIViewController, HaapiUIViewController {
    typealias AssociatedModel = MyFormModel
    
    var haapiFlowViewControllerDelegate: HaapiFlowViewControllerDelegate?
    var uiStylableThemeDelegate: UIStylableThemeDelegate?
    
    var model: MyFormModel
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    init(model: MyFormModel) {
        self.model = model
        super.init(nibName: nil, bundle: nil)
    }
    
    func onAction() {
        haapiFlowViewControllerDelegate?.submit(
            interactionActionModel: model.interactionItems.first as! InteractionActionModel,
            parameters: [:]
        )
    }
    
    func stopLoading() {
        // Custom code here
    }
    
    func hasLoading() -> Bool {
        // Custom code here
        return false
    }
    
    func handleProblemModel(_ problemModel: ProblemModel) -> Bool {
        // Custom code here
        return false
    }
    
    func handleInfoMessageModels(_ infoMessageModels: [InfoMessageModel]) {
        // Custom code here
    }
    
    func handleLinkItemModels(_ linkItemModels: [any LinkItemModel]) {
        // Custom code here
    }
    
    func handleFormModel(_ formModel: FormModel) -> Bool {
        // Custom code here
        return false
    }
    
    func hideHeaderView() {
        // Custom code here
    }
}

The following snippet illustrates registering custom factory blocks for the above examples into the HaapiUIKitApplicationBuilder configuration.

HaapiUIKitApplicationBuilder(haapiUIKitConfiguration: haapiUIKitConfiguration)
    .setViewControllerFactoryRegistry(
        registry: ViewControllerFactoryRegistry().registerViewControllerFactory(modelType: MyFormModel.self, factory: { model,_,_  in
            let vc = FullCustomViewController(model: model)
            return vc
        })
        .registerViewControllerFactorySelectorModel(factory: { formModel, formStyle, commonStyle in
            SubclassingBaseViewController(formModel, style: formStyle, commonStyle: commonStyle)
        })
        .registerViewControllerFactoryFormModel(factory: { formModel, formStyle, commonStyle in
            SubclassingFormViewController(formModel, style: formStyle, commonStyle: commonStyle)
        })
    )
    .buildOrThrow()