diff --git a/packages/react-native-reanimated/src/animation/util.ts b/packages/react-native-reanimated/src/animation/util.ts index 2466ac9fa55c..68886be0766b 100644 --- a/packages/react-native-reanimated/src/animation/util.ts +++ b/packages/react-native-reanimated/src/animation/util.ts @@ -29,6 +29,7 @@ import type { } from '../commonTypes'; import { ReduceMotion } from '../commonTypes'; import type { EasingFunctionFactory } from '../Easing'; +import type { AnimatedUpdate } from '../hook/commonTypes'; import { ReducedMotionManager } from '../ReducedMotion'; import type { HigherOrderAnimation, StyleLayoutAnimation } from './commonTypes'; import type { @@ -106,7 +107,7 @@ export function assertEasingIsWorklet( } } -export function initialUpdaterRun(updater: () => T) { +export function initialUpdaterRun(updater: () => TResult): TResult { IN_STYLE_UPDATER.current = true; const result = updater(); IN_STYLE_UPDATER.current = false; diff --git a/packages/react-native-reanimated/src/commonTypes.ts b/packages/react-native-reanimated/src/commonTypes.ts index 0938f1f69e8a..89a8e2eca0e7 100644 --- a/packages/react-native-reanimated/src/commonTypes.ts +++ b/packages/react-native-reanimated/src/commonTypes.ts @@ -14,7 +14,7 @@ import type { SerializableRef, WorkletFunction } from 'react-native-worklets'; import type { Maybe } from './common/types'; import type { CSSAnimationProperties, CSSTransitionProperties } from './css'; -import type { AnyRecord } from './css/types'; +import type { AnyRecord, UnknownRecord } from './css/types'; import type { EasingFunctionFactory } from './Easing'; type LayoutAnimationOptions = diff --git a/packages/react-native-reanimated/src/createAnimatedComponent/PropsFilter.tsx b/packages/react-native-reanimated/src/createAnimatedComponent/PropsFilter.tsx index 2002e4f0a8fc..bf2a0e7c3486 100644 --- a/packages/react-native-reanimated/src/createAnimatedComponent/PropsFilter.tsx +++ b/packages/react-native-reanimated/src/createAnimatedComponent/PropsFilter.tsx @@ -44,7 +44,7 @@ export class PropsFilter implements IPropsFilter { this._initialPropsMap.set(handle, { ...handle.initial.value, ...initialUpdaterRun(handle.initial.updater), - } as StyleProps); + }); } return this._initialPropsMap.get(handle) ?? {}; diff --git a/packages/react-native-reanimated/src/css/types/helpers.ts b/packages/react-native-reanimated/src/css/types/helpers.ts index e1c94f5d1123..945eedf28422 100644 --- a/packages/react-native-reanimated/src/css/types/helpers.ts +++ b/packages/react-native-reanimated/src/css/types/helpers.ts @@ -3,6 +3,8 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ export type AnyRecord = Record; +export type UnknownRecord = Record; + type NoUndef = T extends undefined ? never : T; export type Repeat< diff --git a/packages/react-native-reanimated/src/hook/commonTypes.ts b/packages/react-native-reanimated/src/hook/commonTypes.ts index bfe7d414403e..4ead211e955e 100644 --- a/packages/react-native-reanimated/src/hook/commonTypes.ts +++ b/packages/react-native-reanimated/src/hook/commonTypes.ts @@ -7,15 +7,17 @@ import type { TextStyle, ViewStyle, } from 'react-native'; -import type { WorkletFunction } from 'react-native-worklets'; import type { - AnimatedPropsAdapterFunction, - AnimatedStyle, + AnimatableValue, + AnimationObject, + AnimationsRecord, + NestedObject, + NestedObjectValues, ShadowNodeWrapper, WrapperRef, } from '../commonTypes'; -import type { AnimatedProps } from '../createAnimatedComponent/commonTypes'; +import type { AnyRecord, UnknownRecord } from '../css/types'; import type { ReanimatedHTMLElement } from '../ReanimatedModule/js-reanimated'; import type { ViewDescriptorsSet } from '../ViewDescriptorsSet'; @@ -87,31 +89,27 @@ export interface IWorkletEventHandler { unregisterFromEvents: (viewTag: number) => void; } -export interface AnimatedStyleHandle< - Style extends DefaultStyle | AnimatedProps = DefaultStyle, -> { +export type AnimatedValuesUpdate = NestedObject< + AnimationObject | AnimatableValue +>; + +export type AnimatedUpdaterHandle = { viewDescriptors: ViewDescriptorsSet; initial: { - value: AnimatedStyle