Fix where navigationview is determined

This commit is contained in:
Ethan Pippin 2021-08-20 22:00:42 -06:00
parent e677be7128
commit 365cacc2ae
2 changed files with 39 additions and 46 deletions

View File

@ -211,7 +211,7 @@ class PlayerViewController: UIViewController, GCKDiscoveryManagerListener, GCKRe
@IBAction func settingsButtonTapped(_ sender: UIButton) { @IBAction func settingsButtonTapped(_ sender: UIButton) {
optionsVC = VideoPlayerSettingsView() optionsVC = VideoPlayerSettingsView()
optionsVC?.delegate = self optionsVC?.playerDelegate = self
optionsVC?.modalPresentationStyle = .popover optionsVC?.modalPresentationStyle = .popover
optionsVC?.popoverPresentationController?.sourceView = playerSettingsButton optionsVC?.popoverPresentationController?.sourceView = playerSettingsButton

View File

@ -8,9 +8,9 @@
import Foundation import Foundation
import SwiftUI import SwiftUI
class VideoPlayerSettingsView: UIViewController { class VideoPlayerSettingsView: UINavigationController {
private var contentView: UIHostingController<VideoPlayerSettings>! private var contentView: UIHostingController<VideoPlayerSettings>!
weak var delegate: PlayerViewController? weak var playerDelegate: PlayerViewController?
override var supportedInterfaceOrientations: UIInterfaceOrientationMask { override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
.landscape .landscape
@ -18,18 +18,13 @@ class VideoPlayerSettingsView: UIViewController {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
contentView = UIHostingController(rootView: VideoPlayerSettings(delegate: self.delegate ?? PlayerViewController()))
self.view.addSubview(contentView.view) self.viewControllers = [UIHostingController(rootView: VideoPlayerSettings(delegate: self.playerDelegate ?? PlayerViewController()))]
contentView.view.translatesAutoresizingMaskIntoConstraints = false
contentView.view.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
contentView.view.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
contentView.view.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
contentView.view.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
} }
override func viewWillDisappear(_ animated: Bool) { override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated) super.viewWillDisappear(animated)
self.delegate?.settingsPopoverDismissed() self.playerDelegate?.settingsPopoverDismissed()
} }
} }
@ -44,44 +39,42 @@ struct VideoPlayerSettings: View {
} }
var body: some View { var body: some View {
NavigationView { Form {
Form { Picker(NSLocalizedString("Closed Captions", comment: ""), selection: $captionTrack) {
Picker(NSLocalizedString("Closed Captions", comment: ""), selection: $captionTrack) { ForEach(delegate.subtitleTrackArray, id: \.id) { caption in
ForEach(delegate.subtitleTrackArray, id: \.id) { caption in Text(caption.name).tag(caption.id)
Text(caption.name).tag(caption.id)
}
} }
.onChange(of: captionTrack) { track in }
self.delegate.subtitleTrackChanged(newTrackID: track) .onChange(of: captionTrack) { track in
self.delegate.subtitleTrackChanged(newTrackID: track)
}
Picker(NSLocalizedString("Audio Track", comment: ""), selection: $audioTrack) {
ForEach(delegate.audioTrackArray, id: \.id) { caption in
Text(caption.name).tag(caption.id).lineLimit(1)
} }
Picker(NSLocalizedString("Audio Track", comment: ""), selection: $audioTrack) { }.onChange(of: audioTrack) { track in
ForEach(delegate.audioTrackArray, id: \.id) { caption in self.delegate.audioTrackChanged(newTrackID: track)
Text(caption.name).tag(caption.id).lineLimit(1) }
} Picker(NSLocalizedString("Playback Speed", comment: ""), selection: $playbackSpeedSelection) {
}.onChange(of: audioTrack) { track in ForEach(delegate.playbackSpeeds.indices, id: \.self) { speedIndex in
self.delegate.audioTrackChanged(newTrackID: track) let speed = delegate.playbackSpeeds[speedIndex]
Text("\(String(speed))x").tag(speedIndex)
} }
Picker(NSLocalizedString("Playback Speed", comment: ""), selection: $playbackSpeedSelection) { }
ForEach(delegate.playbackSpeeds.indices, id: \.self) { speedIndex in .onChange(of: playbackSpeedSelection, perform: { index in
let speed = delegate.playbackSpeeds[speedIndex] self.delegate.playbackSpeedChanged(index: index)
Text("\(String(speed))x").tag(speedIndex) })
} }.navigationBarTitleDisplayMode(.inline)
} .navigationTitle(NSLocalizedString("Audio & Captions", comment: ""))
.onChange(of: playbackSpeedSelection, perform: { index in .toolbar {
self.delegate.playbackSpeedChanged(index: index) ToolbarItemGroup(placement: .navigationBarLeading) {
}) if UIDevice.current.userInterfaceIdiom == .phone {
}.navigationBarTitleDisplayMode(.inline) Button {
.navigationTitle(NSLocalizedString("Audio & Captions", comment: "")) self.delegate.settingsPopoverDismissed()
.toolbar { } label: {
ToolbarItemGroup(placement: .navigationBarLeading) { HStack {
if UIDevice.current.userInterfaceIdiom == .phone { Image(systemName: "chevron.left")
Button { Text("Back").font(.callout)
self.delegate.settingsPopoverDismissed()
} label: {
HStack {
Image(systemName: "chevron.left")
Text("Back").font(.callout)
}
} }
} }
} }