mirror of
https://github.com/home-assistant/iOS.git
synced 2026-04-12 05:08:23 -05:00
Split WebViewController functionality into multiple extension files (Alerts, EmptyState, Gestures, Navigation, Onboarding, Settings, StatusBar, URLLoading, WebViewSetup) and add FrontEndConnectionState enum. Update Xcode project to include the new source files and adjust several Database test file references and a local Swift package path (Sources/SharedPush). Also add empty input/output path arrays to several CocoaPods embed phases. This refactors web view features into modular components and wires them into the project file. <!-- 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 --> ## 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. -->
78 lines
2.7 KiB
Swift
78 lines
2.7 KiB
Swift
import Shared
|
|
import UIKit
|
|
|
|
// MARK: - Empty State
|
|
|
|
extension WebViewController {
|
|
func setupEmptyState() {
|
|
let emptyState = WebViewEmptyStateWrapperView(server: server) { [weak self] in
|
|
self?.hideEmptyState()
|
|
self?.refresh()
|
|
} settingsAction: { [weak self] in
|
|
self?.showSettingsViewController()
|
|
} dismissAction: { [weak self] in
|
|
self?.hideEmptyState()
|
|
}
|
|
|
|
view.addSubview(emptyState)
|
|
|
|
emptyState.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
NSLayoutConstraint.activate([
|
|
emptyState.leftAnchor.constraint(equalTo: view.leftAnchor),
|
|
emptyState.rightAnchor.constraint(equalTo: view.rightAnchor),
|
|
emptyState.topAnchor.constraint(equalTo: view.topAnchor),
|
|
emptyState.bottomAnchor.constraint(equalTo: view.bottomAnchor),
|
|
])
|
|
|
|
emptyState.alpha = 0
|
|
emptyStateView = emptyState
|
|
}
|
|
|
|
func showEmptyState() {
|
|
UIView.animate(withDuration: emptyStateTransitionDuration, delay: 0, options: .curveEaseInOut, animations: {
|
|
self.emptyStateView?.alpha = 1
|
|
}, completion: nil)
|
|
}
|
|
|
|
@objc func hideEmptyState() {
|
|
UIView.animate(withDuration: emptyStateTransitionDuration, delay: 0, options: .curveEaseInOut, animations: {
|
|
self.emptyStateView?.alpha = 0
|
|
}, completion: nil)
|
|
}
|
|
|
|
// To avoid keeping the empty state on screen when user is disconnected in background
|
|
// due to inactivity, we reset the empty state timer
|
|
@objc func resetEmptyStateTimerWithLatestConnectedState() {
|
|
let state: FrontEndConnectionState = isConnected ? .connected : .disconnected
|
|
updateFrontendConnectionState(state: state.rawValue)
|
|
}
|
|
|
|
func emptyStateObservations() {
|
|
// Hide empty state when enter background
|
|
NotificationCenter.default.addObserver(
|
|
self,
|
|
selector: #selector(hideEmptyState),
|
|
name: UIApplication.didEnterBackgroundNotification,
|
|
object: nil
|
|
)
|
|
|
|
// Show empty state again if after entering foreground it is not connected
|
|
NotificationCenter.default.addObserver(
|
|
self,
|
|
selector: #selector(resetEmptyStateTimerWithLatestConnectedState),
|
|
name: UIApplication.willEnterForegroundNotification,
|
|
object: nil
|
|
)
|
|
}
|
|
|
|
func removeEmptyStateObservations() {
|
|
NotificationCenter.default.removeObserver(self, name: UIApplication.didEnterBackgroundNotification, object: nil)
|
|
NotificationCenter.default.removeObserver(
|
|
self,
|
|
name: UIApplication.willEnterForegroundNotification,
|
|
object: nil
|
|
)
|
|
}
|
|
}
|