Skip to content

Commit f747e04

Browse files
joevilchesfacebook-github-bot
authored andcommitted
Let accessible be std::optional in native
Summary: We want to change Text so that if it has links, and no `accessible` value set, it becomes accessible by default for keyboards. To do that we need native to know if "no value is set". This means changing from a `bool` to a `std::optional<bool>`. This diff does that and fixes any build errors. Runtime should be the same, since the default at all the callsites is false (the default before), and JS overrides will still apply. Changelog: [Internal] Reviewed By: javache Differential Revision: D74914316
1 parent 9218d1e commit f747e04

File tree

7 files changed

+8
-6
lines changed

7 files changed

+8
-6
lines changed

packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ - (NSArray *)accessibilityElements
179179
// If the component is not `accessible`, we return an empty array.
180180
// We do this because logically all nested <Text> components represent the content of the <Paragraph> component;
181181
// in other words, all nested <Text> components individually have no sense without the <Paragraph>.
182-
if (!_textView.state || !paragraphProps.accessible) {
182+
if (!_textView.state || !paragraphProps.accessible.value_or(false)) {
183183
return [NSArray new];
184184
}
185185

packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
344344

345345
// `accessible`
346346
if (oldViewProps.accessible != newViewProps.accessible) {
347-
self.accessibilityElement.isAccessibilityElement = newViewProps.accessible;
347+
self.accessibilityElement.isAccessibilityElement = newViewProps.accessible.value_or(false);
348348
}
349349

350350
// `accessibilityLabel`

packages/react-native/ReactAndroid/src/main/jni/react/fabric/FocusOrderingHelper.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ void FocusOrderingHelper::traverseAndUpdateNextFocusableElement(
118118
// focused and present in the hierarchy
119119
if (currNode->getTraits().check(ShadowNodeTraits::Trait::KeyboardFocusable) ||
120120
(props != nullptr &&
121-
(props->focusable || props->accessible || props->hasTVPreferredFocus))) {
121+
(props->focusable || props->accessible.value_or(false) ||
122+
props->hasTVPreferredFocus))) {
122123
LayoutMetrics nodeLayoutMetrics = uimanager.getRelativeLayoutMetrics(
123124
*currNode, parentShadowNode.get(), {.includeTransform = true});
124125

packages/react-native/ReactCommon/react/renderer/components/view/AccessibilityProps.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class AccessibilityProps {
3131

3232
#pragma mark - Props
3333

34-
bool accessible{false};
34+
std::optional<bool> accessible{std::nullopt};
3535
std::optional<AccessibilityState> accessibilityState{std::nullopt};
3636
std::string accessibilityLabel;
3737
std::vector<std::string> accessibilityOrder{};

packages/react-native/ReactCommon/react/renderer/components/view/ConcreteViewShadowNode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ class ConcreteViewShadowNode : public ConcreteShadowNode<
118118
BaseShadowNode::orderIndex_ = 0;
119119
}
120120

121+
// TODO why is this not needed
121122
bool isKeyboardFocusable =
122123
HostPlatformViewTraitsInitializer::isKeyboardFocusable(props) ||
123124
props.accessible;

packages/react-native/ReactCommon/react/renderer/components/view/ViewShadowNode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void ViewShadowNode::initialize() noexcept {
4848

4949
bool formsStackingContext = !viewProps.collapsable ||
5050
viewProps.pointerEvents == PointerEventsMode::None ||
51-
!viewProps.nativeId.empty() || viewProps.accessible ||
51+
!viewProps.nativeId.empty() || viewProps.accessible.value_or(false) ||
5252
viewProps.opacity != 1.0 || viewProps.transform != Transform{} ||
5353
(viewProps.zIndex.has_value() &&
5454
viewProps.yogaStyle.positionType() != yoga::PositionType::Static) ||

packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/HostPlatformViewProps.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ folly::dynamic HostPlatformViewProps::getDiffProps(
692692
}
693693

694694
if (accessible != oldProps->accessible) {
695-
result["accessible"] = accessible;
695+
result["accessible"] = accessible.value_or(false);
696696
}
697697

698698
if (getClipsContentToBounds() != oldProps->getClipsContentToBounds()) {

0 commit comments

Comments
 (0)