This
Code Block import UIKit |
| import SwiftUI |
|
| import Combine |
|
|
|
| struct ContentView: View { |
|
| @State private var isPresented = false |
|
|
|
| var body: some View { |
|
| Button("Show Modal with full screen") { |
|
| self.isPresented.toggle() |
|
| } |
|
| .fullScreenCover(isPresented: $isPresented, content: VideoList.init) |
|
| } |
|
| } |
|
|
|
| struct VideoList: View { |
|
| @Environment(\.presentationMode) var presentationMode |
|
| @ObservedObject private(set) var viewModel: ViewModel |
|
| @State private var isRefreshing = false |
|
|
|
| var body: some View { |
|
| NavigationView { |
|
| List(viewModel.videos.sorted { $0.id > $1.id}, id: \.id) { video in |
|
| NavigationLink( |
|
| destination: VideoDetails(viewModel: VideoDetails.ViewModel(video: video))) { |
|
| VideoRow(video: video) |
|
| } |
|
| } |
|
| .onPullToRefresh(isRefreshing: $isRefreshing, perform: { |
|
| self.viewModel.fetchVideos() |
|
| }) |
|
| .onReceive(viewModel.$videos, perform: { _ in |
|
| self.isRefreshing = false |
|
| }) |
|
| .navigationBarTitle(viewModel.navigationBarTitle) |
|
| } |
|
| .onAppear(perform: viewModel.fetchVideos) |
|
| .frame(maxWidth: .infinity, maxHeight: .infinity) |
|
| .background(Color.red) |
|
| .edgesIgnoringSafeArea(.all) |
|
| .onTapGesture { |
|
| presentationMode.wrappedValue.dismiss() |
|
| } |
|
| } |
|
| } |
|
|
|
| #if DEBUG |
|
| struct VideoList_Previews: PreviewProvider { |
|
| static var previews: some View { |
|
| NavigationView { |
|
| VideoList(viewModel: .init()) |
|
| } |
|
| } |
|
| } |
|
| #endif |
creates this error on line 19: Cannot convert value of type '(Environment<Binding<PresentationMode>>, VideoList.ViewModel) -> VideoList' to expected argument type '() -> VideoList'