Ios.reactnative-2-about-bridge

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.