From cddb52f1522dd3dd6aee990ce21d673fdbc5594f Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Sun, 10 Jul 2022 13:14:07 +0200 Subject: [PATCH] Improve orientation observing --- Shared/Player/VideoPlayerView.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Shared/Player/VideoPlayerView.swift b/Shared/Player/VideoPlayerView.swift index 8e79ac7f..2ed7f224 100644 --- a/Shared/Player/VideoPlayerView.swift +++ b/Shared/Player/VideoPlayerView.swift @@ -46,6 +46,7 @@ struct VideoPlayerView: View { #if os(iOS) @State private var viewVerticalOffset = Self.hiddenOffset + @State private var orientationObserver: Any? #endif @EnvironmentObject private var accounts @@ -117,6 +118,7 @@ struct VideoPlayerView: View { Orientation.lockOrientation(.allButUpsideDown) } viewVerticalOffset = Self.hiddenOffset + stopOrientationUpdates() } } #endif @@ -441,7 +443,7 @@ struct VideoPlayerView: View { } } - NotificationCenter.default.addObserver( + orientationObserver = NotificationCenter.default.addObserver( forName: OrientationTracker.deviceOrientationChangedNotification, object: nil, queue: .main @@ -476,6 +478,11 @@ struct VideoPlayerView: View { } } } + + private func stopOrientationUpdates() { + guard let observer = orientationObserver else { return } + NotificationCenter.default.removeObserver(observer) + } #endif #if os(tvOS)