Facebook Announces Yoga
Zone Leader John Vester examines the cross-platform layout engine that has been recently announced by the team at Facebook.
Join the DZone community and get the full member experience.Join For Free
the development team at facebook recently released yoga. i know you might be tempted to stop reading this post and immediately search "facebook yoga" to cut to the chase. but be warned that the results will more likely resemble groups with pages on facebook focused on physical, mental, and spiritual practices than anything programming related.
let me save you from one of those internet searches that don't provide exactly the results you are expecting.
what is facebook yoga?
emil sjölander, a software engineer at facebook, recently announced yoga , calling it a "cross-platform layout engine" for application design. with the varied approaches for layouts often differing across application platforms (android, ios, web-based), teams developing across multiple platforms are often duplicating efforts to meet their current needs.
"today, layout is handled differently on each platform, through systems like auto layout on ios, composable containers on android, and various css-based approaches on the web. having such a diverse set of layout systems makes it hard for teams building products to share solutions across platforms and increases the amount of time developers spend fixing platform-specific layout bugs."
- emil sjölander (facebook)
yoga introduces a cross-platform library (java for android, objective-c for uikit and c# for .net) that can be used in products like react native, components for android and oculus. the team is continuing to extend their reach by migrating some views in instagram as well as componentkit.
as one might expect, yoga is oss too, which can be found here at github.
how does it work?
using java as an (android) example, a new yoganode (called root) can be established with some initial properties being set:
yoganode root = new yoganode(); root.setwidth(500); root.setheight(300); root.setalignitems(center); root.setjustifycontent(center); root.setpadding(all, 20);
from there, nodes for a text box and image can be configured as well:
yoganode text = new yoganode(); text.setwidth(200); text.setheight(25); yoganode image = new yoganode(); image.setwidth(50); image.setheight(50); image.setpositiontype(absolute); image.setposition(end, 20); image.setposition(top, 20);
finally, the text and image nodes can be attached to the root node:
root.addchildat(text, 0); root.addchildat(image, 1);
when displayed, the end-result will appear as follows:
facebook yoga is intended to reduce the effort of designing layouts across multiple platforms while fostering the goal of creating an optimal layout that can be shared and optimized. emil sjölander has even stated that "sharing a layout implementation across platforms has also enabled us to optimize performance once and see the gains across many product and platforms."
software engineering teams that support different platforms should consider using facebook yoga to standardize on the layout aspect of their applications. in doing so, these teams can work together to build a reusable layout that can be applied to all the platforms that yoga supports. since yoga is part of the open source community, team members can give back and contribute to the project where improvements or optimizations are found.
what are your thoughts? will yoga be part of your application design in 2017?
have a really great day!
Opinions expressed by DZone contributors are their own.