Change NodeToString.cpp to output JSON not html (#1563)

Summary:

X-link: https://github.com/facebook/react-native/pull/42645

We want to be able to capture Yoga trees in production. To do this we need to serialize and deserialize the in-memory representation of a tree. We have a way to turn a tree into html using NodeToString.cpp but that outputs html, which is going to be hard to deserialize. So, I added the [nlohmann json library](https://github.com/nlohmann/json/tree/develop?tab=readme-ov-file) so that we can serialize into JSON instead. Then we need to change the inner workings of NodeToString.cpp to use this library instead of its html.

One of the bigger structural changes I made was standardizing the checks need to append something to the string. What we want is to only add something if it is not the default style. The existing logic does that but bears the burden of knowing what the default of certain styles actually is. This just calls the getter on a new node to obtain that value, which should simplify things a bit.

Reviewed By: NickGerleman

Differential Revision: D52929268
This commit is contained in:
Joe Vilches
2024-02-02 11:00:53 -08:00
committed by Facebook GitHub Bot
parent 4fcc0d8491
commit 292e2f3944
4 changed files with 24977 additions and 180 deletions

View File

@@ -17,3 +17,7 @@ file(GLOB SOURCES CONFIGURE_DEPENDS
add_library(capture STATIC ${SOURCES})
target_link_libraries(capture yogacore)
target_include_directories(capture
PUBLIC
$<BUILD_INTERFACE:${YOGA_ROOT}/lib>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include/yoga/lib>)