forked from google-fabric/velocity-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvelocity-helpers.js
80 lines (72 loc) · 2.23 KB
/
velocity-helpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright (c) 2015 Twitter, Inc. and other contributors
var _ = {
isObject: require('lodash/lang/isObject'),
};
var Velocity = require('./lib/velocity-animate-shim');
var effectCounter = 0;
// Takes a Velocity "UI pack effect" definition and registers it with a unique key, returning that
// key (to later pass as a value for the "animation" property). Takes an optional suffix, which can
// be "In" or "Out" to modify UI Pack's behavior.
//
// Unlike what you get from passing a style hash to VelocityComponent's "animation" property,
// Velocity "UI pack effects" can have chained animation calls and specify a "defaultDuration", and
// also can take advantage of "stagger" and "reverse" options on the VelocityComponent.
//
// You will need to manually register the UI Pack with the global Velocity in your application with:
//
// require('velocity');
// require('velocity-animate/velocity.ui');
//
// See: http://julian.com/research/velocity/#uiPack
//
// Typical usage:
//
// var Animations = {
// down: VelocityHelpers.registerEffect({
// defaultDuration: 1100,
// calls: [
// [{
// transformOriginX: [ '50%', '50%' ],
// transformOriginY: [ 0, 0 ],
// rotateX: [0, 'spring'],
// }, 1, {
// delay: 100,
// easing: 'ease-in',
// }]
// ],
// }),
//
// up: VelocityHelpers.registerEffect({
// defaultDuration: 200,
// calls: [
// [{
// transformOriginX: [ '50%', '50%' ],
// transformOriginY: [ 0, 0 ],
// rotateX: 160,
// }]
// ],
// }),
// };
// ...
// <VelocityComponent animation={this.state.isUp ? Animations.up : Animations.down}>
// ...
// <Velocity>
function registerEffect(suffix, animation) {
if (_.isObject(suffix)) {
animation = suffix;
suffix = '';
}
var key = 'VelocityHelper.animation.' + (effectCounter++) + suffix;
// No-op on the server for now.
if (Velocity.velocityReactServerShim) {
return key
}
if (Velocity.RegisterEffect === undefined) {
throw "Velocity.RegisterEffect not found. You need to require 'velocity-animate/velocity.ui' at a top level for UI Pack.";
}
Velocity.RegisterEffect(key, animation);
return key;
}
module.exports = {
registerEffect: registerEffect,
};