Commit 7dfdfa0
authored
fix: map Windows touch pointer IDs to small JS-safe identifiers in CompositionEventHandler (#16081)
* fix: map Windows touch pointer IDs to small JS-safe identifiers in CompositionEventHandler (#1)
* fix: map Windows touch pointer IDs to small JS-safe identifiers in CompositionEventHandler
Windows touch input can assign arbitrarily large pointer IDs (e.g. 2233). The Fabric
CompositionEventHandler was forwarding these directly as React Native touch identifiers
via `activeTouch.touch.identifier = pointerId`. React Native's JS touch handler uses
identifiers as direct array indices and hard-caps them at 20 — large values caused the
JS layer to back-fill a 2000+ element sparse array, corrupting touch tracking state.
The symptom: after scrolling a ScrollView/FlatList on a touch screen, Pressables and
TouchableOpacities would remain stuck in a pressed state. Taps would fire at the
coordinates where the scroll began rather than where the finger lifted.
Fix: add `AllocateTouchIdentifier()` which cycles through identifiers [0, 19], skipping
any slot already claimed by a live touch in `m_activeTouches`. This mirrors the approach
iOS uses (cycling modulo RCTMaxTouches = 11 in RCTTouchHandler.m). The existing but
unused `m_touchId` field is repurposed as the cycling base.
Updated all dependent lookups that previously relied on `touch.identifier == pointerId`
(which only worked accidentally) to use the `m_activeTouches` map key directly.
Fixes: #16047
* fix: prevent unbounded m_touchId growth in CompositionEventHandler fallback path
When all 20 touch slots are occupied, the fallback return in
AllocateTouchIdentifier used post-increment (`m_touchId++ % kMaxTouchIdentifier`),
which stored the raw incremented value back into m_touchId without a modulo wrap.
Repeated hits would grow m_touchId past 19, breaking the cycling logic and
eventually causing signed-integer overflow (UB).
Fix by computing the wrapped return value first, then storing the next
wrapped value back: captures fallback = m_touchId % kMaxTouchIdentifier,
then m_touchId = (m_touchId + 1) % kMaxTouchIdentifier.
* Create react-native-windows-2c040593-f202-44fc-a55c-5d523c493705.json
* Reserve 1 for mouse
* yarn format1 parent 1afd5d7 commit 7dfdfa0
3 files changed
Lines changed: 54 additions & 4 deletions
File tree
- change
- vnext/Microsoft.ReactNative/Fabric/Composition
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
Lines changed: 41 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1214 | 1214 | | |
1215 | 1215 | | |
1216 | 1216 | | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
1217 | 1248 | | |
1218 | 1249 | | |
1219 | 1250 | | |
| |||
1322 | 1353 | | |
1323 | 1354 | | |
1324 | 1355 | | |
1325 | | - | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
1326 | 1364 | | |
1327 | 1365 | | |
1328 | 1366 | | |
1329 | | - | |
| 1367 | + | |
1330 | 1368 | | |
1331 | 1369 | | |
1332 | 1370 | | |
| |||
1641 | 1679 | | |
1642 | 1680 | | |
1643 | 1681 | | |
1644 | | - | |
| 1682 | + | |
1645 | 1683 | | |
1646 | 1684 | | |
1647 | 1685 | | |
| |||
Lines changed: 6 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
165 | 170 | | |
166 | | - | |
| 171 | + | |
167 | 172 | | |
168 | 173 | | |
169 | 174 | | |
| |||
0 commit comments