Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
LayoutAnimationBatchItem,
IReanimatedModule,
IWorkletsModule,
WorkletFunction,
} from '../commonTypes';
import { checkCppVersion } from '../platform-specific/checkCppVersion';
import { jsVersion } from '../platform-specific/jsVersion';
Expand Down Expand Up @@ -165,7 +166,7 @@ See https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooti
}

subscribeForKeyboardEvents(
handler: ShareableRef<number>,
handler: ShareableRef<WorkletFunction>,
isStatusBarTranslucent: boolean,
isNavigationBarTranslucent: boolean
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
ShareableRef,
Value3D,
ValueRotation,
WorkletFunction,
} from '../../commonTypes';
import type { WebSensor } from './WebSensor';
import { mockedRequestAnimationFrame } from '../../mockedRequestAnimationFrame';
Expand Down Expand Up @@ -210,7 +211,7 @@ class JSReanimated implements IReanimatedModule {
}
}

subscribeForKeyboardEvents(_: ShareableRef<number>): number {
subscribeForKeyboardEvents(_: ShareableRef<WorkletFunction>): number {
if (isWeb()) {
logger.warn('useAnimatedKeyboard is not available on web yet.');
} else if (isJest()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
Value3D,
ValueRotation,
LayoutAnimationBatchItem,
WorkletFunction,
} from '../commonTypes';
import type { WorkletRuntime } from '../runtimes';

Expand Down Expand Up @@ -53,7 +54,7 @@ export interface ReanimatedModuleProxy {
configureProps(uiProps: string[], nativeProps: string[]): void;

subscribeForKeyboardEvents(
handler: ShareableRef<number>,
handler: ShareableRef<WorkletFunction>,
isStatusBarTranslucent: boolean,
isNavigationBarTranslucent: boolean
): number;
Expand Down
3 changes: 2 additions & 1 deletion packages/react-native-reanimated/src/Sensor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
Value3D,
ValueRotation,
ShareableRef,
WorkletFunction,
} from './commonTypes';
import { SensorType } from './commonTypes';
import { makeMutable } from './mutables';
Expand Down Expand Up @@ -56,7 +57,7 @@ export default class Sensor {
sensorType,
config.interval === 'auto' ? -1 : config.interval,
config.iosReferenceFrame,
eventHandler
eventHandler as ShareableRef<WorkletFunction>
);
return this.sensorId !== -1;
}
Expand Down
14 changes: 13 additions & 1 deletion packages/react-native-reanimated/src/commonTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,22 @@ interface WorkletBaseDev extends WorkletBaseCommon {
__stackDetails?: WorkletStackDetails;
}

export type WorkletFunctionDev<
Args extends unknown[] = unknown[],
ReturnValue = unknown,
> = ((...args: Args) => ReturnValue) & WorkletBaseDev;

type WorkletFunctionRelease<
Args extends unknown[] = unknown[],
ReturnValue = unknown,
> = ((...args: Args) => ReturnValue) & WorkletBaseRelease;

export type WorkletFunction<
Args extends unknown[] = unknown[],
ReturnValue = unknown,
> = ((...args: Args) => ReturnValue) & (WorkletBaseRelease | WorkletBaseDev);
> =
| WorkletFunctionDev<Args, ReturnValue>
| WorkletFunctionRelease<Args, ReturnValue>;

/**
* This function allows you to determine if a given function is a worklet. It
Expand Down
11 changes: 8 additions & 3 deletions packages/react-native-reanimated/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
SharedValue,
Value3D,
ValueRotation,
WorkletFunction,
} from './commonTypes';
import { makeShareableCloneRecursive } from './shareables';
import { initializeUIRuntime } from './initializers';
Expand Down Expand Up @@ -85,7 +86,9 @@ export function registerEventHandler<T>(
global.__frameTimestamp = undefined;
}
return ReanimatedModule.registerEventHandler(
makeShareableCloneRecursive(handleAndFlushAnimationFrame),
makeShareableCloneRecursive(
handleAndFlushAnimationFrame as WorkletFunction
),
eventName,
emitterReactTag
);
Expand All @@ -110,7 +113,9 @@ export function subscribeForKeyboardEvents(
global.__frameTimestamp = undefined;
}
return ReanimatedModule.subscribeForKeyboardEvents(
makeShareableCloneRecursive(handleAndFlushAnimationFrame),
makeShareableCloneRecursive(
handleAndFlushAnimationFrame as WorkletFunction
),
options.isStatusBarTranslucentAndroid ?? false,
options.isNavigationBarTranslucentAndroid ?? false
);
Expand All @@ -132,7 +137,7 @@ export function registerSensor(
return sensorContainer.registerSensor(
sensorType,
config,
makeShareableCloneRecursive(eventHandler)
makeShareableCloneRecursive(eventHandler as WorkletFunction)
);
}

Expand Down
Loading