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

Feature Request: Support Custom ErrorView #100

Open
tony-rowan opened this issue Mar 10, 2025 · 0 comments
Open

Feature Request: Support Custom ErrorView #100

tony-rowan opened this issue Mar 10, 2025 · 0 comments

Comments

@tony-rowan
Copy link

The built-in default error handling behaviour is simple and straight forward and exactly what I believe most projects will want most of the time. However, the displayed error view is uncustomisable without duplicating most of the ErrorPresenter extension code. It would be fantastic if we could add a way to hook into the construction of the ErrorView that gets presented so projects could provide their own - to provide fonts, images, branding etc. I know we could hook into visitableDidFailRequest(_:error:retryHandler) and provide a custom implementation, but it feels wasteful when the implementation is almost exactly what we want, just with our own app's branding.

As a first pass, something like this might suffice?

// Turbo/Navigator/Helpers/ErrorPresenter.swift

extension ErrorPresenter {
    func presentError(_ error: Error, retryHandler: Handler?, errorView: AnyClass) {
        let errorView = buildErrorView(error: error, shouldShowRetryButton: retryHandler != nil) {
            retryHandler?()
            self.removeErrorViewController()
        }

        let controller = UIHostingController(rootView: errorView)
        addChild(controller)
        addFullScreenSubview(controller.view)
        controller.didMove(toParent: self)
    }

    // Allow for projects to hook into the error view construction and override to provide their own?
    func buildErrorView(error: Error, shouldShowRetryButton: Bool, handler: @escaping ErrorPresenter.Handler) -> any View {
        ErrorView(error: error, shouldShowRetryButton: shouldShowRetryButton, handler: handler)
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant