When I put AVPlayerViewController
wrapped into UIViewControllerRepresentable
as a fullscreen background of my view, it forces the main content view to ignore safe area.
var body: some View {
VStack(spacing: 0) {
HStack {
Text("Some text")
Spacer()
}
Spacer()
}
.padding(16)
.foregroundColor(Color.white)
.background(
VideoPlayerController(videoURL: videoURL, isPlaying: $isPlaying)
.edgesIgnoringSafeArea(.all)
)
}
In the example above the text ignores safe area.
VideoPlayerController:
struct VideoPlayerController: UIViewControllerRepresentable {
typealias UIViewControllerType = AVPlayerViewController
var videoURL: URL
@Binding var isPlaying: Bool
let showPlaybackControls = false
func makeUIViewController(context: Context) -> AVPlayerViewController {
let player = AVPlayer(url: videoURL)
let playerController = AVPlayerViewController()
playerController.player = player
playerController.showsPlaybackControls = showPlaybackControls
return playerController
}
func updateUIViewController(_ uiViewController: AVPlayerViewController, context: Context) {
if isPlaying {
uiViewController.player?.play()
} else {
uiViewController.player?.pause()
}
}
}
But if I make the background a plain view, the text doesn't ignore safe area anymore
struct ExerciseVideoScreen: View {
let videoURL: URL
@State var isPlaying: Bool = false
var body: some View {
VStack(spacing: 0) {
HStack {
Text("Some text")
Spacer()
}
Spacer()
}
.padding(16)
.foregroundColor(Color.white)
.background(
Color.red
.edgesIgnoringSafeArea(.all)
)
}
}
Is there a way to resolve this issue?