On React Native iOS source code

Source: Internet
Author: User


Original link
Http://www.open-open.com/lib/view/open1465637638193.html

Each project has a portal, which is then initialized, and React Native is no exception. The only clue that a project without OBJECTIVE-C code leaves us is the code in the Appdelegate file:

Rctrootview *rootview = [[Rctrootview alloc] initwithbundleurl:jscodelocation                                                      modulename:@ " Reading "                                                initialproperties:nil                                                   launchoptions:launchoptions];

Everything the user can see comes from this rootview, and all the initialization work is done within this method.

Inside this method, React Native actually creates a Bridge object before Rootview is created. It is a bridge between Objective-c and JavaScript, and subsequent methods of interaction depend entirely on it, and the ultimate purpose of the entire initialization process is to create this bridge object.

The core of the initialization method is the Setup method (under RCTBRIDGE.M), and the main task of the Setup method is to create the Batchedbridge.

-(void) setup{ ...   [self createbatchedbridge];  Rct_profile_end_event (0@ "", nil);}

  

The role of Batchedbridge is to bulk read JavaScript's method calls to Objective-c, while it internally holds a javascriptexecutor, as the name implies, that this object is used to execute JavaScript code.

The key to creating Batchedbridge is the Start method, which can be divided into five steps:

    1. Read JavaScript source code
    2. Initializing module information
    3. The executor that initializes the JavaScript code, the Rctjscexecutor object
    4. Generate a list of modules and write to the JavaScript side
    5. Execute JavaScript Source code

On React Native iOS source code

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.