I am building a custom RN module where I want to expose Swift UIViews from my library to others to use in their RN app. I have a basic example working with a Swift UIView class showing up in my RN module example app:
@objc(TestViewManager)
class TestViewManager : RCTViewManager {
override static func requiresMainQueueSetup() -> Bool {
return true
}
override func view() -> UIView! {
//let myCustomView: TestView = UIView.fromNib()
return TestView()
}
}
When I try to load TestView with nib (using the myCustomView fromNib() init) the RN app builds and runs but then crashes. This is my UIView extension:
extension UIView {
class func fromNib<T: UIView>() -> T {
return Bundle(for: T.self).loadNibNamed(String(describing: T.self), owner: nil, options: nil)![0] as! T
}
}
TestView.swift - my .xib
file is named TestView.xib and has File Owner set to TestView.swift:
public class TestView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
Are .xib files "allowed" in RN modules? I couldn't find any docs on this. Does anyone have any suggestions or know if this is possible?