From b30ad9a77d7e3078d7fd7aa352830cde53d4dcbc Mon Sep 17 00:00:00 2001 From: Joshua Gross Date: Wed, 29 Jun 2022 19:07:17 -0700 Subject: [PATCH] Fix accessibilityRole prop parsing Summary: During the refactor in D36889794 (https://github.com/facebook/react-native/commit/782e004e4943194c40f2fb15527fe99a61f69b88) and later D37050215 (https://github.com/facebook/react-native/commit/47280de85e62f33f0b97bc1ed7c83bc6ca0dc7d4) this block of code was erroneously deleted; add it back, because if the props iterator setter is disabled, nothing sets this property anymore. Changelog: [Internal] Reviewed By: ryancat, nscoding Differential Revision: D37539700 fbshipit-source-id: 0850180721e0549fed6089cb278402c56eb9d627 --- .../components/view/AccessibilityProps.cpp | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/ReactCommon/react/renderer/components/view/AccessibilityProps.cpp b/ReactCommon/react/renderer/components/view/AccessibilityProps.cpp index 01c76f6385e..d3a91fdfa35 100644 --- a/ReactCommon/react/renderer/components/view/AccessibilityProps.cpp +++ b/ReactCommon/react/renderer/components/view/AccessibilityProps.cpp @@ -166,7 +166,30 @@ AccessibilityProps::AccessibilityProps( rawProps, "testID", sourceProps.testId, - "")) {} + "")) { + // It is a (severe!) perf deoptimization to request props out-of-order. + // Thus, since we need to request the same prop twice here + // (accessibilityRole) we "must" do them subsequently here to prevent + // a regression. It is reasonable to ask if the `at` function can be improved; + // it probably can, but this is a fairly rare edge-case that (1) is easy-ish + // to work around here, and (2) would require very careful work to address + // this case and not regress the more common cases. + if (!enablePropIteratorSetter) { + const auto *rawPropValue = + rawProps.at("accessibilityRole", nullptr, nullptr); + AccessibilityTraits traits; + std::string roleString; + if (rawPropValue == nullptr || !rawPropValue->hasValue()) { + traits = AccessibilityTraits::None; + roleString = ""; + } else { + fromRawValue(context, *rawPropValue, traits); + fromRawValue(context, *rawPropValue, roleString); + } + accessibilityTraits = traits; + accessibilityRole = roleString; + } +} void AccessibilityProps::setProp( const PropsParserContext &context,