Bridge
Async batched Bridge used to communicate with the JavaScript application.
1. Find the starting point-rctrootview
In the react-native based project, we see the following code in the APPDELEGATE.M file:
1 Rctrootview*rootview =[[Rctrootview alloc] Initwithbundleurl:jscodelocation2ModuleName:@"Awesomeproject"3 Launchoptions:launchoptions];4 5Self.window =[[UIWindow alloc] Initwithframe:[uiscreen mainscreen].bounds];6Uiviewcontroller *rootviewcontroller =[[Uiviewcontroller alloc] init];7Rootviewcontroller.view = Rootview;
The reason why you can use JS for iOS app development is that the Rctrootview class is the starting point for exploring its causes.
2. Rctbridge
Next Browse class Rctrootview source code, Rctrootview is UIView subclass, and very simple. There is one attribute:
1 ReadOnly Rctbridge *bridge;
Read through the Code of class Rctbridge, with very few 200~300 lines. However, the Discovery class Rctbatchedbridge inherits from the class Rctbridge.
Class Rctbatchedbridge is a private class of bridge modules that are only used in class Rctbridge. This design makes the interface and the complexity of the implementation
Separation.
3. Rctbatchedbridge
Observe the Initiailizer of the class Rctbatchedbridge and discover the ' Initjs ' call to the interface. Here at last and JS ' sex '.
1-(Instancetype) Initwithparentbridge: (Rctbridge *) Bridge2 {3 //Omit multiple lines of code4 // ...... 5 // ......6 7 /**8 * Start the application script9 */Ten [self initjs]; One } A returnSelf ; -}
Reference
1. react-native:rctbridge.m/h
Ios.reactnative-2-about-bridge