Closed cuhte3 closed 3 years ago
I don't have time right now to test it, but if you find a solution I think it would be great to add an example into the Readme.
Try nesting a ThumbSelectorView
inside a UIView
.
struct VideoCoverImageSelectorView: UIViewRepresentable {
let asset: AVAsset?
var getThumbSelectorView: ((ThumbSelectorView) -> Void)?
func makeUIView(context: Context) -> FrameView {
let thumbSelectorFrameView = FrameView()
getThumbSelectorView?(thumbSelectorFrameView.thumbSelectorView)
thumbSelectorFrameView.thumbSelectorView.asset = asset
return thumbSelectorFrameView
}
func updateUIView(_ uiView: FrameView, context: Context) {
uiView.thumbSelectorView.asset = asset
}
class FrameView: UIView {
let thumbSelectorView = ThumbSelectorView()
override init(frame: CGRect) {
super.init(frame: frame)
addSubview(thumbSelectorView)
let constraints = [
thumbSelectorView.centerXAnchor.constraint(equalTo: centerXAnchor),
thumbSelectorView.centerYAnchor.constraint(equalTo: centerYAnchor),
thumbSelectorView.widthAnchor.constraint(equalTo: widthAnchor),
thumbSelectorView.heightAnchor.constraint(equalTo: heightAnchor),
]
NSLayoutConstraint.activate(constraints)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
}
Thanks for the great library! Am trying to use ThumbSelectorView in SwiftUI with UIViewRepresentable, but got the "could not calculate thumb size error". Looking for the past issues am assume i need to set ThumbSelectorView asset into viewDidAppear when the view rect is calculated, however there is no the kind of option is UIViewRepresentable lifecycle. Any advice how to use the ThumbSelectorView in SwiftUI?
example: