1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-15 06:40:32 +05:30
yattee/Shared/Player/VideoDetailsPaddingModifier.swift

54 lines
1.5 KiB
Swift
Raw Normal View History

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