Fabric: core Switch renders but never fires onValueChange on mouse click (new architecture)
维护者通常 2 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 58/100
调研方向
从 vnext/Microsoft.ReactNative/Fabric/Composition/SwitchComponentView.cpp 开始,重点关注 OnPointerPressed、OnPointerReleased 和 IsPrimary() 检查。跟踪鼠标释放是否到达 view,以及 gate 是否接受它,然后添加 issue 中描述的交互测试。当合成的鼠标点击发出 SwitchEventEmitter::onChange 并更新受控 Switch 时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
Environment
- react-native-windows 0.83.2 (component source unchanged on
mainas of 2026-07-17), new architecture (Fabric, composition), Win32/HWND host - Windows 11, physical mouse input
- Reproduced in a production app; repro is trivial (any core
Switch)
Steps to reproduce
import {Switch} from 'react-native';
function Repro() {
const [on, setOn] = React.useState(false);
return <Switch value={on} onValueChange={v => { console.log('onValueChange', v); setOn(v); }} />;
}
- Run on react-native-windows with the new architecture enabled.
- Click the Switch with the mouse.
Expected
onValueChange fires with the toggled value; the Switch (a controlled component) re-renders in the new state. This is the behavior on Android/iOS.
Actual
The Switch renders correctly (including hover visuals), but onValueChange never fires on mouse click. No JS callback, no state change — the control is effectively inert for mouse users.
Root cause pointer
vnext/Microsoft.ReactNative/Fabric/Composition/SwitchComponentView.cpp (current main):
OnPointerReleased(~line 285) is the only mouse path totoggle()(~line 328), which emitsfacebook::react::SwitchEventEmitter::onChange— the native event behindonValueChange.- Both
OnPointerPressed(~line 262) andOnPointerReleasedearly-return unlessargs.GetCurrentPoint(-1).Properties().IsPrimary()is true.
On our device the emitter never fires for mouse clicks, so either the IsPrimary() gate rejects mouse pointer input on this code path, or OnPointerReleased is never routed to the Switch component view at all (pointer capture/hit-test). We have not stepped through native to disambiguate the two; what is proven on-device is that no onChange event reaches JS for any mouse click, on multiple screens and multiple Switch instances. The keyboard path (OnKeyUp, Space, ~line 318) is separate and was not part of this investigation.
Suggested fix
Ensure the pointer-released path reaches toggle() for mouse input: verify PointerRoutedEventArgs::GetCurrentPoint(-1).Properties().IsPrimary() returns true for mouse-generated pointer events in the composition input pipeline (or drop the IsPrimary() gate for mouse pointer devices), and add an interaction test that asserts SwitchEventEmitter::onChange fires on a synthesized mouse click.
Workaround (what we ship today)
Wrap the Switch in a Pressable that owns the interaction, and make the Switch itself inert:
<Pressable onPress={() => setOn(v => !v)}>
<Switch value={on} pointerEvents="none" />
</Pressable>
The Pressable receives the click and toggles state; the Switch is display-only. This restores mouse operation but bypasses the control's own accessibility/interaction semantics.
- 主要语言
- C++
- 星标
- 17.4k
- 派生
- 1.2k
- 平均合并
- 2 天 17 小时
- 30 天内合并 PR
- 13
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoft/react-native-windows 的其他 Issue
-
Needs: Triage :mag:
难度 2/5 1-3 小时 新手友好度 82/100
microsoft/react-native-windows#16340 ·
维护者通常 2 天内回复
-
bug Needs: Triage :mag:
难度 2/5 1-3 小时 新手友好度 68/100
microsoft/react-native-windows#16321 · 1 条评论 ·
维护者通常 2 天内回复
-
Needs: Triage :mag:
难度 5/5 一周以上 新手友好度 30/100
microsoft/react-native-windows#16442 · 1 条评论 ·
维护者通常 2 天内回复
-
Fabric: activating the window doesn't announce the window or the focused control to a screen reader未关闭Needs: Triage :mag:
难度 4/5 3-5 天 新手友好度 48/100
microsoft/react-native-windows#16435 ·
维护者通常 2 天内回复
-
bug Needs: Triage :mag:
难度 4/5 3-5 天 新手友好度 48/100
microsoft/react-native-windows#16410 ·
维护者通常 2 天内回复
查看 microsoft/react-native-windows 的全部 Issue
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
EsotericSoftware/spine-runtimes#3186 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
Round video messages start gray and blocky with libx264: encoder is configured for 1,000,000 fps未关闭
难度 2/5 1-3 小时 新手友好度 78/100
telegramdesktop/tdesktop#31422 ·
维护者通常 9 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 5 天内回复