react-native | Fix a crash on deserilization of props when using 'px'/'em' units.

Summary:
A huge set of props use YGValue directly, say something really basic like `margin`/`position`/`padding`/`border`.
All of these according to CSS spec actually support `number | "em" | "px" | %` units, but we are going to throw and hard crash on `em` and `px`, which are unsupported in React Native.

Using `tryTo` instead of `to` (noexcept vs throwing method) for conversion, and treating things like `margin: 50px` same way as we would treat `margin: false` which is not really supported.

Changelog:
    [General][Fixed] - Fixed a crash on deserialization of props when using 'px'/'em' units.

Reviewed By: bvanderhoof

Differential Revision: D37163250

fbshipit-source-id: 59cbe65a821052f6c7e9588b6d4a0ac14e344684
This commit is contained in:
Nikita Lutsenko
2022-06-15 00:12:58 -07:00
committed by Facebook GitHub Bot
parent c78babac39
commit 70788313fe
@@ -392,8 +392,11 @@ inline void fromRawValue(
YGUnitPercent};
return;
} else {
result = YGValue{folly::to<float>(stringValue), YGUnitPoint};
return;
auto tryValue = folly::tryTo<float>(stringValue);
if (tryValue.hasValue()) {
result = YGValue{tryValue.value(), YGUnitPoint};
return;
}
}
}
}