yattee/Shared/Player/VideoDetailsPaddingModifier.swift

48 lines
1.3 KiB
Swift
Raw Normal View History

2021-08-22 19:13:33 +00:00
import Foundation
import SwiftUI
struct VideoDetailsPaddingModifier: ViewModifier {
2022-06-24 23:39:29 +00:00
static var defaultAdditionalDetailsPadding = 0.0
2022-06-26 22:15:01 +00:00
let playerSize: CGSize
2021-09-18 20:36:42 +00:00
let aspectRatio: Double?
let minimumHeightLeft: Double
let additionalPadding: Double
let fullScreen: Bool
2021-08-22 19:13:33 +00:00
init(
2022-06-26 22:15:01 +00:00
playerSize: CGSize,
2021-09-18 20:36:42 +00:00
aspectRatio: Double? = nil,
minimumHeightLeft: Double? = nil,
additionalPadding: Double? = nil,
fullScreen: Bool = false
2021-08-22 19:13:33 +00:00
) {
2022-06-26 22:15:01 +00:00
self.playerSize = playerSize
2021-08-22 19:13:33 +00:00
self.aspectRatio = aspectRatio ?? VideoPlayerView.defaultAspectRatio
self.minimumHeightLeft = minimumHeightLeft ?? VideoPlayerView.defaultMinimumHeightLeft
2022-05-20 19:53:17 +00:00
self.additionalPadding = additionalPadding ?? Self.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 {
2022-06-26 22:15:01 +00:00
playerSize.height
2021-08-22 19:13:33 +00:00
}
2021-09-18 20:36:42 +00:00
var topPadding: Double {
fullScreen ? 0 : (playerHeight + additionalPadding)
2021-08-22 19:13:33 +00:00
}
func body(content: Content) -> some View {
content
.padding(.top, topPadding)
}
}