mirror of
https://github.com/yattee/yattee.git
synced 2024-12-23 05:53:41 +00:00
Player view layout changes
This commit is contained in:
parent
eca685ae29
commit
328119f0e0
@ -100,99 +100,82 @@ struct VideoPlayerView: View {
|
|||||||
Self._printChanges()
|
Self._printChanges()
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
return GeometryReader { geometry in
|
||||||
#if os(macOS)
|
HStack(spacing: 0) {
|
||||||
return GeometryReader { geometry in
|
content
|
||||||
HSplitView {
|
.onAppear {
|
||||||
content
|
playerSize = geometry.size
|
||||||
}
|
|
||||||
.onAppear {
|
|
||||||
playerSize = geometry.size
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.alert(isPresented: $navigation.presentingAlertInVideoPlayer) { navigation.alert }
|
|
||||||
.onOpenURL { url in
|
|
||||||
URLBookmarkModel.shared.saveBookmark(url)
|
|
||||||
OpenURLHandler.shared.handle(url)
|
|
||||||
}
|
|
||||||
.frame(minWidth: 950, minHeight: 700)
|
|
||||||
#else
|
|
||||||
return GeometryReader { geometry in
|
|
||||||
HStack(spacing: 0) {
|
|
||||||
content
|
|
||||||
.onAppear {
|
|
||||||
playerSize = geometry.size
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.onChange(of: geometry.size) { size in
|
|
||||||
self.playerSize = size
|
|
||||||
}
|
|
||||||
.onChange(of: fullScreenDetails) { value in
|
|
||||||
player.backend.setNeedsDrawing(!value)
|
|
||||||
}
|
|
||||||
#if os(iOS)
|
|
||||||
.frame(width: playerWidth.isNil ? nil : Double(playerWidth!), height: playerHeight.isNil ? nil : Double(playerHeight!))
|
|
||||||
.ignoresSafeArea(.all, edges: playerEdgesIgnoringSafeArea)
|
|
||||||
.onChange(of: player.presentingPlayer) { newValue in
|
|
||||||
if newValue {
|
|
||||||
viewDragOffset = 0
|
|
||||||
} else {
|
|
||||||
viewDragOffset = Self.hiddenOffset
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onAppear {
|
.onChange(of: geometry.size) { _ in
|
||||||
|
self.playerSize = geometry.size
|
||||||
|
}
|
||||||
|
.onChange(of: fullScreenDetails) { value in
|
||||||
|
player.backend.setNeedsDrawing(!value)
|
||||||
|
}
|
||||||
|
#if os(iOS)
|
||||||
|
.padding(.bottom, playerEdgesIgnoringSafeArea == [.bottom] ? 0 : geometry.safeAreaInsets.bottom)
|
||||||
|
.frame(width: playerWidth.isNil ? nil : Double(playerWidth!), height: playerHeight.isNil ? nil : Double(playerHeight!))
|
||||||
|
.ignoresSafeArea(.all, edges: playerEdgesIgnoringSafeArea)
|
||||||
|
.onChange(of: player.presentingPlayer) { newValue in
|
||||||
|
if newValue {
|
||||||
viewDragOffset = 0
|
viewDragOffset = 0
|
||||||
|
} else {
|
||||||
Delay.by(0.2) {
|
viewDragOffset = Self.hiddenOffset
|
||||||
configureOrientationUpdatesBasedOnAccelerometer()
|
|
||||||
|
|
||||||
if let orientationMask = player.lockedOrientation {
|
|
||||||
Orientation.lockOrientation(
|
|
||||||
orientationMask,
|
|
||||||
andRotateTo: orientationMask == .landscapeLeft ? .landscapeLeft : orientationMask == .landscapeRight ? .landscapeRight : .portrait
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
Orientation.lockOrientation(.allButUpsideDown)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.onDisappear {
|
}
|
||||||
if Defaults[.lockPortraitWhenBrowsing] {
|
.onAppear {
|
||||||
Orientation.lockOrientation(.portrait, andRotateTo: .portrait)
|
viewDragOffset = 0
|
||||||
|
|
||||||
|
Delay.by(0.2) {
|
||||||
|
configureOrientationUpdatesBasedOnAccelerometer()
|
||||||
|
|
||||||
|
if let orientationMask = player.lockedOrientation {
|
||||||
|
Orientation.lockOrientation(
|
||||||
|
orientationMask,
|
||||||
|
andRotateTo: orientationMask == .landscapeLeft ? .landscapeLeft : orientationMask == .landscapeRight ? .landscapeRight : .portrait
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
Orientation.lockOrientation(.allButUpsideDown)
|
Orientation.lockOrientation(.allButUpsideDown)
|
||||||
}
|
}
|
||||||
stopOrientationUpdates()
|
|
||||||
player.controls.hideOverlays()
|
|
||||||
}
|
}
|
||||||
.onReceive(NotificationCenter.default.publisher(for: UIDevice.orientationDidChangeNotification)) { _ in
|
}
|
||||||
guard player.lockedOrientation.isNil else {
|
.onDisappear {
|
||||||
return
|
if Defaults[.lockPortraitWhenBrowsing] {
|
||||||
}
|
Orientation.lockOrientation(.portrait, andRotateTo: .portrait)
|
||||||
|
} else {
|
||||||
|
Orientation.lockOrientation(.allButUpsideDown)
|
||||||
|
}
|
||||||
|
stopOrientationUpdates()
|
||||||
|
player.controls.hideOverlays()
|
||||||
|
}
|
||||||
|
.onReceive(NotificationCenter.default.publisher(for: UIDevice.orientationDidChangeNotification)) { _ in
|
||||||
|
guard player.lockedOrientation.isNil else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
Orientation.lockOrientation(.allButUpsideDown, andRotateTo: OrientationTracker.shared.currentInterfaceOrientation)
|
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)
|
.onAnimationCompleted(for: viewDragOffset) {
|
||||||
.onChange(of: dragGestureState) { newValue in
|
guard !dragGestureState else { return }
|
||||||
guard !newValue else { return }
|
if viewDragOffset == 0 {
|
||||||
onPlayerDragGestureEnded()
|
player.onPresentPlayer.forEach { $0() }
|
||||||
|
player.onPresentPlayer = []
|
||||||
|
} else if viewDragOffset == Self.hiddenOffset {
|
||||||
|
player.hide(animate: false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.offset(y: playerOffset)
|
|
||||||
.animation(dragGestureState ? .interactiveSpring(response: 0.05) : .easeOut(duration: 0.2), value: playerOffset)
|
|
||||||
.backport
|
|
||||||
.persistentSystemOverlays(!fullScreenPlayer)
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
#if os(iOS)
|
||||||
|
.onChange(of: dragGestureState) { newValue in
|
||||||
|
guard !newValue else { return }
|
||||||
|
onPlayerDragGestureEnded()
|
||||||
|
}
|
||||||
|
.offset(y: playerOffset)
|
||||||
|
.animation(dragGestureState ? .interactiveSpring(response: 0.05) : .easeOut(duration: 0.2), value: playerOffset)
|
||||||
|
.backport
|
||||||
|
.persistentSystemOverlays(!fullScreenPlayer)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,7 +270,7 @@ struct VideoPlayerView: View {
|
|||||||
return [.vertical]
|
return [.vertical]
|
||||||
}
|
}
|
||||||
|
|
||||||
return []
|
return [.bottom]
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -305,58 +288,54 @@ struct VideoPlayerView: View {
|
|||||||
.ignoresSafeArea()
|
.ignoresSafeArea()
|
||||||
#else
|
#else
|
||||||
GeometryReader { geometry in
|
GeometryReader { geometry in
|
||||||
player.playerBackendView
|
ZStack {
|
||||||
#if !os(tvOS)
|
player.playerBackendView
|
||||||
.modifier(
|
}
|
||||||
VideoPlayerSizeModifier(
|
.modifier(
|
||||||
geometry: geometry,
|
VideoPlayerSizeModifier(
|
||||||
aspectRatio: player.aspectRatio,
|
geometry: geometry,
|
||||||
fullScreen: fullScreenPlayer
|
aspectRatio: player.aspectRatio,
|
||||||
)
|
fullScreen: fullScreenPlayer
|
||||||
)
|
)
|
||||||
.overlay(playerPlaceholder)
|
)
|
||||||
#endif
|
.frame(maxWidth: fullScreenPlayer ? .infinity : nil, maxHeight: fullScreenPlayer ? .infinity : nil)
|
||||||
.frame(maxWidth: fullScreenPlayer ? .infinity : nil, maxHeight: fullScreenPlayer ? .infinity : nil)
|
.onHover { hovering in
|
||||||
.onHover { hovering in
|
hoveringPlayer = hovering
|
||||||
hoveringPlayer = hovering
|
hovering ? player.controls.show() : player.controls.hide()
|
||||||
hovering ? player.controls.show() : player.controls.hide()
|
}
|
||||||
}
|
.gesture(player.controls.presentingOverlays ? nil : playerDragGesture)
|
||||||
#if !os(tvOS)
|
|
||||||
.gesture(player.controls.presentingOverlays ? nil : playerDragGesture)
|
|
||||||
#endif
|
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
.onAppear(perform: {
|
.onAppear(perform: {
|
||||||
NSEvent.addLocalMonitorForEvents(matching: [.mouseMoved]) {
|
NSEvent.addLocalMonitorForEvents(matching: [.mouseMoved]) {
|
||||||
hoverThrottle.execute {
|
hoverThrottle.execute {
|
||||||
if !player.currentItem.isNil, hoveringPlayer {
|
if !player.currentItem.isNil, hoveringPlayer {
|
||||||
player.controls.resetTimer()
|
player.controls.resetTimer()
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $0
|
|
||||||
}
|
|
||||||
})
|
|
||||||
#endif
|
|
||||||
|
|
||||||
.background(Color.black)
|
|
||||||
|
|
||||||
#if !os(tvOS)
|
|
||||||
if !fullScreenPlayer {
|
|
||||||
VideoDetails(page: $detailsPage, sidebarQueue: $sidebarQueue, fullScreen: $fullScreenDetails, bottomPadding: detailsNeedBottomPadding)
|
|
||||||
#if os(iOS)
|
|
||||||
.ignoresSafeArea(.all, edges: .bottom)
|
|
||||||
#endif
|
|
||||||
.modifier(VideoDetailsPaddingModifier(
|
|
||||||
playerSize: player.playerSize,
|
|
||||||
fullScreen: fullScreenDetails
|
|
||||||
))
|
|
||||||
.onDisappear {
|
|
||||||
if player.presentingPlayer {
|
|
||||||
player.setNeedsDrawing(true)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
return $0
|
||||||
|
}
|
||||||
|
})
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
.background(Color.black)
|
||||||
|
|
||||||
|
if !fullScreenPlayer {
|
||||||
|
VideoDetails(video: player.currentVideo, page: $detailsPage, sidebarQueue: $sidebarQueue, fullScreen: $fullScreenDetails, bottomPadding: detailsNeedBottomPadding)
|
||||||
|
#if os(iOS)
|
||||||
|
.ignoresSafeArea(.all, edges: .bottom)
|
||||||
|
#endif
|
||||||
|
.modifier(VideoDetailsPaddingModifier(
|
||||||
|
playerSize: player.playerSize,
|
||||||
|
fullScreen: fullScreenDetails
|
||||||
|
))
|
||||||
|
.onDisappear {
|
||||||
|
if player.presentingPlayer {
|
||||||
|
player.setNeedsDrawing(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.transition(.opacity)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -476,7 +455,7 @@ struct VideoPlayerView: View {
|
|||||||
.foregroundColor(.gray)
|
.foregroundColor(.gray)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
.background(Color.black)
|
.background(colorScheme == .dark ? Color.black : .white)
|
||||||
.contentShape(Rectangle())
|
.contentShape(Rectangle())
|
||||||
.frame(width: player.playerSize.width, height: player.playerSize.height)
|
.frame(width: player.playerSize.width, height: player.playerSize.height)
|
||||||
}
|
}
|
||||||
@ -493,7 +472,7 @@ struct VideoPlayerView_Previews: PreviewProvider {
|
|||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
VideoPlayerView()
|
VideoPlayerView()
|
||||||
.onAppear {
|
.onAppear {
|
||||||
OutroViewModel.shared.prepareForEmptyPlayerPlaceholder(.init(.fixture))
|
WatchNextViewModel.shared.prepareForEmptyPlayerPlaceholder(.init(.fixture))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user