Skip to content

Commit 6b50119

Browse files
committed
fix: make press bulletproof
1 parent 6d6025d commit 6b50119

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

packages/ui/src/userEvent.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
1+
import { InteractionManager } from 'react-native';
12
import NativeHarnessUI from './NativeHarnessUI.js';
23
import type { ElementReference } from './screen.js';
34

45
/**
56
* Flushes pending events on the JS event loop.
67
* This ensures that any events triggered by native code (like onPress callbacks)
78
* are processed before we continue.
9+
*
10+
* Uses InteractionManager.runAfterInteractions to wait until all touch events
11+
* and animations have completed, then does additional event loop tick to
12+
* ensure React state updates are fully processed.
813
*/
914
const flushEvents = (): Promise<void> => {
1015
return new Promise((resolve) => {
11-
// setImmediate runs after I/O events but before timers
12-
// This allows touch event callbacks to be processed first
13-
setImmediate(resolve);
16+
// Wait for React Native to finish processing all interactions (touch events, animations)
17+
InteractionManager.runAfterInteractions(() => {
18+
// Additional event loop ticks to ensure state updates are processed
19+
setImmediate(() => {
20+
resolve();
21+
});
22+
});
1423
});
1524
};
1625

0 commit comments

Comments
 (0)