gpt4 book ai didi

ios - 在 React Native 中使用 nativeID/使用 RCTRootView subview 的正确方法是什么?

转载 作者:行者123 更新时间:2023-11-29 05:28:11 25 4
gpt4 key购买 nike

我有一个现有的 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);
<小时/>

这是我的 RN 层次结构

<View>
<View>
<Text />
<ScrollView /> <--
<View>
</View>

我想在 native 端获取此 ScrollView 。根据文档 nativeID 应该有所帮助。但是,我在 JS 端定义的 RCTRootView 内看不到任何 subview 。事实上, Root View 只有一个名为 RCTRootContentView 的 subview ,它没有任何其他可用的 subview 。

所以我的问题是在 native 端获取 RCRootView subview 的正确方法是什么?

我尝试了一些方法,例如使用 UIManageraddUIBlock 来获取 View 寄存器,但我认为我遗漏了一个明显的点与 RCTRootView 及其工作原理相关。

有趣的是,如果我在 RN 层次结构中直接使用 native 注册的组件(通过 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?
})
}
}
<小时/>

任何帮助都会有帮助,谢谢!

最佳答案

In fact, root view only has a single subview called RCTRootContentView which does not have any further subviews available.

这对我来说似乎是一个问题。 <Text/> JS 中的节点应该创建 UITextView native 内容 View 中的子项。也许尝试实际添加一些内容到 <Text/><ScrollView/>让它渲染?

I want to get a hold of this ScrollView on the native side.

您能否提供更多关于您正在尝试做的事情的背景信息?我有一种感觉nativeID API 不是您想要使用的。

关于ios - 在 React Native 中使用 nativeID/使用 RCTRootView subview 的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57941841/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com