Interview frequency: …
Short answer
Yoga is an open-source layout engine written in C++ that translates Flexbox properties into precise pixel coordinates (x, y, width, height) understood by iOS and Android.
Explanation
Since iOS and Android do not support Flexbox in their native interfaces, Facebook developed the Yoga engine to calculate complex layouts at high C++ speed inside the Shadow Thread, then send the final geometry to UIView elements on iOS and ViewGroup elements on Android.
Code example
// React Native Flexbox code is calculated by Yoga C++:
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
}
});Common mistakes
- Believing that a mini web browser (WebView) is responsible for calculating and applying Flexbox styles.
Follow-up questions
- What are the main differences between browser CSS and the styling system in React Native?
- What is Fabric, and how does it differ from the old rendering system in React Native?