【问题标题】:Is there a way to retrieve react-native TextView in iOS Native app?有没有办法在 iOS Native 应用程序中检索 react-native TextView?
【发布时间】:2021-10-22 03:22:20
【问题描述】:

我正在为 react-native 构建一个桥接库,它是我的 SDK 的包装器。

在 Android 中,我可以通过从 react-native 端传递 nativeId 来拉出视图,使用:

  @ReactMethod
  fun initialiseValidation(uniqueId: String) {
     val rootView = reactContext.currentActivity?.window?.decorView?.rootView
     val myView = ReactFindViewUtil.findView(rootView, uniqueId) as EditText

现在我正在尝试在 iOS 中复制相同的内容 - 用 Swift 编写。

    @objc(initialiseValidation:withUniqueId:)
    func initialiseValidation(uniqueId: String) -> Void {
        let rootViewController = UIApplication.shared.delegate?.window??.rootViewController
#  ReactFindViewUtil cannot be found anywhere

我似乎无法使用ReactFindViewUtil——我怎样才能使用nativeId 获得Swift 中的TextView?

【问题讨论】:

    标签: ios swift react-native


    【解决方案1】:

    到目前为止,我通过一些解决方法来解决这个问题,我希望找到一些 Util。

    @objc
    func initialiseValidation(uniqueId: String) -> Void {
        DispatchQueue.main.async {
            let controller = RCTPresentedViewController();
            let panInput = self.searchForView(subViews: controller?.view!.subviews, nativeId: uniqueId)
    
    [...]                
    
    
    func searchForView(subViews: [UIView]?, nativeId: String) -> UITextField? {
        if (subViews == nil) {
            return nil
        }
        
        for subView in subViews! {
            if (subView.nativeID == nil) {
                let v = searchForView(subViews: subView.subviews, nativeId: nativeId)
                if (v != nil) {
                    return v
                }
            } else if (subView.nativeID! == nativeId) {
                let inputView = (subView as? RCTSinglelineTextInputView)?.backedTextInputView
                return inputView as! UITextField
            }
        }
        
        return nil
    }
    

    相关链接

    【讨论】:

      猜你喜欢
      • 2021-04-08
      • 1970-01-01
      • 2019-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-28
      相关资源
      最近更新 更多