mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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 ( <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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
6076a41560
commit
87b1bad45e
+11
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user