Yoga engine has api that works with "nodes". Every YGNode has a set of properties. Some of them used to setup layout settings, some - to read the calculated position of the node.
Every YGNode has a set of properties that control the layout of node (like minWidth, alignment, justification, etc.) and set of properties that contain calculated layout results (like x, y, width, height). You can join nodes in hierarchy and calculate it. Yoga engine will read "controlling" properties and save the result in "position" properties.
A lot of components in React Native have layout properties that are almost identical to properties in Yoga.
We have a Flexbox object that is wrapper to YGNode. It is responsible for getting layout props from JS side and turning them into QML position properties. Here is the process:
- We receive a set of layout properties from JS side.
ReactNativeHandersearch forFlexboxobject for control and set all the layout properties toFlexbox.- Whenever
Flexboxgets a property update, it passes the value to internalYGNodeobject. - Whenever
UIManagerreceives update on component hierarchy (add/delete/move), it also requestsFlexboxto update hierarchy ofYGNodes - When
RootViewis ready, it triggers recalculation ofFlexboxhierarchy - When calculation completed,
Flexboxread results fromYGNodes and assign them to QML controls.