|
7 | 7 | * of patent rights can be found in the PATENTS file in the same directory. |
8 | 8 | * |
9 | 9 | * @providesModule LayoutAnimation |
| 10 | + * @flow |
10 | 11 | */ |
11 | 12 | 'use strict'; |
12 | 13 |
|
@@ -42,53 +43,72 @@ var animChecker = createStrictShapeTypeChecker({ |
42 | 43 | ), |
43 | 44 | }); |
44 | 45 |
|
| 46 | +type Anim = { |
| 47 | + duration?: number; |
| 48 | + delay?: number; |
| 49 | + springDamping?: number; |
| 50 | + initialVelocity?: number; |
| 51 | + type?: $Enum<typeof Types>; |
| 52 | + property?: $Enum<typeof Properties>; |
| 53 | +} |
| 54 | + |
45 | 55 | var configChecker = createStrictShapeTypeChecker({ |
46 | 56 | duration: PropTypes.number.isRequired, |
47 | 57 | create: animChecker, |
48 | 58 | update: animChecker, |
49 | 59 | delete: animChecker, |
50 | 60 | }); |
51 | 61 |
|
| 62 | +type Config = { |
| 63 | + duration: number; |
| 64 | + create?: Anim; |
| 65 | + update?: Anim; |
| 66 | + delete?: Anim; |
| 67 | +} |
| 68 | + |
| 69 | +function configureNext(config: Config, onAnimationDidEnd?: Function, onError?: Function) { |
| 70 | + configChecker({config}, 'config', 'LayoutAnimation.configureNext'); |
| 71 | + RCTUIManager.configureNextLayoutAnimation(config, onAnimationDidEnd, onError); |
| 72 | +} |
| 73 | + |
| 74 | +function create(duration: number, type, creationProp): Config { |
| 75 | + return { |
| 76 | + duration, |
| 77 | + create: { |
| 78 | + type, |
| 79 | + property: creationProp, |
| 80 | + }, |
| 81 | + update: { |
| 82 | + type, |
| 83 | + }, |
| 84 | + }; |
| 85 | +} |
| 86 | + |
52 | 87 | var LayoutAnimation = { |
53 | | - configureNext(config, onAnimationDidEnd, onError) { |
54 | | - configChecker({config}, 'config', 'LayoutAnimation.configureNext'); |
55 | | - RCTUIManager.configureNextLayoutAnimation(config, onAnimationDidEnd, onError); |
56 | | - }, |
57 | | - create(duration, type, creationProp) { |
58 | | - return { |
59 | | - duration, |
| 88 | + configureNext, |
| 89 | + create, |
| 90 | + Types, |
| 91 | + Properties, |
| 92 | + configChecker: configChecker, |
| 93 | + Presets: { |
| 94 | + easeInEaseOut: create( |
| 95 | + 0.3, Types.easeInEaseOut, Properties.opacity |
| 96 | + ), |
| 97 | + linear: create( |
| 98 | + 0.5, Types.linear, Properties.opacity |
| 99 | + ), |
| 100 | + spring: { |
| 101 | + duration: 0.7, |
60 | 102 | create: { |
61 | | - type, |
62 | | - property: creationProp, |
| 103 | + type: Types.linear, |
| 104 | + property: Properties.opacity, |
63 | 105 | }, |
64 | 106 | update: { |
65 | | - type, |
| 107 | + type: Types.spring, |
| 108 | + springDamping: 0.4, |
66 | 109 | }, |
67 | | - }; |
68 | | - }, |
69 | | - Types: Types, |
70 | | - Properties: Properties, |
71 | | - configChecker: configChecker, |
72 | | -}; |
73 | | - |
74 | | -LayoutAnimation.Presets = { |
75 | | - easeInEaseOut: LayoutAnimation.create( |
76 | | - 0.3, Types.easeInEaseOut, Properties.opacity |
77 | | - ), |
78 | | - linear: LayoutAnimation.create( |
79 | | - 0.5, Types.linear, Properties.opacity |
80 | | - ), |
81 | | - spring: { |
82 | | - duration: 0.7, |
83 | | - create: { |
84 | | - type: Types.linear, |
85 | | - property: Properties.opacity, |
86 | | - }, |
87 | | - update: { |
88 | | - type: Types.spring, |
89 | | - springDamping: 0.4, |
90 | 110 | }, |
91 | | - }, |
| 111 | + } |
92 | 112 | }; |
93 | 113 |
|
94 | 114 | module.exports = LayoutAnimation; |
0 commit comments