Change player size based on aspect ratio

This commit is contained in:
Arkadiusz Fal
2021-11-07 18:53:00 +01:00
parent f33319fd64
commit 76f0a1c66c
4 changed files with 29 additions and 14 deletions

View File

@@ -2,7 +2,7 @@ import Foundation
import SwiftUI
struct VideoPlayerSizeModifier: ViewModifier {
let geometry: GeometryProxy!
let geometry: GeometryProxy
let aspectRatio: Double?
let minimumHeightLeft: Double
@@ -11,7 +11,7 @@ struct VideoPlayerSizeModifier: ViewModifier {
#endif
init(
geometry: GeometryProxy? = nil,
geometry: GeometryProxy,
aspectRatio: Double? = nil,
minimumHeightLeft: Double? = nil
) {
@@ -21,15 +21,10 @@ struct VideoPlayerSizeModifier: ViewModifier {
}
func body(content: Content) -> some View {
// TODO: verify if optional GeometryProxy is still used
if geometry != nil {
content
.frame(maxHeight: maxHeight)
.aspectRatio(usedAspectRatio, contentMode: usedAspectRatioContentMode)
.edgesIgnoringSafeArea(edgesIgnoringSafeArea)
} else {
content.edgesIgnoringSafeArea(edgesIgnoringSafeArea)
}
content
.frame(maxHeight: maxHeight)
.aspectRatio(usedAspectRatio, contentMode: usedAspectRatioContentMode)
.edgesIgnoringSafeArea(edgesIgnoringSafeArea)
}
var usedAspectRatio: Double {