1/**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @format
8 */
9
10export type LayoutAnimationType =
11  | 'spring'
12  | 'linear'
13  | 'easeInEaseOut'
14  | 'easeIn'
15  | 'easeOut'
16  | 'keyboard';
17
18export type LayoutAnimationTypes = {
19  [type in LayoutAnimationType]: type;
20};
21
22export type LayoutAnimationProperty =
23  | 'opacity'
24  | 'scaleX'
25  | 'scaleY'
26  | 'scaleXY';
27
28export type LayoutAnimationProperties = {
29  [prop in LayoutAnimationProperty]: prop;
30};
31
32export interface LayoutAnimationAnim {
33  duration?: number | undefined;
34  delay?: number | undefined;
35  springDamping?: number | undefined;
36  initialVelocity?: number | undefined;
37  type?: LayoutAnimationType | undefined;
38  property?: LayoutAnimationProperty | undefined;
39}
40
41export interface LayoutAnimationConfig {
42  duration: number;
43  create?: LayoutAnimationAnim | undefined;
44  update?: LayoutAnimationAnim | undefined;
45  delete?: LayoutAnimationAnim | undefined;
46}
47
48/** Automatically animates views to their new positions when the next layout happens.
49 * A common way to use this API is to call LayoutAnimation.configureNext before
50 * calling setState. */
51export interface LayoutAnimationStatic {
52  /** Schedules an animation to happen on the next layout.
53   * @param config Specifies animation properties:
54   * `duration` in milliseconds
55   * `create`, config for animating in new views (see Anim type)
56   * `update`, config for animating views that have been updated (see Anim type)
57   * @param onAnimationDidEnd Called when the animation finished. Only supported on iOS.
58   */
59  configureNext: (
60    config: LayoutAnimationConfig,
61    onAnimationDidEnd?: () => void,
62    onAnimationDidFail?: () => void,
63  ) => void;
64  /** Helper for creating a config for configureNext. */
65  create: (
66    duration: number,
67    type?: LayoutAnimationType,
68    creationProp?: LayoutAnimationProperty,
69  ) => LayoutAnimationConfig;
70  Types: LayoutAnimationTypes;
71  Properties: LayoutAnimationProperties;
72  configChecker: (shapeTypes: {[key: string]: any}) => any;
73  Presets: {
74    easeInEaseOut: LayoutAnimationConfig;
75    linear: LayoutAnimationConfig;
76    spring: LayoutAnimationConfig;
77  };
78  easeInEaseOut: (onAnimationDidEnd?: () => void) => void;
79  linear: (onAnimationDidEnd?: () => void) => void;
80  spring: (onAnimationDidEnd?: () => void) => void;
81}
82
83export const LayoutAnimation: LayoutAnimationStatic;
84export type LayoutAnimation = LayoutAnimationStatic;
85