8000 Integration with SwiftUI · Issue #54 · awkward/Tatsi · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Integration with SwiftUI #54
Open
Open
@EstebanC02

Description

@EstebanC02

Hi, I am doing the library integration via SPM to my project in SwiftUI, but I have a problem because the Done at the top of the Tatsi view is not called and I can't get the selected images.

The code for the integration via UIViewControllerRepresentable is as follows:

import SwiftUI
import UIKit
// 1. Add Import Tatsi and Import Photos to your Swift
import Tatsi
import Photos

struct TatsiViewController: UIViewControllerRepresentable {
    
    @Binding var show: Bool
    
    func makeCoordinator() -> Coordinator {
        Coordinator(self)
    }
    
    func makeUIViewController(context: UIViewControllerRepresentableContext<TatsiViewController>) -> TatsiPickerViewController {
        
        // 2. (Optional) Create an instance of TatsiConfig and configure the settings.
        var config = TatsiConfig.default
        config.showCameraOption = false
        config.supportedMediaTypes = [.image]
        config.firstView = .userLibrary
        
        // 3. Create an instance of TatsiPickerViewController. TatsiPickerViewController(config:) allows you to use the config from the previous step
        let pickerViewController = TatsiPickerViewController(config: config)
        // 5. Set the pickerDelegate on TatsiPickerViewController
        pickerViewController.delegate = context.coordinator
        // 6. Present the TatsiPickerViewController
        return pickerViewController
    }
    
    func updateUIViewController(_ uiViewController: TatsiPickerViewController, context: UIViewControllerRepresentableContext<TatsiViewController>) {
        uiViewController.delegate = context.coordinator
    }
    
    // 4. Implement TatsiPickerViewControllerDelegate
    final class Coordinator: NSObject, TatsiPickerViewControllerDelegate, UINavigationControllerDelegate {
        
        var parent: TatsiViewController
        
        init(_ parent: TatsiViewController) {
            self.parent = parent
        }
        
        func pickerViewController(_ pickerViewController: TatsiPickerViewController, didPickAssets assets: [PHAsset]) {
            print("Picked assets: \(assets)")
            parent.show = false
        }
        
        func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
            picker.dismiss(animated: true, completion: nil)
            parent.show = false
        }
        
        func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
            picker.dismiss(animated: true, completion: nil)
            parent.show = false
        }
    }
}

What do I need to integrate in order to obtain the selected images? Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0