2021-08-22 19:13:33 +00:00
|
|
|
import Foundation
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct VideoDetailsPaddingModifier: ViewModifier {
|
2021-10-05 20:20:09 +00:00
|
|
|
static var defaultAdditionalDetailsPadding: Double {
|
|
|
|
#if os(macOS)
|
2021-10-16 22:48:58 +00:00
|
|
|
30
|
2021-10-05 20:20:09 +00:00
|
|
|
#else
|
2021-11-08 16:29:35 +00:00
|
|
|
40
|
2021-10-05 20:20:09 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-08-22 19:13:33 +00:00
|
|
|
let geometry: GeometryProxy
|
2021-09-18 20:36:42 +00:00
|
|
|
let aspectRatio: Double?
|
|
|
|
let minimumHeightLeft: Double
|
|
|
|
let additionalPadding: Double
|
2021-10-05 20:20:09 +00:00
|
|
|
let fullScreen: Bool
|
2021-08-22 19:13:33 +00:00
|
|
|
|
|
|
|
init(
|
|
|
|
geometry: GeometryProxy,
|
2021-09-18 20:36:42 +00:00
|
|
|
aspectRatio: Double? = nil,
|
|
|
|
minimumHeightLeft: Double? = nil,
|
2021-10-05 20:20:09 +00:00
|
|
|
additionalPadding: Double? = nil,
|
|
|
|
fullScreen: Bool = false
|
2021-08-22 19:13:33 +00:00
|
|
|
) {
|
|
|
|
self.geometry = geometry
|
|
|
|
self.aspectRatio = aspectRatio ?? VideoPlayerView.defaultAspectRatio
|
|
|
|
self.minimumHeightLeft = minimumHeightLeft ?? VideoPlayerView.defaultMinimumHeightLeft
|
2021-10-05 20:20:09 +00:00
|
|
|
self.additionalPadding = additionalPadding ?? VideoDetailsPaddingModifier.defaultAdditionalDetailsPadding
|
|
|
|
self.fullScreen = fullScreen
|
2021-08-22 19:13:33 +00:00
|
|
|
}
|
|
|
|
|
2021-09-18 20:36:42 +00:00
|
|
|
var usedAspectRatio: Double {
|
2021-08-22 19:13:33 +00:00
|
|
|
guard aspectRatio != nil else {
|
|
|
|
return VideoPlayerView.defaultAspectRatio
|
|
|
|
}
|
|
|
|
|
|
|
|
return [aspectRatio!, VideoPlayerView.defaultAspectRatio].min()!
|
|
|
|
}
|
|
|
|
|
2021-09-18 20:36:42 +00:00
|
|
|
var playerHeight: Double {
|
2021-08-22 19:13:33 +00:00
|
|
|
[geometry.size.width / usedAspectRatio, geometry.size.height - minimumHeightLeft].min()!
|
|
|
|
}
|
|
|
|
|
2021-09-18 20:36:42 +00:00
|
|
|
var topPadding: Double {
|
2021-10-05 20:20:09 +00:00
|
|
|
fullScreen ? 0 : (playerHeight + additionalPadding)
|
2021-08-22 19:13:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func body(content: Content) -> some View {
|
|
|
|
content
|
|
|
|
.padding(.top, topPadding)
|
|
|
|
}
|
|
|
|
}
|