admin管理员组

文章数量:1122832

I am trying to record the current screen in my SwiftUI app.

The screen record start in the .onAppear { }

Then I stop the record once all the recording has done.

However when I try to show it the finished recording in a

.sheet(isPresented: $showPreview, onDismiss: {
        // Dismiss action
    }, content: {
        // Content
        rpView
    })

I get the blank sheet.

But when I do the following

if showPreview { rpView }

The recording shows on the screen. Not like the .sheet shows on the screen.

I want to show it how the .sheet shows the view on the screen.

How can I do it? Or is it not possible ?

This is how my UIViewControllerRepresentable looks like.

struct RPPreviewView: UIViewControllerRepresentable  {
    
    typealias UIViewControllerType = RPPreviewViewController
    
    let rpPreviewViewController: UIViewControllerType
    @Binding var isShow: Bool
    
    func makeCoordinator() -> Coordinator {
        Coordinator(self)
    }
    
    
    func makeUIViewController(context: Context) -> RPPreviewViewController {
        rpPreviewViewController.previewControllerDelegate = context.coordinator
        rpPreviewViewController.modalPresentationStyle = .pageSheet
        return rpPreviewViewController
    }
    
    func updateUIViewController(_ uiViewController: RPPreviewViewController, context: Context) { print(#function) }
    
    
    
    class Coordinator: NSObject, @preconcurrency RPPreviewViewControllerDelegate {
        
        var parent: RPPreviewView
        
        init(_ parent: RPPreviewView) {
            self.parent = parent
        }
        
        @MainActor func previewController(_ previewController: RPPreviewViewController, didFinishWithActivityTypes activityTypes: Set<String>) {
            previewController.dismiss(animated: true)
            parent.isShow = false
        }
        
    }
}

I referred to this to do this.

本文标签: swiftCannot show RPPreviewViewController with sheet modifier in SwiftUI WhyStack Overflow