Saturday, November 21, 2026
HomeiOS Developmentswift - React Native IOS Bridge Native View - correct method to...

swift – React Native IOS Bridge Native View – correct method to name Native Technique from JS aspect

[ad_1]

I wish to talk about the choices i’ve come throughout for calling a local methodology from a IOS ViewManager/View in JS aspect with out utilizing properties however direct methodology calls.

Possibility A:

implementing a way within the ViewManager which searches for the proper view and calls the given methodology within the view, like this:

func callMethodViaManager(_ node:NSNumber) {
DispatchQueue.primary.async {
let myView = self.bridge.uiManager.view(forReactTag: node) as! MyView
myView.myMethod()
  }
}

after which within the JS aspect implement a handler like this:

 const handleSomething = (e) => { 
  UIManager.dispatchViewManagerCommand(
  ReactNative.findNodeHandle(ref.present),
  UIManager.SwiftComponent.Instructions.callMethodViaManager,
  [])
 };

That is only a quick abstract of the related components, the method in full could be seen in full element possibly only a bit outdated however with some changes one can get it to work additionally with purposeful parts:

https://medium.com/@jjdanek/react-native-calling-class-methods-on-native-swift-views-521faf44f3dc

Possibility B:

For this selection let’s go together with one of the best situation which is that one can get all the required knowledge, setup, and many others on the ViewManager prepared through delegates for instance or another sample or Swift sugar.

Calling the Native strategies within the ViewManager from the JS aspect immediately with the usage of NativeModules, like this:

 const handleSomething = (e) => { 
 NativeModules.MyViewManager.myMethod()
 };

I couldn’t discover a lot about this selection in correlation to a Native View being bridged, this fashion of doing it’s used for Native Module bridging explicitly. The one issues i might discover the place:

React Native UI Part Technique

or guides like these one:

https://teabreak.e-spres-oh.com/swift-in-react-native-the-ultimate-guide-part-1-modules-9bb8d054db03#4377

I’ve tried each strategies and at first look they appear to work each.

So my questions are:

Why is Possibility A the higher answer/choice and the one which is advisable or most used?

What’s flawed or can go flawed with Possibility B?

Is there the rest to consider?

Is there a greater means which isn’t trough properties?

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments