mirror of
https://github.com/yattee/yattee.git
synced 2025-08-05 02:04:07 +00:00
Fix various issues
This commit is contained in:
@@ -4,6 +4,7 @@ import SwiftUI
|
||||
struct TVControls: UIViewRepresentable {
|
||||
var model: PlayerControlsModel!
|
||||
var player: PlayerModel { .shared }
|
||||
var safeArea: SafeAreaModel { .shared }
|
||||
var thumbnails: ThumbnailsModel { .shared }
|
||||
|
||||
@State private var direction = ""
|
||||
@@ -32,10 +33,10 @@ struct TVControls: UIViewRepresentable {
|
||||
|
||||
let controls = UIHostingController(rootView: PlayerControls())
|
||||
controls.view.frame = .init(
|
||||
origin: .init(x: SafeArea.insets.left, y: SafeArea.insets.top),
|
||||
origin: .init(x: safeArea.safeArea.leading, y: safeArea.safeArea.top),
|
||||
size: .init(
|
||||
width: UIScreen.main.bounds.width - SafeArea.horizontalInsets,
|
||||
height: UIScreen.main.bounds.height - SafeArea.verticalInset
|
||||
width: UIScreen.main.bounds.width - safeArea.horizontalInsets,
|
||||
height: UIScreen.main.bounds.height - safeArea.verticalInsets
|
||||
)
|
||||
)
|
||||
|
||||
|
@@ -4,9 +4,9 @@ import SwiftUI
|
||||
struct PlayerBackendView: View {
|
||||
#if os(iOS)
|
||||
@Environment(\.verticalSizeClass) private var verticalSizeClass
|
||||
@ObservedObject private var safeAreaModel = SafeAreaModel.shared
|
||||
#endif
|
||||
@ObservedObject private var player = PlayerModel.shared
|
||||
@ObservedObject private var safeAreaModel = SafeAreaModel.shared
|
||||
|
||||
@Default(.avPlayerUsesSystemControls) private var avPlayerUsesSystemControls
|
||||
|
||||
@@ -36,9 +36,6 @@ struct PlayerBackendView: View {
|
||||
}
|
||||
}
|
||||
.zIndex(0)
|
||||
|
||||
ControlsGradientView()
|
||||
.zIndex(1)
|
||||
}
|
||||
}
|
||||
.overlay(GeometryReader { proxy in
|
||||
|
@@ -104,65 +104,67 @@ struct VideoPlayerView: View {
|
||||
}
|
||||
}
|
||||
.ignoresSafeArea(.all, edges: .bottom)
|
||||
.frame(height: playerHeight.isNil ? nil : Double(playerHeight!))
|
||||
.onChange(of: geometry.size) { _ in
|
||||
self.playerSize = geometry.size
|
||||
}
|
||||
.onChange(of: fullScreenDetails) { value in
|
||||
player.backend.setNeedsDrawing(!value)
|
||||
}
|
||||
#if os(iOS)
|
||||
.onChange(of: player.presentingPlayer) { newValue in
|
||||
if newValue {
|
||||
viewDragOffset = 0
|
||||
.frame(height: playerHeight.isNil ? nil : Double(playerHeight!))
|
||||
#endif
|
||||
.onChange(of: geometry.size) { _ in
|
||||
self.playerSize = geometry.size
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
#if os(macOS)
|
||||
if player.videoForDisplay.isNil {
|
||||
player.hide()
|
||||
.onChange(of: fullScreenDetails) { value in
|
||||
player.backend.setNeedsDrawing(!value)
|
||||
}
|
||||
#if os(iOS)
|
||||
.onChange(of: player.presentingPlayer) { newValue in
|
||||
if newValue {
|
||||
viewDragOffset = 0
|
||||
}
|
||||
#endif
|
||||
viewDragOffset = 0
|
||||
}
|
||||
.onAppear {
|
||||
#if os(macOS)
|
||||
if player.videoForDisplay.isNil {
|
||||
player.hide()
|
||||
}
|
||||
#endif
|
||||
viewDragOffset = 0
|
||||
|
||||
Delay.by(0.2) {
|
||||
orientationModel.configureOrientationUpdatesBasedOnAccelerometer()
|
||||
Delay.by(0.2) {
|
||||
orientationModel.configureOrientationUpdatesBasedOnAccelerometer()
|
||||
|
||||
if let orientationMask = player.lockedOrientation {
|
||||
Orientation.lockOrientation(
|
||||
orientationMask,
|
||||
andRotateTo: orientationMask == .landscapeLeft ? .landscapeLeft : orientationMask == .landscapeRight ? .landscapeRight : .portrait
|
||||
)
|
||||
if let orientationMask = player.lockedOrientation {
|
||||
Orientation.lockOrientation(
|
||||
orientationMask,
|
||||
andRotateTo: orientationMask == .landscapeLeft ? .landscapeLeft : orientationMask == .landscapeRight ? .landscapeRight : .portrait
|
||||
)
|
||||
} else {
|
||||
Orientation.lockOrientation(.allButUpsideDown)
|
||||
}
|
||||
}
|
||||
}
|
||||
.onDisappear {
|
||||
if Defaults[.lockPortraitWhenBrowsing] {
|
||||
Orientation.lockOrientation(.portrait, andRotateTo: .portrait)
|
||||
} else {
|
||||
Orientation.lockOrientation(.allButUpsideDown)
|
||||
}
|
||||
orientationModel.stopOrientationUpdates()
|
||||
player.controls.hideOverlays()
|
||||
}
|
||||
}
|
||||
.onDisappear {
|
||||
if Defaults[.lockPortraitWhenBrowsing] {
|
||||
Orientation.lockOrientation(.portrait, andRotateTo: .portrait)
|
||||
} else {
|
||||
Orientation.lockOrientation(.allButUpsideDown)
|
||||
}
|
||||
orientationModel.stopOrientationUpdates()
|
||||
player.controls.hideOverlays()
|
||||
}
|
||||
.onReceive(NotificationCenter.default.publisher(for: UIDevice.orientationDidChangeNotification)) { _ in
|
||||
guard player.lockedOrientation.isNil else {
|
||||
return
|
||||
}
|
||||
.onReceive(NotificationCenter.default.publisher(for: UIDevice.orientationDidChangeNotification)) { _ in
|
||||
guard player.lockedOrientation.isNil else {
|
||||
return
|
||||
}
|
||||
|
||||
Orientation.lockOrientation(.allButUpsideDown, andRotateTo: OrientationTracker.shared.currentInterfaceOrientation)
|
||||
}
|
||||
.onAnimationCompleted(for: viewDragOffset) {
|
||||
guard !dragGestureState else { return }
|
||||
if viewDragOffset == 0 {
|
||||
player.onPresentPlayer.forEach { $0() }
|
||||
player.onPresentPlayer = []
|
||||
} else if viewDragOffset == Self.hiddenOffset {
|
||||
player.hide(animate: false)
|
||||
Orientation.lockOrientation(.allButUpsideDown, andRotateTo: OrientationTracker.shared.currentInterfaceOrientation)
|
||||
}
|
||||
.onAnimationCompleted(for: viewDragOffset) {
|
||||
guard !dragGestureState else { return }
|
||||
if viewDragOffset == 0 {
|
||||
player.onPresentPlayer.forEach { $0() }
|
||||
player.onPresentPlayer = []
|
||||
} else if viewDragOffset == Self.hiddenOffset {
|
||||
player.hide(animate: false)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#if os(iOS)
|
||||
@@ -326,7 +328,9 @@ struct VideoPlayerView: View {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#if os(iOS)
|
||||
.background(BackgroundBlackView().edgesIgnoringSafeArea(.all))
|
||||
#endif
|
||||
.background(((colorScheme == .dark || fullScreenPlayer) ? Color.black : Color.white).edgesIgnoringSafeArea(.all))
|
||||
#if os(macOS)
|
||||
.frame(minWidth: 650)
|
||||
@@ -426,7 +430,11 @@ struct VideoPlayerView: View {
|
||||
return true
|
||||
}
|
||||
|
||||
return !avPlayerUsesSystemControls || verticalSizeClass == .compact
|
||||
#if os(iOS)
|
||||
return !avPlayerUsesSystemControls || verticalSizeClass == .compact
|
||||
#else
|
||||
return !avPlayerUsesSystemControls
|
||||
#endif
|
||||
}
|
||||
|
||||
var fullScreenPlayer: Bool {
|
||||
@@ -495,15 +503,17 @@ struct VideoPlayerView_Previews: PreviewProvider {
|
||||
}
|
||||
}
|
||||
|
||||
struct BackgroundBlackView: UIViewRepresentable {
|
||||
func makeUIView(context _: Context) -> UIView {
|
||||
let view = UIView()
|
||||
DispatchQueue.main.async {
|
||||
view.superview?.superview?.backgroundColor = .black
|
||||
view.superview?.superview?.layer.removeAllAnimations()
|
||||
#if os(iOS)
|
||||
struct BackgroundBlackView: UIViewRepresentable {
|
||||
func makeUIView(context _: Context) -> UIView {
|
||||
let view = UIView()
|
||||
DispatchQueue.main.async {
|
||||
view.superview?.superview?.backgroundColor = .black
|
||||
view.superview?.superview?.layer.removeAllAnimations()
|
||||
}
|
||||
return view
|
||||
}
|
||||
return view
|
||||
}
|
||||
|
||||
func updateUIView(_: UIView, context _: Context) {}
|
||||
}
|
||||
func updateUIView(_: UIView, context _: Context) {}
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user