This article uses the hello-world project as an example to explain the ReactLynx rendering process in detail:
First Screen Rendering includes stages such as downloading the Bundle, loading the bundle, and drawing.
After the page starts, it first downloads the Bundle。
Once the bundle is downloaded, it enters the loading stage.
During the bundle loading stage, the content of the bundle—such as CSS stylesheets, scripts, and page configurations—is first parsed
After parsing the bundle, the Engine thread virtual machine executes the MTS.
Meanwhile, the background thread virtual machine loads, parses, and executes the BTS.
During BTS execution, you can observe the creation process of components.
The background thread does not block the Engine thread’s Element tree construction, resolve, layout, and other flows.
During the Element tree construction stage, the Element PAPI is called to convert the page structure into an Element tree.
Taking the hello-world project as an example, the first frame creates 1 page element, 6 view elements, 2 image elements, and 5 text elements.
In Trace, you can observe the complete process of creating Elements and setting their Events, Classes, and other attributes.
During the Resolve stage, the Element’s class, inline styles, and other attributes are parsed to determine the Element’s style, and the layout node tree is created.
As shown below, the Resolve stage covers the complete execution flow and the parsing of styles for <view className="Background" />
.
The layout stage measures and lays out the layout nodes. The following example shows the layout process of the <text>Tap the logo and have fun!</text>
node.
After the layout is complete, platform UIs are created, with various attributes and layout information set.
:::tip Element nodes containing only layout attributes will not create platform UI nodes. Nested text will be merged with their parent text node to create a single platform UI. ::
In the hello-world project, the following nodes create platform UI on the first screen:
When the system’s rendering callback occurs, the platform UI completes its first-screen drawing.
Taking the hello-world project as an example, clicking the Logo triggers an update, which demonstrates the component update rendering flow.
After clicking the Logo, LynxView processes the click event and sends the event to the background thread, triggering the corresponding node’s click event handler.
To better observe the execution timing of the click event callback in Trace, you can use the Trace API to add custom Trace events.
The App component updates the state of alterLogo in the click event callback.
After updating the component state, the component diff process is triggered, and the image node changes:
The following image shows the diff process for the App component:
After the component diff is complete, the update information is synchronized to the Engine thread, driving subsequent UI changes. In Trace, clicking the CallLepusMethod
event allows you to see the UI update process after component diff is complete.
The Engine thread shows the update process of the Element tree. As shown below, the Element tree removes one element and adds a new image element.
After the Element update is complete, the layout and UI are updated again.
After the Element tree update is complete, the background thread is notified to trigger the component’s useEffect callback.
To better observe the execution timing of the useEffect callback in Trace, use the Trace API to add custom trace events.