WIP
This commit is contained in:
@@ -395,6 +395,8 @@
|
||||
1CF65A9F2A452D290042FFBD /* PBXTargetDependency */,
|
||||
);
|
||||
name = Werkout_ios;
|
||||
packageProductDependencies = (
|
||||
);
|
||||
productName = Werkout_ios;
|
||||
productReference = 1CF65A222A3972840042FFBD /* Werkout_ios.app */;
|
||||
productType = "com.apple.product-type.application";
|
||||
@@ -443,6 +445,8 @@
|
||||
Base,
|
||||
);
|
||||
mainGroup = 1CF65A192A3972840042FFBD;
|
||||
packageReferences = (
|
||||
);
|
||||
productRefGroup = 1CF65A232A3972840042FFBD /* Products */;
|
||||
projectDirPath = "";
|
||||
projectRoot = "";
|
||||
|
||||
@@ -10,17 +10,20 @@ import AVKit
|
||||
|
||||
struct ExternalWorkoutDetailView: View {
|
||||
@StateObject var bridgeModule = BridgeModule.shared
|
||||
let videoPlayer = VideoPlayerView(url: URL(string: "https://dev.werkout.fitness/media/exercise_videos/Isometric_Bear_Crawl_with_Shoulder_Taps.mp4")!)
|
||||
@State var videoURL = URL(string: "https://dev.werkout.fitness/media/exercise_videos/recovery.mp4")!
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
if let workout = bridgeModule.currentWorkout {
|
||||
GeometryReader { metrics in
|
||||
VStack {
|
||||
HStack {
|
||||
if let currentExercise = bridgeModule.currentExercise {
|
||||
videoPlayer
|
||||
.frame(width: metrics.size.width * 0.6, height: metrics.size.height * 0.8)
|
||||
}
|
||||
VideoViewControllerView(url: $videoURL)
|
||||
.frame(width: metrics.size.width * 0.6, height: metrics.size.height * 0.8)
|
||||
// if let videoPlayer = videoPlayer {
|
||||
// videoPlayer
|
||||
// .frame(width: metrics.size.width * 0.6, height: metrics.size.height * 0.8)
|
||||
// }
|
||||
|
||||
ExtExerciseList(workout: workout,
|
||||
currentExerciseIdx: bridgeModule.currentExerciseIdx)
|
||||
@@ -38,10 +41,10 @@ struct ExternalWorkoutDetailView: View {
|
||||
Text("nothing here bro")
|
||||
}
|
||||
}
|
||||
.onChange(of: bridgeModule.currentExercise, perform: { newValue in
|
||||
if let newValue = newValue,
|
||||
let _videoURL = URL(string: BaseURLs.dev.rawValue + newValue.exercise.videoURL) {
|
||||
videoPlayer.updateVideoURL(url: _videoURL)
|
||||
.onChange(of: bridgeModule.currentExercise, perform: { newValue in
|
||||
if let viddd = newValue?.exercise.videoURL,
|
||||
let url = URL(string: BaseURLs.dev.rawValue + viddd) {
|
||||
videoURL = url
|
||||
}
|
||||
})
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
|
||||
@@ -24,33 +24,69 @@ struct VideoPlayerView: View {
|
||||
.frame(maxWidth: .infinity)
|
||||
.background(Color(uiColor: UIColor(red: 0.11, green: 0.11, blue: 0.12, alpha: 1)))
|
||||
|
||||
SafariWebView(url: $url)
|
||||
VideoViewControllerView(url: $url)
|
||||
}
|
||||
.background(.black)
|
||||
}
|
||||
|
||||
func updateVideoURL(url: URL) {
|
||||
self.url = url
|
||||
}
|
||||
}
|
||||
|
||||
struct SafariWebView: UIViewControllerRepresentable {
|
||||
struct VideoViewControllerView: UIViewControllerRepresentable {
|
||||
@Binding var url: URL
|
||||
|
||||
func makeUIViewController(context: Context) -> VideoViewController {
|
||||
return VideoViewController(videoURL: url)
|
||||
}
|
||||
|
||||
func updateUIViewController(_ uiViewController: VideoViewController, context: Context) {
|
||||
if url != uiViewController.videoURL {
|
||||
uiViewController.videoURL = url
|
||||
uiViewController.layoutView()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class VideoViewController: UIViewController {
|
||||
var videoURL: URL
|
||||
|
||||
func makeUIViewController(context: Context) -> SFSafariViewController {
|
||||
return SFSafariViewController(url: url)
|
||||
init(videoURL: URL) {
|
||||
self.videoURL = videoURL
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
layoutView()
|
||||
}
|
||||
|
||||
func updateUIViewController(_ uiViewController: SFSafariViewController, context: Context) {
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
}
|
||||
|
||||
func layoutView() {
|
||||
self.view.subviews.forEach({
|
||||
$0.removeFromSuperview()
|
||||
})
|
||||
|
||||
let sfVC = SFSafariViewController(url: self.videoURL)
|
||||
sfVC.view.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.backgroundColor = .green
|
||||
self.addChild(sfVC)
|
||||
sfVC.didMove(toParent: self)
|
||||
sfVC.view.backgroundColor = .magenta
|
||||
sfVC.view.frame = self.view.bounds;
|
||||
self.view.addSubview(sfVC.view)
|
||||
sfVC.view.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
|
||||
sfVC.view.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
|
||||
sfVC.view.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
|
||||
sfVC.view.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
|
||||
}
|
||||
}
|
||||
|
||||
//struct VideoPlayerView_Previews: PreviewProvider {
|
||||
// static let exercise = PreviewData.parseExercises().first!
|
||||
//
|
||||
// static var previews: some View {
|
||||
// VideoPlayerView(url: Bundle.main.url(forResource: "Straight_Leg_Sit_Up", withExtension: "mp4")!)
|
||||
// }
|
||||
//}
|
||||
|
||||
struct VideoPlayerView_Previews: PreviewProvider {
|
||||
static let exercise = PreviewData.parseExercises().first!
|
||||
|
||||
static var previews: some View {
|
||||
VideoPlayerView(url: Bundle.main.url(forResource: "Straight_Leg_Sit_Up", withExtension: "mp4")!)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user