Skip to content

Commit 87b1bad

Browse files
mateoguzmanafacebook-github-bot
authored andcommitted
ActivityIndicator: setting resource-id from the testID prop (#48271)
Summary: Fixes #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: #48271 Test Plan: Render a simple activity indicator and pass a `testID` as follows: ```tsx import {ActivityIndicator} from 'react-native'; function Playground() { return ( <ActivityIndicator color="white" testID="default_activity_indicator" accessibilityLabel="Wait for content to load!" /> ); } ``` <details> <summary>Inspect the element using an e2e tool such as Maestro or Appium, the `resource-id` is not present: (see screenshot)</summary> <img width="736" alt="image" src="https://github.com/user-attachments/assets/3aecce5f-3850-4c62-b1ab-aed4133e12bc" /> </details> --- Apply the changes and then: <details> <summary>Inspect again, the `resource-id` is present now: (see screenshot)</summary> <img width="731" alt="image" src="https://github.com/user-attachments/assets/5a0e3bfa-924a-4a50-8eef-2f7fff7e1290" /> </details> Reviewed By: rshest Differential Revision: D67274852 Pulled By: javache fbshipit-source-id: 2ac8d2bbebed5d1723eb33e735bbf3b477a42572
1 parent 6076a41 commit 87b1bad

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ProgressBarContainerView.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ package com.facebook.react.views.progressbar
1010
import android.content.Context
1111
import android.graphics.PorterDuff
1212
import android.view.ViewGroup
13+
import android.view.accessibility.AccessibilityNodeInfo
1314
import android.widget.FrameLayout
1415
import android.widget.ProgressBar
16+
import com.facebook.react.R
1517
import com.facebook.react.bridge.JSApplicationIllegalArgumentException
1618

1719
/**
@@ -27,6 +29,15 @@ internal class ProgressBarContainerView(context: Context) : FrameLayout(context)
2729

2830
private var progressBar: ProgressBar? = null
2931

32+
override fun onInitializeAccessibilityNodeInfo(info: AccessibilityNodeInfo) {
33+
super.onInitializeAccessibilityNodeInfo(info)
34+
35+
val testId = getTag(R.id.react_test_id) as String?
36+
if (testId != null) {
37+
info.viewIdResourceName = testId
38+
}
39+
}
40+
3041
internal fun apply() {
3142
this.progressBar?.let { progressBar ->
3243
progressBar.isIndeterminate = indeterminate

0 commit comments

Comments
 (0)