From 802098d15582edb7d7bd4362a4c7b5710aafd5d3 Mon Sep 17 00:00:00 2001 From: Krzysztof Magiera Date: Fri, 24 Feb 2023 00:24:42 +0100 Subject: [PATCH] Flush animation-frame and immediates on keyboard event to follow same flow as all other type of events --- src/reanimated2/core.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/reanimated2/core.ts b/src/reanimated2/core.ts index 761bb4e772a..c6ce18a162f 100644 --- a/src/reanimated2/core.ts +++ b/src/reanimated2/core.ts @@ -135,8 +135,18 @@ export function subscribeForKeyboardEvents( eventHandler: (state: number, height: number) => void, options: AnimatedKeyboardOptions ): number { + // TODO: this should really go with the same code path as other events, that is + // via registerEventHandler. For now we are copying the code from there. + function handleAndFlushImmediates(state: number, height: number) { + 'worklet'; + const now = performance.now(); + global.__frameTimestamp = now; + eventHandler(state, height); + global.__flushAnimationFrame(now); + global.__frameTimestamp = undefined; + } return NativeReanimatedModule.subscribeForKeyboardEvents( - makeShareableCloneRecursive(eventHandler), + makeShareableCloneRecursive(handleAndFlushImmediates), options.isStatusBarTranslucentAndroid ?? false ); }