Skip to content

Commit 401de0c

Browse files
committed
Make interfaceScale lookup resilient
1 parent 66e1d06 commit 401de0c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Sources/GateEngine/UI/View.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ open class View {
5050
}
5151

5252
public var interfaceScale: Float {
53-
return superView?.interfaceScale ?? 1.0
53+
if let scale = window?.interfaceScale {
54+
return scale
55+
}
56+
return 1.0
5457
}
5558

5659
public var userInteractionEnabled: Bool = true
@@ -88,6 +91,15 @@ open class View {
8891
if let window = view as? Window {
8992
_window = window
9093
}
94+
95+
if _window == nil {
96+
// If the view is removed from the view heirarchy
97+
// Check the ViewController chain
98+
if let window = self.viewController?.parent?.view.window {
99+
_window = window
100+
}
101+
}
102+
91103
return _window
92104
}
93105

0 commit comments

Comments
 (0)