SwiftUI with RoomPlan ?

Hi everyone,

In the demo code and in the video of the RoomPlan framework, UIKit is used with it. However, I would like to know if it is possible to use SwiftUI with RoomPlan instead of UIKit.

Best regards,

Clement

You can use a UIViewRepresentable together with a singleton, not sure if this is the best way to do so but it works for me :) here's a quick example:

Model (here you setup your RoomCaptureView)

final class Model : ObservableObject, RoomCaptureViewDelegate {
    static var shared = Model()
    
    @Published var roomCaptureView : RoomCaptureView

    var captureSessionConfig : RoomCaptureSession.Configuration
    
    init() {
        roomCaptureView = RoomCaptureView(frame: .zero)
        captureSessionConfig = RoomCaptureSession.Configuration()
    }
        
    func startSession() {
        roomCaptureView.captureSession.run(configuration: captureSessionConfig)
    }
    
    func stopSession() {
        roomCaptureView.captureSession.stop()
    }

func captureView(shouldPresent roomDataForProcessing: CapturedRoomData, error: Error?) -> Bool {
        return true
    }
    
    // Here you will get the final post-processed results.
    func captureView(didPresent processedResult: CapturedRoom, error: Error?) {
        if let error = error {
            print("Error: \(error)")
        }

    }
}

UIViewRepresentable

struct RoomCaptureRep: UIViewRepresentable {
        
    
    func makeUIView(context: Context) -> RoomCaptureView {
        return Model.shared.roomCaptureView
    }
    
    func updateUIView(_ uiView: RoomCaptureView, context: Context) {
    }
    
}

Usage

struct CoolRoomPlanView : View {
    @StateObject var model = Model.shared
    var body : some View {
        ZStack {
            RoomCaptureRep()
            Button {
                model.startSession()
            } label: {
                Text( "Start")
            }
        }
    }
}

Yes. A swiftUI implementation of Roomplan is available as a github repo => https://github.com/deurell/roomscanner

SwiftUI with RoomPlan ?
 
 
Q