-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathScenePhase.swift
52 lines (44 loc) · 1.52 KB
/
ScenePhase.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// ScenePhase.swift
// ScenePhase
//
// Created by Philipp on 29.08.21.
//
import SwiftUI
#if TARGET_IOS_MAJOR_13
@available(iOS, introduced: 13, obsoleted: 14.0,
message: "Backport not necessary as of iOS 14", renamed: "SwiftUI.ScenePhase")
public enum ScenePhase: Comparable, Hashable {
/// The scene isn't currently visible in the UI.
case background
/// The scene is in the foreground but should pause its work.
case inactive
/// The scene is in the foreground and interactive.
case active
}
@available(iOS, introduced: 13, obsoleted: 14.0,
message: "Backport not necessary as of iOS 14", renamed: "SwiftUI.ScenePhase")
extension ScenePhase {
init?(_ state: UIScene.ActivationState) {
switch state {
case .background: self = .background
case .foregroundActive: self = .active
case .foregroundInactive: self = .inactive
default: return nil
}
}
}
@available(iOS, introduced: 13, obsoleted: 14.0,
message: "Backport not necessary as of iOS 14", renamed: "SwiftUI.ScenePhase")
private struct ScenePhaseKey: EnvironmentKey {
static var defaultValue: ScenePhase = .background
}
@available(iOS, introduced: 13, obsoleted: 14.0,
message: "Backport not necessary as of iOS 14", renamed: "SwiftUI.ScenePhase")
extension EnvironmentValues {
public var scenePhase: ScenePhase {
get { self[ScenePhaseKey.self] }
set { self[ScenePhaseKey.self] = newValue }
}
}
#endif