MCPcopy Create free account
hub / github.com/adobe/react-spectrum / runAfterKeyboard

Function runAfterKeyboard

packages/react-aria/src/utils/runAfterKeyboard.ts:76–111  ·  view source on GitHub ↗
(fn: QueuedCallback)

Source from the content-addressed store, hash-verified

74 * Guarantees an invocation if an expected transition did not finish within 300ms.
75 */
76export function runAfterKeyboard(fn: QueuedCallback): () => void {
77 // Flush synchronously when keyboard is unsupported. This is default for non-touch devices
78 // or devices which did not open their OSK within our opening timeout.
79 if (!supportsKeyboard()) {
80 return (fn(false), () => {});
81 }
82
83 // Wait two frames to see if focus lands on an input.
84 let frame = window.requestAnimationFrame(() => {
85 frame = window.requestAnimationFrame(() => {
86 let activeElement = document.hasFocus() ? getActiveElement() : null;
87 let willKeyboardOpen = willOpenKeyboard(activeElement);
88
89 // If keyboard won't change, call the function immediately.
90 if (isKeyboardOpen() === willKeyboardOpen) {
91 return fn(willKeyboardOpen);
92 }
93
94 // On close, fire immediately since consumers may assert the ICB.
95 if (isKeyboardOpen() && !willKeyboardOpen) {
96 return fn(willKeyboardOpen);
97 }
98
99 resizeCallbacks.add(fn);
100
101 if (!listenersByWindow.has(window)) {
102 listenersByWindow.set(window, setupGlobalListeners());
103 }
104 });
105 });
106
107 return () => {
108 window.cancelAnimationFrame(frame);
109 resizeCallbacks.delete(fn);
110 };
111}
112
113/**
114 * Delays a callback execution until the on-screen keyboard has finished its transition.

Callers 5

onBlurFunction · 0.90
overrideFocusFunction · 0.90
PopoverInnerFunction · 0.90
ModalOverlayInnerFunction · 0.90

Calls 10

supportsKeyboardFunction · 0.90
getActiveElementFunction · 0.90
willOpenKeyboardFunction · 0.90
isKeyboardOpenFunction · 0.90
fnFunction · 0.85
setupGlobalListenersFunction · 0.85
deleteMethod · 0.80
addMethod · 0.65
hasMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected