mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-06-17 07:20:20 +08:00
Fabric: properly convert prop value with object shape
Summary:
For props that expects a struct/object value, like scrollView's contentInset, not all keys may be present. For example:
```
<ScrollView ... contentInset={{top: 10}} />
```
In this example, `left`, `bottom`, and `right` should just default to 0 (or whatever the default is in the platform). Before this fix, an exception occured when calling `fromRawValue()` because it is assuming all 4 keys are present in the prop bag. However, only `top` key was present in this example.
To fix this, we have to loop through the available keys in the prop bag, then assign the values accordingly.
Reviewed By: JoshuaGross
Differential Revision: D14868549
fbshipit-source-id: e25208eb31f6d4061338e9cac48a93fe71859859
This commit is contained in:
committed by
Facebook Github Bot
parent
6aa896896f
commit
63343dad2e
@@ -73,7 +73,13 @@ inline std::string toString(const SharedColor &value) {
|
||||
inline void fromRawValue(const RawValue &value, Point &result) {
|
||||
if (value.hasType<better::map<std::string, Float>>()) {
|
||||
auto map = (better::map<std::string, Float>)value;
|
||||
result = {map.at("x"), map.at("y")};
|
||||
for (const auto &pair : map) {
|
||||
if (pair.first == "x") {
|
||||
result.x = pair.second;
|
||||
} else if (pair.first == "y") {
|
||||
result.y = pair.second;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -90,7 +96,13 @@ inline void fromRawValue(const RawValue &value, Point &result) {
|
||||
inline void fromRawValue(const RawValue &value, Size &result) {
|
||||
if (value.hasType<better::map<std::string, Float>>()) {
|
||||
auto map = (better::map<std::string, Float>)value;
|
||||
result = {map.at("width"), map.at("height")};
|
||||
for (const auto &pair : map) {
|
||||
if (pair.first == "width") {
|
||||
result.width = pair.second;
|
||||
} else if (pair.first == "height") {
|
||||
result.height = pair.second;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -112,7 +124,17 @@ inline void fromRawValue(const RawValue &value, EdgeInsets &result) {
|
||||
|
||||
if (value.hasType<better::map<std::string, Float>>()) {
|
||||
auto map = (better::map<std::string, Float>)value;
|
||||
result = {map.at("top"), map.at("left"), map.at("bottom"), map.at("right")};
|
||||
for (const auto &pair : map) {
|
||||
if (pair.first == "top") {
|
||||
result.top = pair.second;
|
||||
} else if (pair.first == "left") {
|
||||
result.left = pair.second;
|
||||
} else if (pair.first == "bottom") {
|
||||
result.bottom = pair.second;
|
||||
} else if (pair.first == "right") {
|
||||
result.right = pair.second;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -134,10 +156,17 @@ inline void fromRawValue(const RawValue &value, CornerInsets &result) {
|
||||
|
||||
if (value.hasType<better::map<std::string, Float>>()) {
|
||||
auto map = (better::map<std::string, Float>)value;
|
||||
result = {map.at("topLeft"),
|
||||
map.at("topRight"),
|
||||
map.at("bottomLeft"),
|
||||
map.at("bottomRight")};
|
||||
for (const auto &pair : map) {
|
||||
if (pair.first == "topLeft") {
|
||||
result.topLeft = pair.second;
|
||||
} else if (pair.first == "topRight") {
|
||||
result.topRight = pair.second;
|
||||
} else if (pair.first == "bottomLeft") {
|
||||
result.bottomLeft = pair.second;
|
||||
} else if (pair.first == "bottomRight") {
|
||||
result.bottomRight = pair.second;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user