Skip to content

Fix touch event handling, improve reliability, and optimize performance#16048

Merged
acoates-ms merged 16 commits intomicrosoft:mainfrom
acoates-ms:textinputtouch
Apr 24, 2026
Merged

Fix touch event handling, improve reliability, and optimize performance#16048
acoates-ms merged 16 commits intomicrosoft:mainfrom
acoates-ms:textinputtouch

Conversation

@acoates-ms
Copy link
Copy Markdown
Contributor

@acoates-ms acoates-ms commented Apr 24, 2026

Description

Copied from #16015 so I can drive it to completion.

This PR bundles several touch stability and performance improvements for the Windows React Native Fabric renderer: it adds a m_childrenCache to avoid O(n) WinRT iterator traversal on every GetAt, hardens the codebase against a null RootComponentView, converts m_capturedPointers / m_children / m_componentNames to std::unordered_set for O(1) operations, and adds snap-point change detection in CompScrollerVisual to skip redundant reconfiguration.

Also brings over issues found in #16009

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Why

Touch functionality often drops/misses touches from the user

What

What changes were made to the codebase to solve the bug, add the functionality, etc. that you specified above.

Changelog

Should this change be included in the release notes: yes

Fix touch event handling, improve reliability, and optimize performance

Important Files Changed

Filename Overview
vnext/Microsoft.ReactNative/Fabric/Composition/CompositionContextHelper.cpp Adds m_childrenCache for O(1) GetAt; iterator-based InsertAt preserved in WinRT layer, cache mirrors inserts and removes. Snap-point dedup early-exit added. Prior assert+nullptr guard for out-of-range GetAt kept.
vnext/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.cpp RootComponentView() changed to return raw pointer with null checks throughout; DispatchSynthesizedTouchCancelForActiveTouch and GetTouchableViewsInPathToRoot added; multi-touch early-return fixed with null guard instead of early return; handler lambda captures this for non-static IsPointerWithinInitialTree.
vnext/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.h RootComponentView() signature updated to return pointer; IsPointerWithinInitialTree made non-static; m_capturedPointers changed to unordered_set; two new method declarations added.
vnext/Microsoft.ReactNative/Fabric/Composition/CompositionViewComponentView.cpp anyHitTestHelper now iterates directly via m_children.GetAt(i-1) (O(1) per call on single_threaded_vector) rather than copying children into a local vector; eliminates per-event heap allocation for hit-testing.
vnext/Microsoft.ReactNative/Modules/Animated/AnimatedNode.h m_children changed from std::vector to std::unordered_set; Children() return type updated; changes iteration order for callers — safe as long as no caller depends on insertion-order traversal.
vnext/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp Changes to text input component view; pre-existing concern about createVisual() returning nullptr is unaddressed but was flagged in a prior review thread.

Sequence Diagram

sequenceDiagram
    participant W as WinRT Input
    participant EH as CompositionEventHandler
    participant RC as RootComponentView*
    participant FUI as FabricUIManager
    participant JS as JS EventEmitter

    W->>EH: PointerPressed/Moved/Released
    EH->>EH: RootComponentView() → raw ptr (null-safe)
    alt rootView == nullptr
        EH-->>W: early return (no crash)
    else rootView valid
        EH->>RC: hitTest(clientPoint, ptLocal)
        RC-->>EH: targetTag
        EH->>FUI: GetViewRegistry().componentViewDescriptorWithTag(targetTag)
        FUI-->>EH: targetComponentView
        EH->>EH: DispatchTouchEvent(eventType, pointerId, ...)
        loop for each activeTouch
            EH->>RC: hitTest (null-checked)
            EH->>EH: handler λ [this, &activeTouch, &pointerEvent]
            note over EH: IsPointerWithinInitialTree() walks parent chain
            EH->>JS: onPointerDown/Move/Up/Cancel + onClick/onAuxClick
        end
        loop for each uniqueEventEmitter
            EH->>JS: onTouchStart/Move/End/Cancel
        end
    end
Loading
Microsoft Reviewers: Open in CodeFlow
Microsoft Reviewers: Open in CodeFlow

gmacmaster and others added 14 commits April 20, 2026 10:47
- Fix touch/pen pointer device type detection and screenPoint coordinates
- Fix touch cancel to include all active touches per W3C spec
- Synthesize touch-cancel for stale pointers and releases outside views
- Fix TextInput pointer message translation (use mouse-style messages for RichEdit)
- Fix ShouldSubmit modifier key checks (altDown, ctrlKey)
- Add null safety to RootComponentView() for island teardown
- Fix Pressability hover timeout and tabIndex focusable mapping
- Cache event path to root to avoid repeated tree walks
- Use unordered_set for pointer capture tracking
- Eliminate O(n²) hit testing by caching visual children
- Skip snap scroll reconfiguration when unchanged
- Improve TextInput reliability: thread-safe loading, null safety, use-after-free fix
- Fix Timing data race and remove duplicate image error allocation
- Use unordered_set for animated node and component registry lookups
- Clean up dead code in ScrollView and simplify Modal event emitter init
@acoates-ms acoates-ms requested a review from a team as a code owner April 24, 2026 15:43
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 24, 2026

Performance Test Results

Branch: textinputtouch
Commit: 4c580865
Time: 2026-04-24T18:03:58.025Z
Tests: 161/161 passed

✅ Passed

161 scenario(s) across 28 suite(s) — no regressions

SectionList

Scenario Mean Median StdDev Renders vs Baseline
SectionList mount 5.00ms 5.00ms ±0.82ms 1 +0.0%
SectionList unmount 0.10ms 0.00ms ±0.32ms 0 +0.0%
SectionList rerender 10.70ms 11.00ms ±0.67ms 2 +4.8%
SectionList with-3-sections-15-items 5.50ms 5.00ms ±0.85ms 1 -9.1%
SectionList with-5-sections-50-items 6.30ms 6.00ms ±1.49ms 1 +0.0%
SectionList with-10-sections-200-items 5.20ms 5.00ms ±0.42ms 1 -9.1%
SectionList with-20-sections-200-items 4.40ms 4.50ms ±1.07ms 1 -10.0%
SectionList with-section-separator 1.70ms 2.00ms ±0.48ms 1 +0.0%
SectionList with-item-separator 2.20ms 2.00ms ±0.63ms 1 +0.0%
SectionList with-header-footer 1.70ms 2.00ms ±0.48ms 1 +0.0%
SectionList with-section-footer 2.30ms 2.00ms ±1.70ms 1 +0.0%
SectionList with-sticky-section-headers 1.90ms 2.00ms ±0.57ms 1 +0.0%
SectionList with-empty-list 0.50ms 0.50ms ±0.53ms 1 -50.0%
SectionList with-50-sections-1000-items 1.90ms 1.50ms ±1.52ms 1 -25.0%

FlatList

Scenario Mean Median StdDev Renders vs Baseline
FlatList mount 4.30ms 4.00ms ±1.49ms 1 +0.0%
FlatList unmount 0.10ms 0.00ms ±0.32ms 0 +0.0%
FlatList rerender 10.20ms 10.00ms ±1.55ms 2 +11.1%
FlatList with-10-items 4.30ms 4.00ms ±0.67ms 1 +0.0%
FlatList with-100-items 5.40ms 5.00ms ±1.43ms 1 +0.0%
FlatList with-500-items 4.60ms 5.00ms ±0.84ms 1 +25.0%
FlatList with-1000-items 4.70ms 4.00ms ±1.25ms 1 +0.0%
FlatList horizontal 3.80ms 4.00ms ±1.32ms 1 -20.0%
FlatList with-separator 2.40ms 2.00ms ±1.35ms 1 +0.0%
FlatList with-header-footer 1.50ms 1.50ms ±0.53ms 1 -25.0%
FlatList with-empty-list 0.50ms 0.50ms ±0.53ms 1 +0.0%
FlatList with-get-item-layout 1.50ms 1.50ms ±0.53ms 1 +50.0%
FlatList inverted 1.90ms 1.50ms ±1.52ms 1 +0.0%
FlatList with-num-columns 2.50ms 2.50ms ±0.53ms 1 -16.7%

TouchableOpacity

Scenario Mean Median StdDev Renders vs Baseline
TouchableOpacity mount 1.00ms 1.00ms ±0.00ms 1 +0.0%
TouchableOpacity unmount 0.10ms 0.00ms ±0.32ms 0 +0.0%
TouchableOpacity rerender 1.10ms 1.00ms ±0.32ms 2 +0.0%
TouchableOpacity custom-active-opacity 0.70ms 1.00ms ±0.48ms 1 +0.0%
TouchableOpacity disabled 0.80ms 0.50ms ±1.23ms 1 -50.0%
TouchableOpacity with-all-handlers 0.70ms 1.00ms ±0.48ms 1 +0.0%
TouchableOpacity with-hit-slop 0.70ms 1.00ms ±0.48ms 1 +0.0%
TouchableOpacity with-delay 0.70ms 1.00ms ±0.48ms 1 +0.0%
TouchableOpacity nested 1.30ms 1.00ms ±0.48ms 1 +0.0%
TouchableOpacity multiple-10 5.80ms 5.00ms ±1.52ms 1 -16.7%
TouchableOpacity multiple-50 26.40ms 25.00ms ±2.41ms 1 -13.8%
TouchableOpacity multiple-100 31.80ms 27.00ms ±11.78ms 1 -46.0%

ScrollView

Scenario Mean Median StdDev Renders vs Baseline
ScrollView mount 0.20ms 0.00ms ±0.42ms 1 +0.0%
ScrollView unmount 0.10ms 0.00ms ±0.32ms 0 +0.0%
ScrollView rerender 0.60ms 1.00ms ±0.52ms 2 +0.0%
ScrollView children-20 3.20ms 3.00ms ±1.15ms 1 -25.0%
ScrollView children-100 16.40ms 16.00ms ±2.53ms 1 +0.0%
ScrollView horizontal 3.30ms 3.00ms ±0.48ms 1 -25.0%
ScrollView sticky-headers 2.70ms 3.00ms ±0.95ms 1 +0.0%
ScrollView scroll-indicators 1.20ms 1.00ms ±1.40ms 1 +0.0%
ScrollView nested 1.10ms 1.00ms ±0.32ms 1 +0.0%
ScrollView content-container-style 0.70ms 1.00ms ±0.48ms 1 +0.0%
ScrollView children-500 20.67ms 20.00ms ±2.72ms 1 +5.3%

TouchableHighlight

Scenario Mean Median StdDev Renders vs Baseline
TouchableHighlight mount 0.50ms 0.50ms ±0.53ms 1 +0.0%
TouchableHighlight unmount 0.10ms 0.00ms ±0.32ms 0 +0.0%
TouchableHighlight rerender 0.70ms 1.00ms ±0.48ms 2 +0.0%
TouchableHighlight custom-underlay-color 0.60ms 1.00ms ±0.52ms 1 +Infinity%
TouchableHighlight custom-active-opacity 0.30ms 0.00ms ±0.48ms 1 +0.0%
TouchableHighlight disabled 0.30ms 0.00ms ±0.48ms 1 +0.0%
TouchableHighlight with-all-handlers 0.30ms 0.00ms ±0.48ms 1 +0.0%
TouchableHighlight with-hit-slop 0.30ms 0.00ms ±0.48ms 1 +0.0%
TouchableHighlight nested-touchables 1.00ms 1.00ms ±0.00ms 1 +0.0%
TouchableHighlight multiple-touchables-10 2.70ms 3.00ms ±0.48ms 1 +0.0%
TouchableHighlight multiple-touchables-50 13.50ms 13.00ms ±2.17ms 1 +4.0%
TouchableHighlight multiple-touchables-100 23.60ms 24.00ms ±3.44ms 1 +6.7%

Pressable

Scenario Mean Median StdDev Renders vs Baseline
Pressable mount 0.30ms 0.00ms ±0.48ms 1 +0.0%
Pressable unmount 0.20ms 0.00ms ±0.42ms 0 +0.0%
Pressable rerender 0.60ms 1.00ms ±0.52ms 2 +100.0%
Pressable with-all-handlers 0.30ms 0.00ms ±0.48ms 1 +0.0%
Pressable with-style-function 0.40ms 0.00ms ±0.52ms 1 +0.0%
Pressable disabled 0.30ms 0.00ms ±0.48ms 1 +0.0%
Pressable with-hit-slop 0.40ms 0.00ms ±0.52ms 1 +0.0%
Pressable nested 0.70ms 1.00ms ±0.48ms 1 +0.0%
Pressable multiple-10 3.00ms 3.00ms ±0.53ms 1 +0.0%
Pressable multiple-50 15.73ms 16.00ms ±1.58ms 1 +14.3%
Pressable multiple-100 16.80ms 12.00ms ±10.14ms 1 +0.0%

Modal

Scenario Mean Median StdDev Renders vs Baseline
Modal mount 0.20ms 0.00ms ±0.42ms 1 +0.0%
Modal unmount 0.10ms 0.00ms ±0.32ms 0 +0.0%
Modal rerender 0.90ms 1.00ms ±0.32ms 2 +Infinity%
Modal slide-animation 0.40ms 0.00ms ±0.52ms 1 +0.0%
Modal fade-animation 0.50ms 0.50ms ±0.53ms 1 +Infinity%
Modal transparent 0.40ms 0.00ms ±0.52ms 1 +0.0%
Modal with-callbacks 0.30ms 0.00ms ±0.48ms 1 +0.0%
Modal rich-content 1.90ms 2.00ms ±0.74ms 1 +0.0%
Modal with-accessibility 0.20ms 0.00ms ±0.42ms 1 +0.0%

Image

Scenario Mean Median StdDev Renders vs Baseline
Image mount 0.20ms 0.00ms ±0.42ms 1 +0.0%
Image unmount 0.00ms 0.00ms ±0.00ms 0 +0.0%
Image rerender 0.20ms 0.00ms ±0.42ms 2 +0.0%
Image with-resize-mode 0.10ms 0.00ms ±0.32ms 1 +0.0%
Image with-border-radius 0.20ms 0.00ms ±0.42ms 1 +0.0%
Image with-tint-color 0.20ms 0.00ms ±0.42ms 1 +0.0%
Image with-blur-radius 0.20ms 0.00ms ±0.42ms 1 +0.0%
Image with-accessibility 0.10ms 0.00ms ±0.32ms 1 +0.0%
Image multiple-10 1.00ms 1.00ms ±0.00ms 1 +0.0%
Image multiple-50 3.80ms 4.00ms ±0.41ms 1 +33.3%
Image multiple-100 7.87ms 7.00ms ±1.51ms 1 -12.5%

ActivityIndicator

Scenario Mean Median StdDev Renders vs Baseline
ActivityIndicator mount 0.20ms 0.00ms ±0.42ms 1 +0.0%
ActivityIndicator unmount 0.20ms 0.00ms ±0.42ms 0 +0.0%
ActivityIndicator rerender 0.10ms 0.00ms ±0.32ms 2 +0.0%
ActivityIndicator size-large 0.20ms 0.00ms ±0.42ms 1 +0.0%
ActivityIndicator size-small 0.10ms 0.00ms ±0.32ms 1 +0.0%
ActivityIndicator with-color 0.00ms 0.00ms ±0.00ms 1 +0.0%
ActivityIndicator not-animating 0.00ms 0.00ms ±0.00ms 1 +0.0%
ActivityIndicator with-accessibility 0.20ms 0.00ms ±0.42ms 1 +0.0%
ActivityIndicator multiple-10 1.00ms 1.00ms ±0.00ms 1 +0.0%
ActivityIndicator multiple-50 3.87ms 4.00ms ±0.83ms 1 +0.0%
ActivityIndicator multiple-100 8.33ms 8.00ms ±1.45ms 1 +14.3%

Switch

Scenario Mean Median StdDev Renders vs Baseline
Switch mount 0.30ms 0.00ms ±0.48ms 1 +0.0%
Switch unmount 0.10ms 0.00ms ±0.32ms 0 +0.0%
Switch rerender 0.30ms 0.00ms ±0.48ms 2 -100.0%
Switch value-true 0.30ms 0.00ms ±0.48ms 1 +0.0%
Switch disabled 0.30ms 0.00ms ±0.48ms 1 +0.0%
Switch custom-colors 0.40ms 0.00ms ±0.97ms 1 +0.0%
Switch on-value-change 0.10ms 0.00ms ±0.32ms 1 +0.0%
Switch with-accessibility 0.20ms 0.00ms ±0.42ms 1 +0.0%
Switch multiple-10 1.60ms 2.00ms ±0.51ms 1 +0.0%
Switch multiple-50 9.73ms 9.00ms ±2.40ms 1 +0.0%
Switch multiple-100 18.33ms 17.00ms ±3.20ms 1 +6.3%

Button

Scenario Mean Median StdDev Renders vs Baseline
Button mount 0.60ms 1.00ms ±0.52ms 1 +0.0%
Button unmount 0.10ms 0.00ms ±0.32ms 0 +0.0%
Button rerender 1.10ms 1.00ms ±0.32ms 2 +0.0%
Button disabled 0.60ms 1.00ms ±0.52ms 1 +0.0%
Button with-color 0.60ms 1.00ms ±0.52ms 1 +100.0%
Button with-accessibility 0.40ms 0.00ms ±0.52ms 1 -100.0%
Button multiple-10 5.60ms 5.00ms ±1.06ms 1 -16.7%
Button multiple-50 21.67ms 27.00ms ±8.61ms 1 +0.0%
Button multiple-100 15.47ms 15.00ms ±2.23ms 1 -21.1%

TextInput

Scenario Mean Median StdDev Renders vs Baseline
TextInput mount 0.10ms 0.00ms ±0.32ms 1 +0.0%
TextInput unmount 0.00ms 0.00ms ±0.00ms 0 +0.0%
TextInput rerender 0.30ms 0.00ms ±0.48ms 2 +0.0%
TextInput multiline 0.20ms 0.00ms ±0.42ms 1 +0.0%
TextInput with-value 0.20ms 0.00ms ±0.42ms 1 +0.0%
TextInput styled 0.20ms 0.00ms ±0.42ms 1 +0.0%
TextInput multiple-100 7.60ms 8.00ms ±1.45ms 1 +14.3%

View

Scenario Mean Median StdDev Renders vs Baseline
View mount 0.00ms 0.00ms ±0.00ms 1 +0.0%
View unmount 0.10ms 0.00ms ±0.32ms 0 +0.0%
View rerender 0.30ms 0.00ms ±0.48ms 2 +0.0%
View nested-50 3.73ms 4.00ms ±0.59ms 1 +33.3%
View nested-100 7.93ms 8.00ms ±1.22ms 1 +14.3%
View shadow 0.10ms 0.00ms ±0.32ms 1 +0.0%
View border-radius 0.20ms 0.00ms ±0.42ms 1 +0.0%
View nested-500 17.27ms 10.00ms ±12.69ms 1 +0.0%

Text

Scenario Mean Median StdDev Renders vs Baseline
Text mount 0.20ms 0.00ms ±0.42ms 1 +0.0%
Text unmount 0.10ms 0.00ms ±0.32ms 0 +0.0%
Text rerender 0.20ms 0.00ms ±0.42ms 2 +0.0%
Text long-1000 0.00ms 0.00ms ±0.00ms 1 +0.0%
Text nested 0.30ms 0.00ms ±0.48ms 1 +0.0%
Text styled 0.20ms 0.00ms ±0.42ms 1 +0.0%
Text multiple-100 8.33ms 8.00ms ±1.63ms 1 +14.3%

SectionList.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
SectionList native mount 5.19ms 5.03ms ±0.49ms 1 -22.6%

FlatList.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
FlatList native mount 5.48ms 5.11ms ±1.21ms 1 -44.7%

TouchableHighlight.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
TouchableHighlight native mount 1.45ms 1.42ms ±0.19ms 1 -31.9%

TouchableOpacity.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
TouchableOpacity native mount 1.68ms 1.45ms ±0.70ms 1 -53.8%

Pressable.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
Pressable native mount 1.63ms 1.57ms ±0.21ms 1 -37.6%

ScrollView.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
ScrollView native mount 3.57ms 3.25ms ±0.68ms 1 -19.7%

ActivityIndicator.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
ActivityIndicator native mount 1.60ms 1.43ms ±0.62ms 1 -42.6%

TextInput.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
TextInput native mount 2.16ms 2.11ms ±0.19ms 1 -48.4%

Switch.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
Switch native mount 1.07ms 1.00ms ±0.19ms 1 -42.4%

Button.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
Button native mount 1.54ms 1.53ms ±0.10ms 1 -41.3%

Modal.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
Modal native mount 0.89ms 0.84ms ±0.23ms 1 -31.0%

Image.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
Image native mount 1.65ms 1.62ms ±0.29ms 1 -28.5%

View.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
View native mount 1.01ms 0.92ms ±0.22ms 1 -35.5%

Text.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
Text native mount 1.19ms 1.17ms ±0.11ms 1 -32.8%

Copy link
Copy Markdown
Contributor

@iamAbhi-916 iamAbhi-916 left a comment

Choose a reason for hiding this comment

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

LGTM

@acoates-ms acoates-ms merged commit 5563f8f into microsoft:main Apr 24, 2026
32 checks passed
@acoates-ms acoates-ms deleted the textinputtouch branch April 24, 2026 19:03
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.

3 participants