mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-06-16 06:42:37 +08:00
Summary: Our long-term plan is to completely illuminate `jsi::Value`-to-`folly::dynamic` serialization step in prop parsing process improving performance and memory pressure. At the same time, we don't want to introduce a hard dependency in application code to JSI because it exposes direct access to VM and prevents parsing some data that come *NOT* from JSVM. RawValue is an extremely light-weight (hopefully fully optimized-out) abstraction that provides limited JSON-like and C++-idiomatic interface. The current particular implementation is still using `folly::dynamic` inside, but I have fully JSI-powered one which will replace the current one right after we figure out how to deal with folly::dynamic-specific callsites. Or we can implement RawValue in a hybrid manner if a code-size implication of that will be minimal. Reviewed By: JoshuaGross, mdvacca Differential Revision: D13962466 fbshipit-source-id: e848522fd242f21e9e771773f2103f1c1d9d7f21
105 lines
2.4 KiB
C++
105 lines
2.4 KiB
C++
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <folly/dynamic.h>
|
|
#include <react/components/view/AccessibilityPrimitives.h>
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
inline void fromString(const std::string &string, AccessibilityTraits &result) {
|
|
if (string == "none") {
|
|
result = AccessibilityTraits::None;
|
|
return;
|
|
}
|
|
if (string == "button") {
|
|
result = AccessibilityTraits::Button;
|
|
return;
|
|
}
|
|
if (string == "link") {
|
|
result = AccessibilityTraits::Link;
|
|
return;
|
|
}
|
|
if (string == "image") {
|
|
result = AccessibilityTraits::Image;
|
|
return;
|
|
}
|
|
if (string == "selected") {
|
|
result = AccessibilityTraits::Selected;
|
|
return;
|
|
}
|
|
if (string == "plays") {
|
|
result = AccessibilityTraits::PlaysSound;
|
|
return;
|
|
}
|
|
if (string == "keyboardkey") {
|
|
result = AccessibilityTraits::KeyboardKey;
|
|
return;
|
|
}
|
|
if (string == "text") {
|
|
result = AccessibilityTraits::StaticText;
|
|
return;
|
|
}
|
|
if (string == "disabled") {
|
|
result = AccessibilityTraits::NotEnabled;
|
|
return;
|
|
}
|
|
if (string == "frequentUpdates") {
|
|
result = AccessibilityTraits::UpdatesFrequently;
|
|
return;
|
|
}
|
|
if (string == "search") {
|
|
result = AccessibilityTraits::SearchField;
|
|
return;
|
|
}
|
|
if (string == "startsMedia") {
|
|
result = AccessibilityTraits::StartsMediaSession;
|
|
return;
|
|
}
|
|
if (string == "adjustable") {
|
|
result = AccessibilityTraits::Adjustable;
|
|
return;
|
|
}
|
|
if (string == "allowsDirectInteraction") {
|
|
result = AccessibilityTraits::AllowsDirectInteraction;
|
|
return;
|
|
}
|
|
if (string == "pageTurn") {
|
|
result = AccessibilityTraits::CausesPageTurn;
|
|
return;
|
|
}
|
|
if (string == "header") {
|
|
result = AccessibilityTraits::Header;
|
|
return;
|
|
}
|
|
abort();
|
|
}
|
|
|
|
inline void fromRawValue(const RawValue &value, AccessibilityTraits &result) {
|
|
if (value.hasType<std::string>()) {
|
|
fromString((std::string)value, result);
|
|
return;
|
|
}
|
|
|
|
if (value.hasType<std::vector<std::string>>()) {
|
|
result = {};
|
|
auto items = (std::vector<std::string>)value;
|
|
for (auto &item : items) {
|
|
AccessibilityTraits itemAccessibilityTraits;
|
|
fromString(item, itemAccessibilityTraits);
|
|
result = result | itemAccessibilityTraits;
|
|
}
|
|
}
|
|
|
|
abort();
|
|
}
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|