How to display PHLivePhotoView in SwiftUI

929 Views Asked by At

I'm working on a basic app for live photos and try to build user interface on SwiftUI. However, I don't understand how to display Live Photos properly. Is it possible to incorporate PHLivePhotoView into SwiftUI?

1

There are 1 best solutions below

0
Igor Kashin On BEST ANSWER

As @Asperi mentioned, UIViewRepresentable wrapper is a way to go:

import SwiftUI
import PhotosUI

struct LivePhotoView: UIViewRepresentable {
    @Binding var livephoto: PHLivePhoto

    func makeUIView(context: Context) -> PHLivePhotoView {
        return PHLivePhotoView()
    }

    func updateUIView(_ lpView: PHLivePhotoView, context: Context) {
        lpView.livePhoto = livephoto
    }
}