使用Swift UIView和.xib文件来响应本机模块

问题描述

我正在构建一个自定义RN模块,我想在其中向其他人公开来自我的库的Swift UIView,以在他们的RN应用中使用。我有一个使用Swift UIView类的基本示例,该类显示在RN模块示例应用程序中:

@objc(TestViewManager)
class TestViewManager : RCTViewManager {
    
  override static func requiresMainQueueSetup() -> Bool {
    return true
  }

  override func view() -> UIView! {
    //let myCustomView: TestView = UIView.fromNib()
    return TestView()
  }
}

当我尝试用笔尖加载TestView时(使用myCustomView fromNib()init),RN应用会生成并运行,但随后崩溃。这是我的UIView扩展名:

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-我的.xib文件名为TestView.xib,并且文件所有者设置为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")
    }

}

RN模块中是否允许“ .xib”文件?我找不到关于此的任何文档。有没有人有任何建议或知道是否可行?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)