Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions packages/react-native-reanimated/__typetests__/common/miscTest.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
/* eslint-disable @typescript-eslint/no-empty-function */
/* eslint-disable @typescript-eslint/no-unused-vars */
import {
createAnimatedPropAdapter,
Easing,
interpolateColor,
isSharedValue,
Keyframe,
makeMutable,
useAnimatedProps,
useAnimatedStyle,
useSharedValue,
} from '../..';

Expand Down Expand Up @@ -39,19 +35,6 @@ function InterpolateColorTest() {
return null;
}

function UpdatePropsTest() {
const adapter1 = createAnimatedPropAdapter((props) => {}, []);
const adapter2 = createAnimatedPropAdapter((props) => {}, ['prop1', 'prop2']);
const adapter3 = createAnimatedPropAdapter(() => {});

// @ts-expect-error works only for useAnimatedProps
useAnimatedStyle(() => ({}), undefined, [adapter1, adapter2, adapter3]);

useAnimatedProps(() => ({}), null, adapter1);

useAnimatedProps(() => ({}), null, [adapter2, adapter3]);
}

function EasingFactoryFunctionTest() {
const easing = Easing.bezier(0.1, 0.7, 1, 0.1);

Expand Down
23 changes: 0 additions & 23 deletions packages/react-native-reanimated/src/PropAdapters.ts

This file was deleted.

11 changes: 1 addition & 10 deletions packages/react-native-reanimated/src/commonTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
TransformsStyle,
ViewStyle,
} from 'react-native';
import type { SerializableRef, WorkletFunction } from 'react-native-worklets';
import type { SerializableRef } from 'react-native-worklets';

import type { CSSAnimationProperties, CSSTransitionProperties } from './css';
import type { EasingFunctionFactory } from './Easing';
Expand Down Expand Up @@ -227,15 +227,6 @@ export type MapperRegistry = {
stop: (mapperID: number) => void;
};

export type AnimatedPropsAdapterFunction = (
props: Record<string, unknown>
) => void;

export type AnimatedPropsAdapterWorklet = WorkletFunction<
[props: Record<string, unknown>],
void
>;

export interface NestedObject<T> {
[key: string]: NestedObjectValues<T>;
}
Expand Down
10 changes: 1 addition & 9 deletions packages/react-native-reanimated/src/hook/commonTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ import type {
} from 'react-native';
import type { WorkletFunction } from 'react-native-worklets';

import type {
AnimatedPropsAdapterFunction,
AnimatedStyle,
ShadowNodeWrapper,
} from '../commonTypes';
import type { AnimatedStyle, ShadowNodeWrapper } from '../commonTypes';
import type { AnimatedProps } from '../createAnimatedComponent/commonTypes';
import type { ReanimatedHTMLElement } from '../ReanimatedModule/js-reanimated';
import type { ViewDescriptorsSet } from '../ViewDescriptorsSet';
Expand Down Expand Up @@ -108,9 +104,5 @@ export interface JestAnimatedStyleHandle<
export type UseAnimatedStyleInternal<Style extends DefaultStyle> = (
updater: WorkletFunction<[], Style> | (() => Style),
dependencies?: DependencyList | null,
adapters?:
| AnimatedPropsAdapterFunction
| AnimatedPropsAdapterFunction[]
| null,
isAnimatedProps?: boolean
) => AnimatedStyleHandle<Style> | JestAnimatedStyleHandle<Style>;
16 changes: 1 addition & 15 deletions packages/react-native-reanimated/src/hook/useAnimatedProps.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
'use strict';
import { SHOULD_BE_USE_WEB } from '../common';
import type { AnimatedPropsAdapterFunction } from '../commonTypes';
import type { DependencyList, UseAnimatedStyleInternal } from './commonTypes';
import { useAnimatedStyle } from './useAnimatedStyle';

// TODO: we should make sure that when useAP is used we are not assigning styles

type UseAnimatedProps = <Props extends object>(
updater: () => Partial<Props>,
dependencies?: DependencyList | null,
adapters?:
| AnimatedPropsAdapterFunction
| AnimatedPropsAdapterFunction[]
| null,
Comment on lines -12 to -15
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as for createAnimatedPropAdapter, what about backwards compatibility?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you suggest here? Should I still accept this adapters array but don't use it anywhere at all? It seems to me a bit confusing that a function takes a parameter that is completely ignored.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can make adapters parameter @deprecated and no-op but throw a warning with an actionable developer-friendly error message when it's used.

isAnimatedProps?: boolean
) => Partial<Props>;

function useAnimatedPropsJS<Props extends object>(
updater: () => Props,
deps?: DependencyList | null,
adapters?:
| AnimatedPropsAdapterFunction
| AnimatedPropsAdapterFunction[]
| null
deps?: DependencyList | null
) {
return (useAnimatedStyle as UseAnimatedStyleInternal<Props>)(
updater,
deps,
adapters,
true
);
}
Expand All @@ -42,8 +30,6 @@ const useAnimatedPropsNative = useAnimatedStyle;
* animate.
* @param dependencies - An optional array of dependencies. Only relevant when
* using Reanimated without the Babel plugin on the Web.
* @param adapters - An optional function or array of functions allowing to
* adopt prop naming between JS and the native side.
* @returns An animated props object which has to be passed to `animatedProps`
* property of an Animated component that you want to animate.
* @see https://docs.swmansion.com/react-native-reanimated/docs/core/useAnimatedProps
Expand Down
53 changes: 7 additions & 46 deletions packages/react-native-reanimated/src/hook/useAnimatedStyle.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';

import type { MutableRefObject } from 'react';
import { useEffect, useRef } from 'react';
import type { WorkletFunction } from 'react-native-worklets';
Expand All @@ -8,8 +7,6 @@ import { isWorkletFunction, makeShareable } from 'react-native-worklets';
import { initialUpdaterRun } from '../animation';
import { IS_JEST, ReanimatedError, SHOULD_BE_USE_WEB } from '../common';
import type {
AnimatedPropsAdapterFunction,
AnimatedPropsAdapterWorklet,
AnimatedStyle,
AnimationObject,
NestedObjectValues,
Expand All @@ -30,12 +27,7 @@ import type {
JestAnimatedStyleHandle,
} from './commonTypes';
import { useSharedValue } from './useSharedValue';
import {
buildWorkletsHash,
isAnimated,
shallowEqual,
validateAnimatedStyles,
} from './utils';
import { isAnimated, shallowEqual, validateAnimatedStyles } from './utils';

interface AnimatedState {
last: AnimatedStyle<any>;
Expand Down Expand Up @@ -305,8 +297,7 @@ function jestStyleUpdater(
updater: WorkletFunction<[], AnimatedStyle<any>> | (() => AnimatedStyle<any>),
state: AnimatedState,
animationsActive: SharedValue<boolean>,
animatedValues: MutableRefObject<AnimatedStyle<any>>,
adapters: AnimatedPropsAdapterFunction[]
animatedValues: MutableRefObject<AnimatedStyle<any>>
): void {
'worklet';
const animations: AnimatedStyle<any> = state.animations ?? {};
Expand Down Expand Up @@ -360,12 +351,7 @@ function jestStyleUpdater(
});

if (Object.keys(updates).length) {
updatePropsJestWrapper(
viewDescriptors,
updates,
animatedValues,
adapters
);
updatePropsJestWrapper(viewDescriptors, updates, animatedValues);
}

if (!allFinished) {
Expand All @@ -391,12 +377,7 @@ function jestStyleUpdater(
state.last = newValues;

if (!shallowEqual(oldValues, newValues)) {
updatePropsJestWrapper(
viewDescriptors,
newValues,
animatedValues,
adapters
);
updatePropsJestWrapper(viewDescriptors, newValues, animatedValues);
}
}

Expand Down Expand Up @@ -456,7 +437,6 @@ export function useAnimatedStyle<Style extends DefaultStyle | AnimatedProps>(
| WorkletFunction<[], Style>
| ((() => Style) & Record<string, unknown>),
dependencies?: DependencyList | null,
adapters?: AnimatedPropsAdapterWorklet | AnimatedPropsAdapterWorklet[] | null,
isAnimatedProps = false
):
| AnimatedStyleHandle<Style | AnimatedProps>
Expand All @@ -480,12 +460,7 @@ For more, see the docs: \`https://docs.swmansion.com/react-native-reanimated/doc
);
}
}
const adaptersArray = adapters
? Array.isArray(adapters)
? adapters
: [adapters]
: [];
const adaptersHash = adapters ? buildWorkletsHash(adaptersArray) : null;

const areAnimationsActive = useSharedValue<boolean>(true);
const jestAnimatedValues = useRef<Style | AnimatedProps>(
{} as Style | AnimatedProps
Expand All @@ -497,9 +472,6 @@ For more, see the docs: \`https://docs.swmansion.com/react-native-reanimated/doc
} else {
dependencies.push(updater.__workletHash);
}
if (adaptersHash) {
dependencies.push(adaptersHash);
}

if (!animatedUpdaterData.current) {
const initialStyle = initialUpdaterRun(updater);
Expand Down Expand Up @@ -528,17 +500,7 @@ For more, see the docs: \`https://docs.swmansion.com/react-native-reanimated/doc

useEffect(() => {
let fun;
let updaterFn = updater;
if (adapters) {
updaterFn = (() => {
'worklet';
const newValues = updater();
adaptersArray.forEach((adapter) => {
adapter(newValues as Record<string, unknown>);
});
return newValues;
}) as WorkletFunction<[], Style>;
}
const updaterFn = updater;

if (IS_JEST) {
fun = () => {
Expand All @@ -548,8 +510,7 @@ For more, see the docs: \`https://docs.swmansion.com/react-native-reanimated/doc
updater,
remoteState,
areAnimationsActive,
jestAnimatedValues,
adaptersArray
jestAnimatedValues
);
};
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-reanimated/src/hook/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ReanimatedError } from '../common';
import type { DependencyList } from './commonTypes';

// Builds one big hash from multiple worklets' hashes.
export function buildWorkletsHash<Args extends unknown[], ReturnValue>(
function buildWorkletsHash<Args extends unknown[], ReturnValue>(
worklets:
| Record<string, WorkletFunction<Args, ReturnValue>>
| WorkletFunction<Args, ReturnValue>[]
Expand Down
1 change: 0 additions & 1 deletion packages/react-native-reanimated/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ export {
setNativeProps,
} from './platformFunctions';
export { getUseOfValueInStyleWarning } from './pluginUtils';
export { createAnimatedPropAdapter } from './PropAdapters';
export type {
AnimatedScreenTransition,
GoBackGesture,
Expand Down
5 changes: 0 additions & 5 deletions packages/react-native-reanimated/src/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,6 @@ const Colors = {
// convertToRGBA: ADD ME IF NEEDED
};

const PropAdapters = {
// createAnimatedPropAdapter: ADD ME IF NEEDED
};

class BaseAnimationMock {
duration() {
return this;
Expand Down Expand Up @@ -476,7 +472,6 @@ const Reanimated = {
...Easing,
...platformFunctions,
...Colors,
...PropAdapters,
...layoutReanimation,
...isSharedValue,
...commonTypes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,8 @@ if (SHOULD_BE_USE_WEB) {
export const updatePropsJestWrapper = (
viewDescriptors: ViewDescriptorsWrapper,
updates: AnimatedStyle<any>,
animatedValues: MutableRefObject<AnimatedStyle<any>>,
adapters: ((updates: AnimatedStyle<any>) => void)[]
animatedValues: MutableRefObject<AnimatedStyle<any>>
): void => {
adapters.forEach((adapter) => {
adapter(updates);
});
animatedValues.current.value = {
...animatedValues.current.value,
...updates,
Expand Down
2 changes: 0 additions & 2 deletions packages/react-native-worklets/plugin/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const reanimatedFunctionHooks = new Set([
'useFrameCallback',
'useAnimatedStyle',
'useAnimatedProps',
'createAnimatedPropAdapter',
'useDerivedValue',
'useAnimatedScrollHandler',
'useAnimatedReaction',
Expand All @@ -45,7 +44,6 @@ const reanimatedFunctionArgsToWorkletize = new Map([
['useFrameCallback', [0]],
['useAnimatedStyle', [0]],
['useAnimatedProps', [0]],
['createAnimatedPropAdapter', [0]],
['useDerivedValue', [0]],
['useAnimatedScrollHandler', [0]],
['useAnimatedReaction', [0, 1]],
Expand Down