Files
iOS/Sources/App/Container/RecoveredServerReauthHostingView.swift
Bruno Pantaleão Gonçalves 6e84ff4cb6 Migrate app from UIKit based app to SwiftUI (#4748)
<!-- Thank you for submitting a Pull Request and helping to improve Home
Assistant. Please complete the following sections to help the processing
and review of your changes. Please do not delete anything from this
template. -->

## Summary
<!-- Provide a brief summary of the changes you have made and most
importantly what they aim to achieve -->
This PR is a massive refactor of how the app handles UI presentation and
navigation, goin from the UIKit based apps style to SwiftUI.

## Screenshots
<!-- If this is a user-facing change not in the frontend, please include
screenshots in light and dark mode. -->

## Link to pull request in Documentation repository
<!-- Pull requests that add, change or remove functionality must have a
corresponding pull request in the Companion App Documentation repository
(https://github.com/home-assistant/companion.home-assistant). Please add
the number of this pull request after the "#" -->
Documentation: home-assistant/companion.home-assistant#

## Any other notes
<!-- If there is any other information of note, like if this Pull
Request is part of a bigger change, please include it here. -->

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-16 10:33:17 +02:00

41 lines
1.5 KiB
Swift

import PromiseKit
import Shared
import SwiftUI
/// Hosts the recovered-server re-auth screen via `embeddedInHostingController()` so it gets a
/// `ViewControllerProvider` the OAuth login is presented from that hosting controller.
struct RecoveredServerReauthHostingView: UIViewControllerRepresentable {
let server: Server
let state: OnboardingStateObservable
func makeUIViewController(context: Context) -> UIViewController {
RecoveredServerReauthScreen(server: server, state: state).embeddedInHostingController()
}
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
}
private struct RecoveredServerReauthScreen: View {
@EnvironmentObject private var hostingProvider: ViewControllerProvider
let server: Server
let state: OnboardingStateObservable
var body: some View {
WebViewEmptyStateView(
style: .recoveredServerNeedingReauthentication,
server: server,
availableReauthURLTypes: state.availableReauthURLTypes(for: server),
settingsAction: { Current.sceneManager.appCoordinator.done { $0.showSettings() } },
recoveredServerReauthAction: { urlType, completion in
state.performRecoveredServerReauthentication(
for: server,
using: urlType,
presenter: hostingProvider.viewController,
completion: completion
)
},
serverSelectionAction: { state.handleRecoveredServerSelection($0) }
)
}
}