Immersive scene phases
Observing the ScenePhase
in the environment has demonstrated to be a far more reliable technique for determining if an ImmersiveSpace
is active or not. This is particularly helpful for making accessibility announcements, as it allows the user to adjust to the context switch.
import SwiftUI
@main
struct ImmersiveScenePhaseApp: App {
@Environment(\.scenePhase) var scenePhase
var body: some Scene {
WindowGroup {
ContentView()
}
ImmersiveSpace(id: "ImmersiveSpace") {
ImmersiveView()
}
.onChange(of: scenePhase) { _, newPhase in
var scenePhaseDescription = AttributedString("ImmersiveSpace \(newPhase)")
scenePhaseDescription.accessibilitySpeechAnnouncementPriority = .high
switch newPhase {
case .active:
AccessibilityNotification.Announcement(scenePhaseDescription).post()
case .inactive:
AccessibilityNotification.Announcement(scenePhaseDescription).post()
default:
break
}
}
}
}
🙏
Thank you @Harlan for pointing this up