-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnvironmentValues+.swift
More file actions
56 lines (48 loc) · 1.53 KB
/
Copy pathEnvironmentValues+.swift
File metadata and controls
56 lines (48 loc) · 1.53 KB
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
53
54
55
56
//
// EnvironmentValues+.swift
// DevLog
//
// Created by 최윤진 on 2/6/26.
//
import SwiftUI
extension EnvironmentValues {
var safeAreaInsets: EdgeInsets {
self[SafeAreaInsetsKey.self]
}
var sceneWidth: CGFloat {
self[SceneWidthKey.self]
}
var sceneHeight: CGFloat {
self[SceneHeightKey.self]
}
private struct SafeAreaInsetsKey: EnvironmentKey {
static var defaultValue: EdgeInsets {
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let window = windowScene.windows.first(where: { $0.isKeyWindow }) else {
return EdgeInsets()
}
return window.safeAreaInsets.insets
}
}
private struct SceneWidthKey: EnvironmentKey {
static var defaultValue: CGFloat {
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene else {
return UIScreen.main.bounds.width
}
return windowScene.screen.bounds.width
}
}
private struct SceneHeightKey: EnvironmentKey {
static var defaultValue: CGFloat {
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene else {
return UIScreen.main.bounds.height
}
return windowScene.screen.bounds.height
}
}
}
extension UIEdgeInsets {
var insets: EdgeInsets {
EdgeInsets(top: top, leading: left, bottom: bottom, trailing: right)
}
}