From 119fd1efe7c52db9d6591f48dac60d0a35dca031 Mon Sep 17 00:00:00 2001 From: Kevin Gozali Date: Mon, 11 Jun 2018 19:47:26 -0700 Subject: [PATCH] iOS: Fixed some props conversion errors Summary: * numbers in JS are doubles in native land, since there's no notion of int or int64 in JS - so simply convert numbers to int instead of assuming it's int * the parsing of Yoga props with `'...%'` string value has a bug: it should be copying the number instead of the `%` Reviewed By: shergin Differential Revision: D8370873 fbshipit-source-id: 44e9e3f0530c000c963e8e9ca66e8b0a48d80bcd --- ReactCommon/fabric/core/propsConversions.h | 6 +++++- ReactCommon/fabric/view/conversions.h | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ReactCommon/fabric/core/propsConversions.h b/ReactCommon/fabric/core/propsConversions.h index 548b88f3d..bf2f96f6c 100644 --- a/ReactCommon/fabric/core/propsConversions.h +++ b/ReactCommon/fabric/core/propsConversions.h @@ -17,7 +17,11 @@ namespace facebook { namespace react { inline void fromDynamic(const folly::dynamic &value, bool &result) { result = value.getBool(); } -inline void fromDynamic(const folly::dynamic &value, int &result) { result = value.getInt(); } +inline void fromDynamic(const folly::dynamic &value, int &result) { + // All numbers from JS are treated as double, and JS cannot represent int64 in practice. + // So this always converts the value to int64 instead. + result = value.asInt(); +} inline void fromDynamic(const folly::dynamic &value, std::string &result) { result = value.getString(); } template diff --git a/ReactCommon/fabric/view/conversions.h b/ReactCommon/fabric/view/conversions.h index cec142a7b..66cb25da0 100644 --- a/ReactCommon/fabric/view/conversions.h +++ b/ReactCommon/fabric/view/conversions.h @@ -201,7 +201,7 @@ inline void fromDynamic(const folly::dynamic &value, YGValue &result) { return; } else { if (stringValue.back() == '%') { - result = { folly::to(stringValue.substr(stringValue.length() - 1)), YGUnitPercent }; + result = { folly::to(stringValue.substr(0, stringValue.length() - 1)), YGUnitPercent }; return; } else { result = { folly::to(stringValue), YGUnitPoint };