Skip to content

Commit 9f43581

Browse files
fabOnReactfacebook-github-bot
authored andcommitted
accessibilityLabelledBy use DynamicFromObject to parse String to Dynamic (#34371)
Summary: `accessibilityLabelledBy` accepts String or Array type. - The JavaScript Array type corresponds to java [ReadableArray][3] ([HybridData][4]) - The JavaScript String type corresponds to the java String Use [DynamicFromObject][5] to parse String to Dynamic. https://github.com/facebook/react-native/blob/e509f96baf5e523301a5c9567c416508ff20d175/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java#L222-L228 All credits to [grgr-dkrk][1] (PR #32470). fixes [https://github.com/facebook/react-native/issues/30846][2] ## Changelog [Android] [Fixed] - accessibilityLabelledBy use DynamicFromObject to parse String to Dynamic Pull Request resolved: #34371 Test Plan: <details><summary>testing accessibilityLabelledBy with TextInput</summary> <p> https://user-images.githubusercontent.com/24992535/183593138-7ced1974-6a06-4f0f-822a-1ade1edc7212.mp4 </p> </details> <details><summary>testing accessibilityLabelledBy with Switch</summary> <p> ![Screen Shot 2022-08-09 at 15 53 37](https://user-images.githubusercontent.com/24992535/183596336-4b73186b-6d27-485e-a6ea-29a0f0b9ef50.png) </p> </details> <details><summary>testing paper renderer after the fix</summary> <p> https://user-images.githubusercontent.com/24992535/183605619-01f1be64-788a-43bd-88b0-a7b2cad75148.mp4 </p> </details> [1]: https://github.com/grgr-dkrk [2]: #30846 [3]: https://github.com/facebook/react-native/blob/e509f96baf5e523301a5c9567c416508ff20d175/ReactAndroid/src/main/java/com/facebook/react/bridge/ReadableArray.java#L1 [4]: https://github.com/facebookincubator/fbjni/blob/main/java/com/facebook/jni/HybridData.java [5]: https://github.com/facebook/react-native/blob/e509f96baf5e523301a5c9567c416508ff20d175/ReactAndroid/src/main/java/com/facebook/react/bridge/DynamicFromObject.java#L74 Reviewed By: lunaleaps Differential Revision: D38706360 Pulled By: huntie fbshipit-source-id: e4771552d3fddfad50f4d4cbbf971fe4a718e134
1 parent 3d21852 commit 9f43581

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManagerDelegate.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import androidx.annotation.Nullable;
1212
import com.facebook.react.bridge.ColorPropConverter;
1313
import com.facebook.react.bridge.Dynamic;
14+
import com.facebook.react.bridge.DynamicFromObject;
1415
import com.facebook.react.bridge.ReadableArray;
1516
import com.facebook.react.bridge.ReadableMap;
1617
import com.facebook.yoga.YogaConstants;
@@ -92,7 +93,8 @@ public void setProperty(T view, String propName, @Nullable Object value) {
9293
mViewManager.setNativeId(view, (String) value);
9394
break;
9495
case ViewProps.ACCESSIBILITY_LABELLED_BY:
95-
mViewManager.setAccessibilityLabelledBy(view, (Dynamic) value);
96+
Dynamic dynamicFromObject = new DynamicFromObject(value);
97+
mViewManager.setAccessibilityLabelledBy(view, dynamicFromObject);
9698
break;
9799
case ViewProps.OPACITY:
98100
mViewManager.setOpacity(view, value == null ? 1.0f : ((Double) value).floatValue());

packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const {
2727
StyleSheet,
2828
Slider,
2929
Platform,
30+
Switch,
3031
} = require('react-native');
3132
import type {EventSubscription} from 'react-native/Libraries/vendor/emitter/EventEmitter';
3233

@@ -228,6 +229,16 @@ class AccessibilityExample extends React.Component<{}> {
228229
/>
229230
</View>
230231
</RNTesterBlock>
232+
<RNTesterBlock title="Switch with accessibilityLabelledBy attribute">
233+
<View>
234+
<Text nativeID="formLabel4">Enable Notifications</Text>
235+
<Switch
236+
value={true}
237+
accessibilityLabel="switch test1"
238+
accessibilityLabelledBy="formLabel4"
239+
/>
240+
</View>
241+
</RNTesterBlock>
231242
</View>
232243
);
233244
}

0 commit comments

Comments
 (0)