Skip to content

[Fabric] Implement nativeID #14659

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

anupriya13
Copy link
Contributor

@anupriya13 anupriya13 commented May 12, 2025

Description

Type of Change

  • New feature (non-breaking change which adds functionality)

Why

[Fabric] Implement nativeID

Resolves #13830 #13728 #12514

What

[Fabric] Implemented nativeID
Mapped native Id to UIA_AutomationIdPropertyId

React Native Prop UI Automation Property Purpose
testID UIA_AutomationIdPropertyId Identifies the element uniquely for tests
nativeID UIA_AutomationIdPropertyId (fallback) Used if testID is missing

Screenshots

image

Testing

Playground composition tested

Changelog

Should this change be included in the release notes: Yes

Add a brief summary of the change to use in the release notes for the next release. [Fabric] Implement nativeID

Microsoft Reviewers: Open in CodeFlow

@anupriya13 anupriya13 requested a review from chiaramooney May 12, 2025 09:55
@anupriya13 anupriya13 marked this pull request as ready for review May 12, 2025 09:55
@anupriya13 anupriya13 requested a review from a team as a code owner May 12, 2025 09:55
@anupriya13 anupriya13 requested a review from acoates-ms May 12, 2025 09:56
@anupriya13 anupriya13 requested a review from Copilot May 12, 2025 12:31
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements nativeID support for Fabric by mapping the nativeID property as a fallback to the UI Automation AutomationId property when testID is absent.

  • C++ changes update the automation provider to use nativeID as a fallback.
  • The TSX sample is updated to demonstrate usage of the new nativeID prop.
  • A JSON changelog entry has been added to document the change.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
vnext/Microsoft.ReactNative/Fabric/Composition/CompositionDynamicAutomationProvider.cpp Updates the UI Automation property retrieval to use nativeID as fallback when testID is empty.
packages/playground/Samples/text.tsx Adds nativeID prop to the Text component in the playground sample.
change/react-native-windows-c1f73033-6623-45cb-a6ee-f64376e9e1e4.json Adds a changelog entry marking the PR as a prerelease patch change.
Comments suppressed due to low confidence (2)

vnext/Microsoft.ReactNative/Fabric/Composition/CompositionDynamicAutomationProvider.cpp:489

  • Ensure that fallback to props->nativeId is intentional; if both testId and nativeId might be empty, consider adding explicit handling of such cases.
auto wideId = !props->testId.empty() ? (::Microsoft::Common::Unicode::Utf8ToUtf16(props->testId)) : (::Microsoft::Common::Unicode::Utf8ToUtf16(props->nativeId));

packages/playground/Samples/text.tsx:15

  • [nitpick] The nativeID prop value 'nativeId_Test' uses mixed casing; consider standardizing the casing for nativeID values to improve consistency and readability.
<Text nativeID="nativeId_Test" style={styles.welcome}>

@acoates-ms
Copy link
Contributor

I don't think I agree with nativeId being the same as testId. testId gets mapped to accessibility properties for usage in automation.

nativeId is supposed to allow native code to reference the component. For that we'd need a native method to access the nativeId of a component - so a new public property on MS.RN.ComponentView. And a way to look up a ComponentView from a nativeId -- Something like MS.RN.Compositon.CompositionUIService.ComponentFromReactTag, but that looks up the component based on nativeId instead of react tag. Although putting it on CompositionUIService might not make sense either. Or it may require a view to search from. Looking at the android impl, in ReactFindViewUtil, I think there is a need to be able to search for a nativeId on a specific UI tree.

@anupriya13 anupriya13 marked this pull request as draft May 21, 2025 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement nativeID property for Text in Fabric Implement nativeID property for View in Fabric Add support for nativeId (for use with LabeledBy)
3 participants