From 87b1bad45e4eb730ea07686a2b2558253c60d3b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateo=20Guzm=C3=A1n?= Date: Mon, 16 Dec 2024 04:42:38 -0800 Subject: [PATCH] ActivityIndicator: setting `resource-id` from the `testID` prop (#48271) Summary: Fixes https://github.com/facebook/react-native/issues/39092 Right now, the `testID` prop that is passed to the ActivityIndicator component is not being applied as a `resource-id`. In this PR, we overwrite the `onInitializeAccessibilityNodeInfo` in the `ProgressBarContainerView` to set this `resource-id`. ## Changelog: [ANDROID][ADDED] - ActivityIndicator: setting `resource-id` from the `testID` prop Pull Request resolved: https://github.com/facebook/react-native/pull/48271 Test Plan: Render a simple activity indicator and pass a `testID` as follows: ```tsx import {ActivityIndicator} from 'react-native'; function Playground() { return ( ); } ```
Inspect the element using an e2e tool such as Maestro or Appium, the `resource-id` is not present: (see screenshot) image
--- Apply the changes and then:
Inspect again, the `resource-id` is present now: (see screenshot) image
Reviewed By: rshest Differential Revision: D67274852 Pulled By: javache fbshipit-source-id: 2ac8d2bbebed5d1723eb33e735bbf3b477a42572 --- .../views/progressbar/ProgressBarContainerView.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 c24b2540fd5..ef9d89f1eae 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,8 +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 com.facebook.react.R import com.facebook.react.bridge.JSApplicationIllegalArgumentException /** @@ -27,6 +29,15 @@ internal class ProgressBarContainerView(context: Context) : FrameLayout(context) private var progressBar: ProgressBar? = null + 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() { this.progressBar?.let { progressBar -> progressBar.isIndeterminate = indeterminate