From 9f4358142ea7d8f110bbb09dbe3896f5859d56b3 Mon Sep 17 00:00:00 2001 From: fabriziobertoglio1987 Date: Tue, 16 Aug 2022 04:26:20 -0700 Subject: [PATCH] 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 https://github.com/facebook/react-native/pull/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: https://github.com/facebook/react-native/pull/34371 Test Plan:
testing accessibilityLabelledBy with TextInput

https://user-images.githubusercontent.com/24992535/183593138-7ced1974-6a06-4f0f-822a-1ade1edc7212.mp4

testing accessibilityLabelledBy with Switch

![Screen Shot 2022-08-09 at 15 53 37](https://user-images.githubusercontent.com/24992535/183596336-4b73186b-6d27-485e-a6ea-29a0f0b9ef50.png)

testing paper renderer after the fix

https://user-images.githubusercontent.com/24992535/183605619-01f1be64-788a-43bd-88b0-a7b2cad75148.mp4

[1]: https://github.com/grgr-dkrk [2]: https://github.com/facebook/react-native/issues/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 --- .../react/uimanager/BaseViewManagerDelegate.java | 4 +++- .../js/examples/Accessibility/AccessibilityExample.js | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManagerDelegate.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManagerDelegate.java index 5c2ca1b828f07a..bb809381494e5e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManagerDelegate.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManagerDelegate.java @@ -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; @@ -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()); diff --git a/packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js b/packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js index 294db3d0e28edb..271a3db44bc7af 100644 --- a/packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js +++ b/packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js @@ -27,6 +27,7 @@ const { StyleSheet, Slider, Platform, + Switch, } = require('react-native'); import type {EventSubscription} from 'react-native/Libraries/vendor/emitter/EventEmitter'; @@ -228,6 +229,16 @@ class AccessibilityExample extends React.Component<{}> { /> + + + Enable Notifications + + + ); }