Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[Fabric][Composition] Expose a non-mutating focusability API on  ComponentView  (e.g.  IsFocusable ) for FocusZone / single-tab-stop scenarios

未关闭
#16,363 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
45/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
冷清
技术栈
cpp, react-native

调研方向

首先跟踪 Composition 实现中的 ComponentView.TryFocus 以及所请求的非变更式可聚焦性入口点。然后检查 Composition.FocusManager.FindFirstFocusableElement、FindLastFocusableElement 和 GettingFocusEventArgs.TrySetNewFocusedComponent,包括 IFocusManagerStatics 激活路径。完成的标准是:无需移动焦点即可使用主要查询,并且面向托管 RNW 应用的次要 API 行为已得到澄清或修复。

由索引模型根据 Issue 内容生成。

描述

bug Invalid Triage Needs: Triage :mag:
Problem Description

Building a FocusZone / single-tab-stop control on Composition (New Architecture) requires identifying the next focusable  ComponentView  in tab order. Today there is no non-mutating way to test whether a  ComponentView  can take focus, so we must call  ComponentView.TryFocus(...)  in a loop — which moves focus as a side effect while probing. We need a query API that reports focusability without changing focus.

What we're doing
Native  RCTFocusZone  implementation. On Tab we want to move focus to the first focusable element outside the zone in one transition; arrow keys navigate within. To find that element we DFS the tree and call  TryFocus  on each candidate until one succeeds, because there's no way to ask "is this focusable?" first.
Gaps

  1. No non-mutating focusability property on  ComponentView . Requesting an  IsFocusable  /  Focusable  (get-only  bool ) property, so we can select the correct target without side-effecting focus.
  2.  Composition.FocusManager.FindFirstFocusableElement  /  FindLastFocusableElement  statics throw — their activation factory ( IFocusManagerStatics ) isn't registered in the runtime we load, so  get_activation_factory  throws (fatal inside a  noexcept  input handler). If these are the intended API, they need to be usable from a hosted RNW app.
  3.  GettingFocusEventArgs.TrySetNewFocusedComponent(ComponentView)  projects as  void  (no success  bool ), so we can't redirect focus during  GettingFocus  and know whether it was accepted, forcing focus logic into  KeyDown  instead.
    Ask
    Primarily (1) a non-mutating focusability query on  ComponentView . Secondarily, clarify/fix (2) and (3) so focus navigation can be built without trial-and-error  TryFocus .
    Workaround
    DFS +  TryFocus  trial-and-error in  KeyDown , which mutates focus while probing and costs a tree walk per keystroke.
Steps To Reproduce
  1. In a react-native-windows Fabric (Composition / New Architecture) app, add a native
    component (e.g. a custom FocusZone) that subclasses the codegen ComponentView and, in
    Initialize, registers a KeyDown handler on the container ComponentView.
  2. In that handler, try to move keyboard focus to the next focusable ComponentView in tab
    order (e.g. on Tab, the first focusable element outside the zone). To do this you must
    determine which ComponentView can accept focus.
  3. Look for a non-mutating way to test whether a given ComponentView is focusable. There is
    none: ComponentView.TryFocus(FocusState) is the only option, and it moves focus as a
    side effect while probing.
  4. Result: you have to call TryFocus in a loop across candidate views, causing focus to
    actually move during probing, and there is no API to identify the correct target up front.
Expected Results

No response

CLI version

CLI version is  13.6.9

Environment
react-native-windows 0.81.5 (Fabric / Composition),  Microsoft.ReactNative  C++/WinRT
Community Modules

No response

Target React Native Architecture

None

Target Platform Version

None

Visual Studio Version

None

Build Configuration

None

Snack, code example, screenshot, or link to a repository

No response

主要语言
C++
星标
17.4k
派生
1.2k
平均合并
3 天 7 小时
30 天内合并 PR
17

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/react-native-windows 的其他 Issue

查看 microsoft/react-native-windows 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。