Skip to content

Commit

Permalink
accessibilityLabelledBy use DynamicFromObject to parse String to Dyna…
Browse files Browse the repository at this point in the history
…mic (#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
  • Loading branch information
fabOnReact authored and facebook-github-bot committed Aug 16, 2022
1 parent 3d21852 commit 9f43581
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import androidx.annotation.Nullable;
import com.facebook.react.bridge.ColorPropConverter;
import com.facebook.react.bridge.Dynamic;
import com.facebook.react.bridge.DynamicFromObject;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.yoga.YogaConstants;
Expand Down Expand Up @@ -92,7 +93,8 @@ public void setProperty(T view, String propName, @Nullable Object value) {
mViewManager.setNativeId(view, (String) value);
break;
case ViewProps.ACCESSIBILITY_LABELLED_BY:
mViewManager.setAccessibilityLabelledBy(view, (Dynamic) value);
Dynamic dynamicFromObject = new DynamicFromObject(value);
mViewManager.setAccessibilityLabelledBy(view, dynamicFromObject);
break;
case ViewProps.OPACITY:
mViewManager.setOpacity(view, value == null ? 1.0f : ((Double) value).floatValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const {
StyleSheet,
Slider,
Platform,
Switch,
} = require('react-native');
import type {EventSubscription} from 'react-native/Libraries/vendor/emitter/EventEmitter';

Expand Down Expand Up @@ -228,6 +229,16 @@ class AccessibilityExample extends React.Component<{}> {
/>
</View>
</RNTesterBlock>
<RNTesterBlock title="Switch with accessibilityLabelledBy attribute">
<View>
<Text nativeID="formLabel4">Enable Notifications</Text>
<Switch
value={true}
accessibilityLabel="switch test1"
accessibilityLabelledBy="formLabel4"
/>
</View>
</RNTesterBlock>
</View>
);
}
Expand Down

0 comments on commit 9f43581

Please sign in to comment.