1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-14 06:10:32 +05:30
yattee/Shared/Player/VideoDetailsPaddingModifier.swift
2021-09-18 22:42:04 +02:00

43 lines
1.2 KiB
Swift

import Foundation
import SwiftUI
struct VideoDetailsPaddingModifier: ViewModifier {
let geometry: GeometryProxy
let aspectRatio: Double?
let minimumHeightLeft: Double
let additionalPadding: Double
init(
geometry: GeometryProxy,
aspectRatio: Double? = nil,
minimumHeightLeft: Double? = nil,
additionalPadding: Double = 35.00
) {
self.geometry = geometry
self.aspectRatio = aspectRatio ?? VideoPlayerView.defaultAspectRatio
self.minimumHeightLeft = minimumHeightLeft ?? VideoPlayerView.defaultMinimumHeightLeft
self.additionalPadding = additionalPadding
}
var usedAspectRatio: Double {
guard aspectRatio != nil else {
return VideoPlayerView.defaultAspectRatio
}
return [aspectRatio!, VideoPlayerView.defaultAspectRatio].min()!
}
var playerHeight: Double {
[geometry.size.width / usedAspectRatio, geometry.size.height - minimumHeightLeft].min()!
}
var topPadding: Double {
playerHeight + additionalPadding
}
func body(content: Content) -> some View {
content
.padding(.top, topPadding)
}
}