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:
- Read JavaScript source code
- Initializing module information
- The executor that initializes the JavaScript code, the Rctjscexecutor object
- Generate a list of modules and write to the JavaScript side
- Execute JavaScript Source code
On React Native iOS source code