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.
ReactNativeHander
search forFlexbox
object for control and set all the layout properties toFlexbox
.- Whenever
Flexbox
gets a property update, it passes the value to internalYGNode
object. - Whenever
UIManager
receives update on component hierarchy (add/delete/move), it also requestsFlexbox
to update hierarchy ofYGNode
s - When
RootView
is ready, it triggers recalculation ofFlexbox
hierarchy - When calculation completed,
Flexbox
read results fromYGNode
s and assign them to QML controls.