簡體   English   中英

有沒有辦法在 iOS 本機應用程序中檢索 react-native TextView?

[英]Is there a way to retrieve react-native TextView in iOS Native app?

我正在為 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 中的nativeId

到目前為止,我通過一些變通辦法解決了這個問題,我希望能找到一些 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
}

相關鏈接

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM