diff --git a/src/reanimated2/NativeReanimated/index.ts b/src/reanimated2/NativeReanimated/index.ts index 7212c59ae7d3..fb1804420bf6 100644 --- a/src/reanimated2/NativeReanimated/index.ts +++ b/src/reanimated2/NativeReanimated/index.ts @@ -2,11 +2,6 @@ import reanimatedJS from '../js-reanimated'; import { shouldBeUseWeb } from '../PlatformChecker'; import { NativeReanimated } from './NativeReanimated'; -let exportedModule; -if (shouldBeUseWeb()) { - exportedModule = reanimatedJS; -} else { - exportedModule = new NativeReanimated(); -} - -export default exportedModule as NativeReanimated; +export default (shouldBeUseWeb() + ? reanimatedJS + : new NativeReanimated()) as NativeReanimated; diff --git a/src/reanimated2/component/FlatList.tsx b/src/reanimated2/component/FlatList.tsx index 6504e2e70909..60d22ee15eba 100644 --- a/src/reanimated2/component/FlatList.tsx +++ b/src/reanimated2/component/FlatList.tsx @@ -62,6 +62,15 @@ export const ReanimatedFlatList = forwardRef( : styles.verticallyInverted : undefined; + // Set default scrollEventThrottle, because user expects + // to have continuous scroll events and + // react-native defaults it to 50 for FlatLists. + // We set it to 1 so we have peace until + // there are 960 fps screens. + if (!('scrollEventThrottle' in restProps)) { + restProps.scrollEventThrottle = 1; + } + const cellRenderer = React.useMemo( () => createCellRenderer(itemLayoutAnimation, cellStyle), [cellStyle] diff --git a/src/reanimated2/component/ScrollView.tsx b/src/reanimated2/component/ScrollView.tsx index efaf7d09cd87..d9f2749946f3 100644 --- a/src/reanimated2/component/ScrollView.tsx +++ b/src/reanimated2/component/ScrollView.tsx @@ -41,10 +41,12 @@ export const AnimatedScrollView: AnimatedScrollView = forwardRef( ); } - if (!restProps.scrollEventThrottle) { - // Set default scrollEventThrottle to 8, because user expects - // to have continuous scroll events - restProps.scrollEventThrottle = 8; + // Set default scrollEventThrottle, because user expects + // to have continuous scroll events. + // We set it to 1 so we have peace until + // there are 960 fps screens. + if (!('scrollEventThrottle' in restProps)) { + restProps.scrollEventThrottle = 1; } return ; diff --git a/src/reanimated2/threads.ts b/src/reanimated2/threads.ts index dbdd59269d50..cd2290f954a0 100644 --- a/src/reanimated2/threads.ts +++ b/src/reanimated2/threads.ts @@ -16,11 +16,8 @@ export function setupMicrotasks() { let microtasksQueue: Array<() => void> = []; let isExecutingMicrotasksQueue = false; - - // @ts-ignore – typescript expects this to conform to NodeJS definition and expects the return value to be NodeJS.Immediate which is an object and not a number - global.queueMicrotask = (callback: () => void): number => { + global.queueMicrotask = (callback: () => void) => { microtasksQueue.push(callback); - return -1; }; global.__callMicrotasks = () => {