Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SwiftUI Modal Dismiss Problem #403

Open
halilyuce opened this issue Apr 10, 2021 · 0 comments
Open

SwiftUI Modal Dismiss Problem #403

halilyuce opened this issue Apr 10, 2021 · 0 comments

Comments

@halilyuce
Copy link

Hello guys, thanks for this amazing repo!

I'm using this with UIViewControllerRepresentable on SwiftUI and everything is working well. I just have a problem with modals. When I click to dismiss button, it's dismissing presented modals too. I just want to hide the image viewer.

Is there any possible way to do it? Maybe custom dismiss button action? I can dismiss with a boolean maybe.

Thanks in advance.

import SwiftUI
import SKPhotoBrowser

struct PhotoViewer: UIViewControllerRepresentable {
    @Binding var viewerImages:[SKPhoto]
    @Binding var currentPageIndex: Int
    
    func makeUIViewController(context: Context) -> SKPhotoBrowser {
        SKPhotoBrowserOptions.displayHorizontalScrollIndicator = false
        let browser = SKPhotoBrowser(photos: viewerImages)
        browser.initializePageIndex(currentPageIndex)
        browser.delegate = context.coordinator
        return browser
    }
    
    func makeCoordinator() -> Coordinator {
        Coordinator(self)
    }
    
    func updateUIViewController(_ browser: SKPhotoBrowser, context: Context) {
        browser.photos = viewerImages
        browser.currentPageIndex = currentPageIndex
    }
    
    class Coordinator: NSObject, SKPhotoBrowserDelegate {
        
        var control: PhotoViewer
        
        init(_ control: PhotoViewer) {
            self.control = control
        }
        
        func didShowPhotoAtIndex(_ browser: PhotoViewer) {
            self.control.currentPageIndex = browser.currentPageIndex
        }
        
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant