From a064de151f8314abacbd0f17127597266644fd78 Mon Sep 17 00:00:00 2001 From: Moti Zilberman Date: Thu, 16 Feb 2023 07:03:06 -0800 Subject: [PATCH] Reduce use of assertions in parsing accessibility props 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 (https://github.com/facebook/react-native/commit/d16c1a04d8ceaf6b6df07d734cd54d490b6c6093) and D43184994 (https://github.com/facebook/react-native/commit/ee4714e3693a3bd88215bd7a19ff805e3262b1c8). Reviewed By: jacdebug Differential Revision: D43324899 fbshipit-source-id: fb343203f16464009931f07592e663b06dcf20e7 --- .../components/view/accessibilityPropsConversions.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/ReactCommon/react/renderer/components/view/accessibilityPropsConversions.h b/ReactCommon/react/renderer/components/view/accessibilityPropsConversions.h index 6659e9d7104db3..c3ebe5608ee1fc 100644 --- a/ReactCommon/react/renderer/components/view/accessibilityPropsConversions.h +++ b/ReactCommon/react/renderer/components/view/accessibilityPropsConversions.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -116,7 +117,7 @@ inline void fromRawValue( result = {}; - react_native_assert(value.hasType>()); + react_native_expect(value.hasType>()); if (value.hasType>()) { auto items = (std::vector)value; for (auto &item : items) { @@ -188,7 +189,8 @@ inline void fromRawValue( const PropsParserContext &context, const RawValue &value, ImportantForAccessibility &result) { - react_native_assert(value.hasType()); + result = ImportantForAccessibility::Auto; + react_native_expect(value.hasType()); if (value.hasType()) { auto string = (std::string)value; if (string == "auto") { @@ -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"; @@ -278,7 +280,8 @@ inline void fromRawValue( const PropsParserContext &context, const RawValue &value, AccessibilityLiveRegion &result) { - react_native_assert(value.hasType()); + result = AccessibilityLiveRegion::None; + react_native_expect(value.hasType()); if (value.hasType()) { auto string = (std::string)value; if (string == "none") { @@ -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";