From 1416d5109ccf08707dcb40ee5615819cea0c0f08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateo=20Guzm=C3=A1n?= Date: Sat, 14 Dec 2024 10:16:07 +0100 Subject: [PATCH 1/3] feat(progress-bar): [android] setting resource-id from testID --- .../ProgressBarAccessibilityDelegate.kt | 18 ++++++++++++++++++ .../progressbar/ProgressBarContainerView.kt | 5 +++++ 2 files changed, 23 insertions(+) create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ProgressBarAccessibilityDelegate.kt diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ProgressBarAccessibilityDelegate.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ProgressBarAccessibilityDelegate.kt new file mode 100644 index 00000000000000..c86229707f9564 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ProgressBarAccessibilityDelegate.kt @@ -0,0 +1,18 @@ +package com.facebook.react.views.progressbar + +import android.view.View +import androidx.core.view.AccessibilityDelegateCompat +import androidx.core.view.accessibility.AccessibilityNodeInfoCompat +import com.facebook.react.R + +internal class ProgressBarAccessibilityDelegate : AccessibilityDelegateCompat() { + override fun onInitializeAccessibilityNodeInfo(host: View, info: AccessibilityNodeInfoCompat) { + super.onInitializeAccessibilityNodeInfo(host, info) + + val testId = host.getTag(R.id.react_test_id) as String? + + if (testId != null) { + info.viewIdResourceName = testId + } + } +} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ProgressBarContainerView.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ProgressBarContainerView.kt index c24b2540fd5760..50a9f5aea5aab2 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ProgressBarContainerView.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ProgressBarContainerView.kt @@ -12,6 +12,7 @@ import android.graphics.PorterDuff import android.view.ViewGroup import android.widget.FrameLayout import android.widget.ProgressBar +import androidx.core.view.ViewCompat import com.facebook.react.bridge.JSApplicationIllegalArgumentException /** @@ -27,6 +28,10 @@ internal class ProgressBarContainerView(context: Context) : FrameLayout(context) private var progressBar: ProgressBar? = null + init { + ViewCompat.setAccessibilityDelegate(this, ProgressBarAccessibilityDelegate()) + } + internal fun apply() { this.progressBar?.let { progressBar -> progressBar.isIndeterminate = indeterminate From ed27966bff5b138b74e9f3390c9d55a532783574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateo=20Guzm=C3=A1n?= Date: Sat, 14 Dec 2024 10:27:09 +0100 Subject: [PATCH 2/3] fix(progress-bar): [android] adding copyright to the accessibility delegate file --- .../views/progressbar/ProgressBarAccessibilityDelegate.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ProgressBarAccessibilityDelegate.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ProgressBarAccessibilityDelegate.kt index c86229707f9564..77a5a323a18c6e 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ProgressBarAccessibilityDelegate.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ProgressBarAccessibilityDelegate.kt @@ -1,3 +1,10 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + package com.facebook.react.views.progressbar import android.view.View From d5a918f82b26ed3c23f02c76f4a334e6fc18e461 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateo=20Guzm=C3=A1n?= Date: Mon, 16 Dec 2024 00:42:04 +0100 Subject: [PATCH 3/3] refactor(progress-bar): [android] simplifying approach to set resource-id --- .../ProgressBarAccessibilityDelegate.kt | 25 ------------------- .../progressbar/ProgressBarContainerView.kt | 12 ++++++--- 2 files changed, 9 insertions(+), 28 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ProgressBarAccessibilityDelegate.kt diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ProgressBarAccessibilityDelegate.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ProgressBarAccessibilityDelegate.kt deleted file mode 100644 index 77a5a323a18c6e..00000000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ProgressBarAccessibilityDelegate.kt +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.react.views.progressbar - -import android.view.View -import androidx.core.view.AccessibilityDelegateCompat -import androidx.core.view.accessibility.AccessibilityNodeInfoCompat -import com.facebook.react.R - -internal class ProgressBarAccessibilityDelegate : AccessibilityDelegateCompat() { - override fun onInitializeAccessibilityNodeInfo(host: View, info: AccessibilityNodeInfoCompat) { - super.onInitializeAccessibilityNodeInfo(host, info) - - val testId = host.getTag(R.id.react_test_id) as String? - - if (testId != null) { - info.viewIdResourceName = testId - } - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ProgressBarContainerView.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ProgressBarContainerView.kt index 50a9f5aea5aab2..ef9d89f1eae749 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ProgressBarContainerView.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ProgressBarContainerView.kt @@ -10,9 +10,10 @@ package com.facebook.react.views.progressbar import android.content.Context import android.graphics.PorterDuff import android.view.ViewGroup +import android.view.accessibility.AccessibilityNodeInfo import android.widget.FrameLayout import android.widget.ProgressBar -import androidx.core.view.ViewCompat +import com.facebook.react.R import com.facebook.react.bridge.JSApplicationIllegalArgumentException /** @@ -28,8 +29,13 @@ internal class ProgressBarContainerView(context: Context) : FrameLayout(context) private var progressBar: ProgressBar? = null - init { - ViewCompat.setAccessibilityDelegate(this, ProgressBarAccessibilityDelegate()) + override fun onInitializeAccessibilityNodeInfo(info: AccessibilityNodeInfo) { + super.onInitializeAccessibilityNodeInfo(info) + + val testId = getTag(R.id.react_test_id) as String? + if (testId != null) { + info.viewIdResourceName = testId + } } internal fun apply() {