0

I'm building a bridge library for react-native that is a wrapper around my SDK.

In Android, I can pull out a view by passing nativeId from react-native side, using:

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

Now I am trying to replicate the same in iOS - writing it in Swift.

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

I cannot seem to be able to use ReactFindViewUtil -- how can I get my hands on the TextView in Swift using the nativeId?

macalac
  • 11
  • 6

1 Answers1

0

So far I got this working with a bit of a workaround that I hope to find some Util for.

@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
}

Related links

macalac
  • 11
  • 6