[英]What is the correct way of using nativeID / working with RCTRootView subviews in React Native?
I have an existing iOS app and I am using react native's RCTRootView
to draw some components for my app. 我有一个现有的iOS应用程序,并且正在使用react native的
RCTRootView
为我的应用程序绘制一些组件。
// swift
private lazy var RNContent: RCTRootView = {
let mockData:NSDictionary = ["someProps": self.someProps]
let RNContent = RCTRootView(bridge: self.bridge, moduleName: "RNContent", initialProperties: mockData as [NSObject : AnyObject])!
return RNContent
}()
// JS
AppRegistry.registerComponent('RNContent', () => component);
Here is what my RN hierarchy looks like 这是我的RN层次结构
<View>
<View>
<Text />
<ScrollView /> <--
<View>
</View>
I want to get a hold of this ScrollView
on the native side. 我想在本地获取此
ScrollView
。 As per the docs nativeID
should help. 根据文档
nativeID
应该会有所帮助。 However, I can't see any subviews inside the RCTRootView
that I define in JS side. 但是,我看不到我在JS端定义的
RCTRootView
内部的RCTRootView
视图。 In fact, root view only has a single subview called RCTRootContentView
which does not have any further subviews available. 实际上,根视图仅具有一个称为
RCTRootContentView
子视图,该子视图没有任何其他可用的子视图。
So my question is what is the correct way to get hold of the subviews of RCRootView
on the native side? 所以我的问题是在本机端获取
RCRootView
子视图的正确方法是什么?
I have tried a few things like, using the UIManager
's addUIBlock
to get hold of the view register, but I think there is an obvious point I am missing related to the RCTRootView
and how it works. 我已经尝试了一些方法,例如,使用
UIManager
的addUIBlock
来获取视图寄存器,但是我认为我缺少与RCTRootView
及其工作方式有关的明显点。
Interestingly, if I directly use a natively registered component (registered via RCT_EXTERN_MODULE
) in my RN hierarchy I can see that this component is detached from the RCTRootContentView
and it also has a nativeID that I assigned to it on the JS side. 有趣的是,如果我在RN层次结构中直接使用一个本机注册的组件(通过
RCT_EXTERN_MODULE
注册),则可以看到该组件已从RCTRootContentView
分离出来,并且还具有在JS端分配给它的nativeID。
RCTExecuteOnUIManagerQueue {
self.bridge.uiManager.addUIBlock { (uiManager: RCTUIManager?, viewRegistry:[NSNumber : UIView]?) in
uiManager?.view(forNativeID: "SelfAssignedID", withRootTag: self. RNContent.reactTag) // nil
viewRegistry?.forEach({ (key: NSNumber, value: UIView) in
print("Test1: ", key, value.nativeID) // only native components has nativeID, which does makes sense because RCTRootContentView doesn't have subviews... but why not? is there a way to get hold of them? If not, why not?
})
}
}
Any help would be helpful, thanks! 任何帮助都会有所帮助,谢谢!
In fact, root view only has a single subview called RCTRootContentView which does not have any further subviews available.
实际上,根视图仅具有一个称为RCTRootContentView的子视图,该子视图没有任何其他可用的子视图。
This seems like an issue to me. 对我来说,这似乎是一个问题。 The
<Text/>
node in JS should be creating a UITextView
child in the native content view. JS中的
<Text/>
节点应在本机内容视图中创建UITextView
子级。 Maybe try actually adding some content to <Text/>
and <ScrollView/>
to get it to render? 也许尝试实际向
<Text/>
和<ScrollView/>
添加一些内容以使其呈现?
I want to get a hold of this ScrollView on the native side.
我想在本地获取此ScrollView。
Can you give some more context on what you're trying to do? 您可以针对您要做的事情提供更多背景信息吗? I have a feeling
nativeID
API isn't what you want to use. 我觉得
nativeID
API不是您要使用的API。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.