在reactnative和iOS混合開發(fā)過程中, 繼承自RCTViewManager的原生組件, 必須實現(xiàn)方法:
override func view() -> UIView {
}
由于對RCTViewManager的docs沒有細看, 導致出現(xiàn)如下代碼:
lazy var testView: TestView = {
let view = TestView()
return view
}()
override func view() -> UIView {
return testView
}
這樣會導致該testView無法釋放, 無論多少界面使用該testView, 加載的始終是一個view, init方法只走一次, 通過對RCTViewManager文檔的了解, 表明該view不該被緩存, 始終加載的是新的view
/**
* This method instantiates a native view to be managed by the module. Override
* this to return a custom view instance, which may be preconfigured with default
* properties, subviews, etc. This method will be called many times, and should
* return a fresh instance each time. The view module MUST NOT cache the returned
* view and return the same instance for subsequent calls.
*/
- (UIView *)view;
解決方法:
override func view() -> UIView {
return TestView()
}
小細節(jié), 特此小記!!!