Skip to content

Commit

Permalink
Reduce use of assertions in parsing accessibility props
Browse files Browse the repository at this point in the history
Summary:
Changelog:
[General][Fixed] - Reduce use of assertions when parsing accessibility props passed from JS

Fixes some more cases along the same lines as D43184380 (d16c1a0) and D43184994 (ee4714e).

Reviewed By: jacdebug

Differential Revision: D43324899

fbshipit-source-id: fb343203f16464009931f07592e663b06dcf20e7
  • Loading branch information
motiz88 authored and facebook-github-bot committed Feb 16, 2023
1 parent e665a0f commit a064de1
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <folly/dynamic.h>
#include <glog/logging.h>
#include <react/debug/react_native_assert.h>
#include <react/debug/react_native_expect.h>
#include <react/renderer/components/view/AccessibilityPrimitives.h>
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/core/propsConversions.h>
Expand Down Expand Up @@ -116,7 +117,7 @@ inline void fromRawValue(

result = {};

react_native_assert(value.hasType<std::vector<std::string>>());
react_native_expect(value.hasType<std::vector<std::string>>());
if (value.hasType<std::vector<std::string>>()) {
auto items = (std::vector<std::string>)value;
for (auto &item : items) {
Expand Down Expand Up @@ -188,7 +189,8 @@ inline void fromRawValue(
const PropsParserContext &context,
const RawValue &value,
ImportantForAccessibility &result) {
react_native_assert(value.hasType<std::string>());
result = ImportantForAccessibility::Auto;
react_native_expect(value.hasType<std::string>());
if (value.hasType<std::string>()) {
auto string = (std::string)value;
if (string == "auto") {
Expand All @@ -201,7 +203,7 @@ inline void fromRawValue(
result = ImportantForAccessibility::NoHideDescendants;
} else {
LOG(ERROR) << "Unsupported ImportantForAccessiblity value: " << string;
react_native_assert(false);
react_native_expect(false);
}
} else {
LOG(ERROR) << "Unsupported ImportantForAccessiblity type";
Expand Down Expand Up @@ -278,7 +280,8 @@ inline void fromRawValue(
const PropsParserContext &context,
const RawValue &value,
AccessibilityLiveRegion &result) {
react_native_assert(value.hasType<std::string>());
result = AccessibilityLiveRegion::None;
react_native_expect(value.hasType<std::string>());
if (value.hasType<std::string>()) {
auto string = (std::string)value;
if (string == "none") {
Expand All @@ -289,7 +292,7 @@ inline void fromRawValue(
result = AccessibilityLiveRegion::Assertive;
} else {
LOG(ERROR) << "Unsupported AccessibilityLiveRegion value: " << string;
react_native_assert(false);
react_native_expect(false);
}
} else {
LOG(ERROR) << "Unsupported AccessibilityLiveRegion type";
Expand Down

0 comments on commit a064de1

Please sign in to comment.