Skip to content

Commit cdb643e

Browse files
authored
[LOOP-5958] Toolbar Orientation Fix (#938)
1 parent a7e7c02 commit cdb643e

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

Loop/Views/StatusTableView.swift

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -262,34 +262,38 @@ struct LegacyTabBarBackground: ViewModifier {
262262

263263
struct ActionTabView<Content: View>: View {
264264

265-
@State private var orientation: UIDeviceOrientation
265+
@State private var orientation: UIInterfaceOrientation
266266

267-
private let allowedOrientations: [UIDeviceOrientation]
268267
private let content: Content
269268
private let tabs: [ActionTab]
270269

271270
init(
272-
allowedOrientations: [UIDeviceOrientation] = [.portrait],
273271
@ViewBuilder content: @escaping () -> Content,
274272
@ActionTabBuilder tabs: @escaping () -> [ActionTab],
275273
) {
276274
self.content = content()
277275
self.tabs = tabs()
278276

279-
self.allowedOrientations = allowedOrientations
280-
self.orientation = UIDevice.current.orientation
277+
self.orientation = Self.currentOrientation()
281278
}
282279

283280
var body: some View {
284281
content
285282
.safeAreaInset(edge: .bottom, spacing: 0) {
286-
if orientation == .unknown || allowedOrientations.contains(orientation) {
283+
if orientation.isPortrait {
287284
ActionTabBar(items: tabs)
288285
.modifier(LegacyTabBarBackground())
289286
}
290287
}
291288
.onReceive(NotificationCenter.default.publisher(for: UIDevice.orientationDidChangeNotification)) { _ in
292-
orientation = UIDevice.current.orientation
289+
orientation = Self.currentOrientation()
293290
}
294291
}
292+
293+
private static func currentOrientation() -> UIInterfaceOrientation {
294+
UIApplication.shared.connectedScenes
295+
.compactMap { $0 as? UIWindowScene }
296+
.first?
297+
.interfaceOrientation ?? .portrait
298+
}
295299
}

0 commit comments

Comments
 (0)