Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore missing API #4847

Merged
merged 10 commits into from
Aug 4, 2023
Merged
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
86 changes: 80 additions & 6 deletions src/Animated.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,87 @@
export { default as createAnimatedComponent } from './createAnimatedComponent';
export {
addWhitelistedNativeProps,
addWhitelistedUIProps,
import type { Extrapolate as _Extrapolate } from './reanimated2/interpolateColor';
import type { SharedValue as _SharedValue } from './reanimated2/commonTypes';
import type { DerivedValue as _DerivedValue } from './reanimated2/hook/useDerivedValue';
import type {
TransformStyleTypes as _TransformStyleTypes,
Adaptable as _Adaptable,
AdaptTransforms as _AdaptTransforms,
AnimatedTransform as _AnimatedTransform,
AnimateStyle as _AnimateStyle,
StylesOrDefault as _StylesOrDefault,
AnimateProps as _AnimateProps,
} from './reanimated2/helperTypes';
import type { EasingFunction as _EasingFunction } from './reanimated2/Easing';
import {
addWhitelistedNativeProps as _addWhitelistedNativeProps,
addWhitelistedUIProps as _addWhitelistedUIProps,
} from './ConfigHelper';
import type { AnimatedScrollViewProps as _AnimatedScrollViewProps } from './reanimated2/component/ScrollView';
import type { FlatListPropsWithLayout as _FlatListPropsWithLayout } from './reanimated2/component/FlatList';
export { default as createAnimatedComponent } from './createAnimatedComponent';

export { AnimatedText as Text } from './reanimated2/component/Text';
export { AnimatedView as View } from './reanimated2/component/View';
export { AnimatedScrollView as ScrollView } from './reanimated2/component/ScrollView';
export { AnimatedImage as Image } from './reanimated2/component/Image';
export { ReanimatedFlatList as FlatList } from './reanimated2/component/FlatList';
export type { SharedValue } from './reanimated2/commonTypes';
export type { AnimatedStyle, AnimateStyle } from './reanimated2/helperTypes';
/**
* @deprecated Please import `Extrapolate` directly from `react-native-reanimated` instead of `Animated` namespace.
*/
export type Extrapolate = typeof _Extrapolate;
/**
* @deprecated Please import `SharedValue` directly from `react-native-reanimated` instead of `Animated` namespace.
*/

export type SharedValue<T> = _SharedValue<T>;
/**
* @deprecated Please import `DerivedValue` directly from `react-native-reanimated` instead of `Animated` namespace.
*/
export type DerivedValue<T> = _DerivedValue<T>;
/**
* @deprecated Please import `Adaptable` directly from `react-native-reanimated` instead of `Animated` namespace.
*/
export type Adaptable<T> = _Adaptable<T>;
/**
* @deprecated Please import `TransformStyleTypes` directly from `react-native-reanimated` instead of `Animated` namespace.
* */
export type TransformStyleTypes = _TransformStyleTypes;
/**
* @deprecated Please import `AdaptTransforms` directly from `react-native-reanimated` instead of `Animated` namespace.
* */
export type AdaptTransforms<T> = _AdaptTransforms<T>;
/**
* @deprecated Please import `AnimatedTransform` directly from `react-native-reanimated` instead of `Animated` namespace.
*/
export type AnimatedTransform = _AnimatedTransform;
/**
* @deprecated Please import `AnimateStyle` directly from `react-native-reanimated` instead of `Animated` namespace.
* */
export type AnimateStyle<S> = _AnimateStyle<S>;
/**
* @deprecated Please import `StylesOrDefault` directly from `react-native-reanimated` instead of `Animated` namespace.
* */
export type StylesOrDefault<S> = _StylesOrDefault<S>;
/**
* @deprecated Please import `AnimateProps` directly from `react-native-reanimated` instead of `Animated` namespace.
* */
export type AnimateProps<P extends object> = _AnimateProps<P>;
/**
* @deprecated Please import `EasingFunction` directly from `react-native-reanimated` instead of `Animated` namespace.
* */
export type EasingFunction = _EasingFunction;
/**
* @deprecated Please import `addWhitelistedNativeProps` directly from `react-native-reanimated` instead of `Animated` namespace.
* */
export const addWhitelistedNativeProps = _addWhitelistedNativeProps;
/**
* @deprecated Please import `addWhitelistedUIProps` directly from `react-native-reanimated` instead of `Animated` namespace.
* */
export const addWhitelistedUIProps = _addWhitelistedUIProps;
/**
* @deprecated Please import `AnimatedScrollViewProps` directly from `react-native-reanimated` instead of `Animated` namespace.
* */
export type AnimatedScrollViewProps = _AnimatedScrollViewProps;
/**
* @deprecated Please import `FlatListPropsWithLayout` directly from `react-native-reanimated` instead of `Animated` namespace.
* */
export type FlatListPropsWithLayout<T> = _FlatListPropsWithLayout<T>;
26 changes: 18 additions & 8 deletions src/reanimated2/Easing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,19 @@ import { Bezier } from './Bezier';
* - [`out`](docs/easing.html#out) runs an easing function backwards
*/

export type EasingFn = (t: number) => number;
export type EasingFunction = (t: number) => number;

export type EasingFactoryFn = { factory: () => EasingFn };
/**
* @deprecated Please use `EasingFunction` type instead.
*/
export type EasingFn = EasingFunction;

export type EasingFunctionFactory = { factory: () => EasingFunction };

/**
* @deprecated Please use `EasingFunctionFactory` type instead.
*/
export type EasingFactoryFn = EasingFunctionFactory;
/**
* A linear function, `f(t) = t`. Position correlates to elapsed time one to
* one.
Expand Down Expand Up @@ -99,7 +109,7 @@ function cubic(t: number): number {
* n = 4: http://easings.net/#easeInQuart
* n = 5: http://easings.net/#easeInQuint
*/
function poly(n: number): EasingFn {
function poly(n: number): EasingFunction {
'worklet';
return (t) => {
'worklet';
Expand Down Expand Up @@ -147,7 +157,7 @@ function exp(t: number): number {
*
* http://easings.net/#easeInElastic
*/
function elastic(bounciness = 1): EasingFn {
function elastic(bounciness = 1): EasingFunction {
'worklet';
const p = bounciness * Math.PI;
return (t) => {
Expand Down Expand Up @@ -232,15 +242,15 @@ function bezierFn(
/**
* Runs an easing function forwards.
*/
function in_(easing: EasingFn): EasingFn {
function in_(easing: EasingFunction): EasingFunction {
'worklet';
return easing;
}

/**
* Runs an easing function backwards.
*/
function out(easing: EasingFn): EasingFn {
function out(easing: EasingFunction): EasingFunction {
'worklet';
return (t) => {
'worklet';
Expand All @@ -253,7 +263,7 @@ function out(easing: EasingFn): EasingFn {
* forwards for half of the duration, then backwards for the rest of the
* duration.
*/
function inOut(easing: EasingFn): EasingFn {
function inOut(easing: EasingFunction): EasingFunction {
'worklet';
return (t) => {
'worklet';
Expand All @@ -270,7 +280,7 @@ function inOut(easing: EasingFn): EasingFn {
* steps in the animation, and the `roundToNextStep` parameter determines whether the animation
* should start at the beginning or end of each step.
*/
function steps(n = 10, roundToNextStep = true): EasingFn {
function steps(n = 10, roundToNextStep = true): EasingFunction {
'worklet';
return (t) => {
'worklet';
Expand Down
2 changes: 2 additions & 0 deletions src/reanimated2/animation/decay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ interface DecayConfig {
velocity?: number;
}

export type WithDecayConfig = DecayConfig;

interface DefaultDecayConfig {
deceleration: number;
velocityFactor: number;
Expand Down
6 changes: 3 additions & 3 deletions src/reanimated2/animation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ export type {
} from './commonTypes';
export { cancelAnimation, defineAnimation, initialUpdaterRun } from './util';
export { withTiming } from './timing';
export type { TimingAnimation } from './timing';
export type { TimingAnimation, WithTimingConfig } from './timing';
export { withSpring } from './spring';
export type { SpringAnimation } from './springUtils';
export { withDecay } from './decay';
export type { SpringAnimation, WithSpringConfig } from './springUtils';
export { withDecay, WithDecayConfig } from './decay';
export type { DecayAnimation } from './decay';
export { withDelay } from './delay';
export { withRepeat } from './repeat';
Expand Down
2 changes: 2 additions & 0 deletions src/reanimated2/animation/springUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export type SpringConfig = {
}
);

export type WithSpringConfig = SpringConfig;

export interface SpringConfigInner {
useDuration: boolean;
configIsInvalid: boolean;
Expand Down
8 changes: 5 additions & 3 deletions src/reanimated2/animation/timing.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { EasingFn, EasingFactoryFn } from '../Easing';
import type { EasingFunction, EasingFunctionFactory } from '../Easing';
import { Easing } from '../Easing';
import { defineAnimation } from './util';
import type {
Expand All @@ -10,12 +10,14 @@ import type {

interface TimingConfig {
duration?: number;
easing?: EasingFn | EasingFactoryFn;
easing?: EasingFunction | EasingFunctionFactory;
}

export type WithTimingConfig = TimingConfig;

export interface TimingAnimation extends Animation<TimingAnimation> {
type: string;
easing: EasingFn;
easing: EasingFunction;
startValue: AnimatableValue;
startTime: Timestamp;
progress: number;
Expand Down
2 changes: 2 additions & 0 deletions src/reanimated2/component/FlatList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ interface ReanimatedFlatListPropsWithLayout<T> extends FlatListProps<T> {
itemLayoutAnimation?: ILayoutAnimationBuilder;
}

export type FlatListPropsWithLayout<T> = ReanimatedFlatListPropsWithLayout<T>;

// TODO TYPESCRIPT This is a temporary type to get rid of .d.ts file.
declare class ReanimatedFlatListClass<T> extends Component<
AnimateProps<ReanimatedFlatListPropsWithLayout<T>>
Expand Down
2 changes: 1 addition & 1 deletion src/reanimated2/component/ScrollView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { SharedValue } from '../commonTypes';
import type { AnimateProps } from '../helperTypes';
import { useAnimatedRef, useScrollViewOffset } from '../hook';

interface AnimatedScrollViewProps extends ScrollViewProps {
export interface AnimatedScrollViewProps extends ScrollViewProps {
scrollViewOffset?: SharedValue<number>;
}

Expand Down
13 changes: 8 additions & 5 deletions src/reanimated2/helperTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,24 @@ import type { ReanimatedKeyframe } from './layoutReanimation/animationBuilder/Ke
import type { SharedTransition } from './layoutReanimation/sharedTransitions';
import type { DependencyList } from './hook/commonTypes';

type Adaptable<T> = T | ReadonlyArray<T | ReadonlyArray<T>> | SharedValue<T>;
export type Adaptable<T> =
| T
| ReadonlyArray<T | ReadonlyArray<T>>
| SharedValue<T>;

type AdaptTransforms<T> = {
export type AdaptTransforms<T> = {
[P in keyof T]: Adaptable<T[P]>;
};

type TransformsStyle = Pick<RNTransformsStyle, 'transform'>;

type TransformStyleTypes = TransformsStyle['transform'] extends
export type TransformStyleTypes = TransformsStyle['transform'] extends
| readonly (infer T)[]
| string
| undefined
? T
: never;
type AnimatedTransform = AdaptTransforms<TransformStyleTypes>[];
export type AnimatedTransform = AdaptTransforms<TransformStyleTypes>[];

/**
* @deprecated Please use `AnimatedStyle` type instead.
Expand All @@ -62,7 +65,7 @@ type MaybeSharedValue<S> = {
[K in keyof S]: S[K] | Readonly<SharedValue<Extract<S[K], AnimatableValue>>>;
};

type StylesOrDefault<T> = 'style' extends keyof T
export type StylesOrDefault<T> = 'style' extends keyof T
? MaybeSharedValue<T['style']>
: Record<string, unknown>;

Expand Down
5 changes: 4 additions & 1 deletion src/reanimated2/hook/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ export {
export { useSharedValue } from './useSharedValue';
export { useReducedMotion } from './useReducedMotion';
export { useAnimatedStyle } from './useAnimatedStyle';
export type { AnimatedStyleResult } from './useAnimatedStyle';
export type {
AnimatedStyleResult,
AnimatedStyleProp,
} from './useAnimatedStyle';
export { useAnimatedGestureHandler } from './useAnimatedGestureHandler';
export type {
GestureHandlerEvent,
Expand Down
4 changes: 2 additions & 2 deletions src/reanimated2/hook/useAnimatedStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,8 @@ function checkSharedValueUsage(
}
}

// TODO TYPESCRIPT This is a temporary type to get rid of .d.ts file.
type AnimatedStyleProp<T> =
// This type is kept for backward compatibility.
export type AnimatedStyleProp<T> =
| AnimatedStyle<T>
| RegisteredStyle<AnimatedStyle<T>>;

Expand Down
14 changes: 13 additions & 1 deletion src/reanimated2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,16 @@ export * from './commonTypes';
export * from './frameCallback';
export * from './pluginUtils';
export * from './jestUtils';
export type { AnimateProps } from './helperTypes';
export type {
Adaptable,
AdaptTransforms,
AnimateProps,
AnimatedProps,
AnimatedTransform,
TransformStyleTypes,
AnimateStyle,
AnimatedStyle,
StylesOrDefault,
} from './helperTypes';
export type { AnimatedScrollViewProps } from './component/ScrollView';
export type { FlatListPropsWithLayout } from './component/FlatList';
4 changes: 2 additions & 2 deletions src/reanimated2/interpolateColor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const interpolateColorsRGB = (
);
};

interface InterpolateRGB {
export interface InterpolateRGB {
r: number[];
g: number[];
b: number[];
Expand Down Expand Up @@ -141,7 +141,7 @@ const getInterpolateRGB = (
return { r, g, b, a };
};

interface InterpolateHSV {
export interface InterpolateHSV {
h: number[];
s: number[];
v: number[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import type {
BaseBuilderAnimationConfig,
LayoutAnimationAndConfig,
} from './commonTypes';
import type { EasingFn } from '../../Easing';
import type { EasingFunction } from '../../Easing';
import { BaseAnimationBuilder } from './BaseAnimationBuilder';
import type { StyleProps } from '../../commonTypes';

export class ComplexAnimationBuilder extends BaseAnimationBuilder {
easingV?: EasingFn;
easingV?: EasingFunction;
rotateV?: string;
type?: AnimationFunction;
dampingV?: number;
Expand All @@ -27,13 +27,13 @@ export class ComplexAnimationBuilder extends BaseAnimationBuilder {

static easing<T extends typeof ComplexAnimationBuilder>(
this: T,
easingFunction: EasingFn
easingFunction: EasingFunction
) {
const instance = this.createInstance();
return instance.easing(easingFunction);
}

easing(easingFunction: EasingFn): this {
easing(easingFunction: EasingFunction): this {
this.easingV = easingFunction;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { EasingFn } from '../../Easing';
import type { EasingFunction } from '../../Easing';
import { Easing } from '../../Easing';
import { withDelay, withSequence, withTiming } from '../../animation';
import type {
Expand All @@ -11,7 +11,7 @@ import type { TransformProperty, StyleProps } from '../../commonTypes';
interface KeyframePoint {
duration: number;
value: number | string;
easing?: EasingFn;
easing?: EasingFunction;
}
interface ParsedKeyframesDefinition {
initialValues: StyleProps;
Expand Down Expand Up @@ -113,7 +113,7 @@ class InnerKeyframe implements IEntryExitAnimationBuilder {
key: string;
value: string | number;
currentKeyPoint: number;
easing?: EasingFn;
easing?: EasingFunction;
}): void => {
if (!(key in parsedKeyframes)) {
throw Error(
Expand Down
Loading