0

I'm trying to add a youTube video on to my page and the code is in a swift file called VideoView but when I try and put VideoView(youtubeID: "id here") in my home page code it either creates another view or dosent show at all and I want it to be below what I've got the page already but also want to add more below the video. Thanks.

here's my homepage code:

struct Home: View {
    var body: some View {
        ScrollView {
            VStack(spacing: 0) {
                ZStack {
                    Image("")
                        .resizable()
                        .scaledToFill()
                    VStack(alignment: .leading) {
                        VStack(alignment: .leading) {
                            Text("")
                                .font(.title3)
                                .foregroundColor(Color.white)
                                .multilineTextAlignment(.leading)
                                .padding(.leading)
                                .padding(.top)
                            Text("")
                                .font(.title)
                                .foregroundColor(Color.white)
                                .multilineTextAlignment(.leading)
                                .padding(.leading)
                                .padding(.bottom)
                        }
                        .background(.opacity(0.3))
                        .cornerRadius(15)
                        
                        
                    }
                }
                VStack(alignment: .leading) {
                    ZStack {
                        Rectangle()
                            .frame(height: 75)
                        Text("")
                            .foregroundColor(.white)
                            .tracking(5)
                    }
                    VStack(alignment: .leading) {
                        Text("")
                            .font(.headline)
                            .padding([.top, .leading, .trailing])
                            .padding(.bottom, 1.0)
                        Text("")
                            .font(.body)
                            .padding(.horizontal)
                            .foregroundColor(Color.primary)
                        Divider()
                        Text("")
                            .font(.subheadline)
                            .fontWeight(.bold)
                            .padding([.top, .leading, .trailing])
                            .padding(.bottom, 1.0)
                        Text("")
                            .font(.callout)
                            .padding(.horizontal)
                        Divider()
                    }
                }
            }
        }.edgesIgnoringSafeArea(.top)
    }
}

here's VideoView code:

import SwiftUI
import WebKit

struct VideoView: UIViewRepresentable {
    
    let videoID: String
    
    func makeUIView(context: Context) -> WKWebView {
        return WKWebView()
    }
    
    func updateUIView(_ uiView: WKWebView, context: Context) {
        guard let youtubeURL = URL(string: "https://www.youtube.com/embed/\(videoID)") else {return}
        uiView.scrollView.isScrollEnabled = false
        uiView.load(URLRequest(url: youtubeURL))
    }
}

enter image description here

Ash
  • 81
  • 9
  • 1
    Could you add some images showing what layout you've got right now? – Throvn Aug 20 '22 at 16:20
  • Actually it is not clear where do you put your `VideoView`, but I assume in ScrollView, so it is conflict of scroll views (WKWebView has own scrollview). This should be helpful https://stackoverflow.com/a/59790493/12299030. – Asperi Aug 20 '22 at 16:21
  • @Throvn I've added images now – Ash Aug 20 '22 at 16:52
  • @Asperi when I put it in scrollview it doesn't show – Ash Aug 20 '22 at 16:53

0 Answers0