Can't get Lumina camera to go away

27 Views Asked by At

I'm trying to develop an iOS app that has camera functionality using the Lumina framework. The majority of the app is built using SwiftUI, but I understand that Lumina was built to work with UIKit. I have set up a button that shows the camera, but I cant' get the cancel button to dismiss the camera.

I am using two Swift files to control the camera, Measure.swift and ViewController.swift, which I have copied out below.

//Measure.swift
import SwiftUI
import AVKit
import Lumina

struct Measure: UIViewControllerRepresentable {
    @Binding var isCameraVisible: Bool
    func makeUIViewController(context: Context) -> ViewController {
        let vc = ViewController()
        return vc
        
    }
    
    func updateUIViewController(_ uiViewController: ViewController, context: Context) {
        uiViewController.beginAppearanceTransition(true, animated: true)
        uiViewController.endAppearanceTransition()
    }
    func makeCoordinator() -> Coordinator {
            return Coordinator(isCameraVisible: $isCameraVisible)
    }


    class Coordinator: NSObject, LuminaDelegate {
        @Binding var isCameraVisible: Bool

        init(isCameraVisible: Binding<Bool>) {
                _isCameraVisible = isCameraVisible
        }

        func videoRecordingCaptured(_ videoURL: URL?, error: Error?) {
            isCameraVisible = false
        }

        func dismissed(controller: ViewController) {
            controller.dismiss(animated: true, completion: nil)
            isCameraVisible = false
        }
     
    }

    
    

    
}
struct MeasureWrapper: View {

    @State private var isCameraVisible = false

    var body: some View {
        NavigationStack{
            if isCameraVisible {
                Measure(isCameraVisible: $isCameraVisible)
                    .edgesIgnoringSafeArea(.all)
                    
            }
            else {
                Button(action: {
                        isCameraVisible.toggle()
                    }) {
                        Text("Show camera")
                }                    
                
            }
        }
    }
}

struct Measure_Previews: PreviewProvider {
    static var previews: some View {
        MeasureWrapper()
    }
}

//ViewController.swift
import UIKit
import Lumina
  

class ViewController: UIViewController {
    var delegate: LuminaDelegate?

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        let camera = LuminaViewController()
        camera.delegate = self 
        camera.setShutterButton(visible: false)
        camera.setTorchButton(visible: false)
        present(camera, animated: true, completion: nil)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}
extension ViewController: LuminaDelegate {
    func dismissed(controller: ViewController) {
        controller.dismiss(animated: true, completion: nil)
    }
}
0

There are 0 best solutions below