2015-02-19 01:39:09 +00:00
|
|
|
/**
|
2015-03-23 22:07:33 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
2015-02-19 01:39:09 +00:00
|
|
|
*
|
|
|
|
* @providesModule LayoutAnimation
|
2015-03-25 02:34:12 +00:00
|
|
|
* @flow
|
2017-05-12 22:01:24 +00:00
|
|
|
* @format
|
2015-02-19 01:39:09 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2017-05-12 22:01:24 +00:00
|
|
|
const PropTypes = require('prop-types');
|
|
|
|
const UIManager = require('UIManager');
|
2015-02-19 01:39:09 +00:00
|
|
|
|
2017-09-06 10:25:01 +00:00
|
|
|
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
|
|
|
|
* found when Flow v0.54 was deployed. To see the error delete this comment and
|
|
|
|
* run Flow. */
|
2017-05-12 22:01:24 +00:00
|
|
|
const keyMirror = require('fbjs/lib/keyMirror');
|
2015-02-19 01:39:09 +00:00
|
|
|
|
2017-05-12 22:01:24 +00:00
|
|
|
const {checkPropTypes} = PropTypes;
|
2017-03-22 22:58:29 +00:00
|
|
|
|
2017-05-12 22:01:24 +00:00
|
|
|
const TypesEnum = {
|
2015-02-19 01:39:09 +00:00
|
|
|
spring: true,
|
|
|
|
linear: true,
|
|
|
|
easeInEaseOut: true,
|
|
|
|
easeIn: true,
|
|
|
|
easeOut: true,
|
2015-06-25 16:14:19 +00:00
|
|
|
keyboard: true,
|
2015-04-09 15:46:53 +00:00
|
|
|
};
|
2017-05-12 22:01:24 +00:00
|
|
|
const Types = keyMirror(TypesEnum);
|
2015-02-19 01:39:09 +00:00
|
|
|
|
2017-05-12 22:01:24 +00:00
|
|
|
const PropertiesEnum = {
|
2015-02-19 01:39:09 +00:00
|
|
|
opacity: true,
|
|
|
|
scaleXY: true,
|
2015-04-09 15:46:53 +00:00
|
|
|
};
|
2017-05-12 22:01:24 +00:00
|
|
|
const Properties = keyMirror(PropertiesEnum);
|
2015-02-19 01:39:09 +00:00
|
|
|
|
2017-05-12 22:01:24 +00:00
|
|
|
const animType = PropTypes.shape({
|
2015-02-19 01:39:09 +00:00
|
|
|
duration: PropTypes.number,
|
|
|
|
delay: PropTypes.number,
|
|
|
|
springDamping: PropTypes.number,
|
|
|
|
initialVelocity: PropTypes.number,
|
2017-05-12 22:01:24 +00:00
|
|
|
type: PropTypes.oneOf(Object.keys(Types)).isRequired,
|
|
|
|
property: PropTypes.oneOf(
|
|
|
|
// Only applies to create/delete
|
|
|
|
Object.keys(Properties),
|
2015-02-19 01:39:09 +00:00
|
|
|
),
|
|
|
|
});
|
|
|
|
|
2015-03-25 02:34:12 +00:00
|
|
|
type Anim = {
|
2016-08-09 13:32:41 +00:00
|
|
|
duration?: number,
|
|
|
|
delay?: number,
|
|
|
|
springDamping?: number,
|
|
|
|
initialVelocity?: number,
|
|
|
|
type?: $Enum<typeof TypesEnum>,
|
|
|
|
property?: $Enum<typeof PropertiesEnum>,
|
2017-05-12 22:01:24 +00:00
|
|
|
};
|
2015-03-25 02:34:12 +00:00
|
|
|
|
2017-05-12 22:01:24 +00:00
|
|
|
const configType = PropTypes.shape({
|
2015-02-19 01:39:09 +00:00
|
|
|
duration: PropTypes.number.isRequired,
|
2017-03-22 22:58:29 +00:00
|
|
|
create: animType,
|
|
|
|
update: animType,
|
|
|
|
delete: animType,
|
2015-02-19 01:39:09 +00:00
|
|
|
});
|
|
|
|
|
2015-03-25 02:34:12 +00:00
|
|
|
type Config = {
|
2016-08-09 13:32:41 +00:00
|
|
|
duration: number,
|
|
|
|
create?: Anim,
|
|
|
|
update?: Anim,
|
|
|
|
delete?: Anim,
|
2017-05-12 22:01:24 +00:00
|
|
|
};
|
2015-03-25 02:34:12 +00:00
|
|
|
|
2017-03-22 22:58:29 +00:00
|
|
|
function checkConfig(config: Config, location: string, name: string) {
|
|
|
|
checkPropTypes({config: configType}, {config}, location, name);
|
|
|
|
}
|
|
|
|
|
2015-08-01 08:44:05 +00:00
|
|
|
function configureNext(config: Config, onAnimationDidEnd?: Function) {
|
2017-02-15 03:58:24 +00:00
|
|
|
if (__DEV__) {
|
2017-03-22 22:58:29 +00:00
|
|
|
checkConfig(config, 'config', 'LayoutAnimation.configureNext');
|
2017-02-15 03:58:24 +00:00
|
|
|
}
|
2015-11-27 13:39:00 +00:00
|
|
|
UIManager.configureNextLayoutAnimation(
|
2017-05-12 22:01:24 +00:00
|
|
|
config,
|
|
|
|
onAnimationDidEnd || function() {},
|
|
|
|
function() {
|
|
|
|
/* unused */
|
|
|
|
},
|
2015-08-01 08:44:05 +00:00
|
|
|
);
|
2015-03-25 02:34:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function create(duration: number, type, creationProp): Config {
|
|
|
|
return {
|
|
|
|
duration,
|
|
|
|
create: {
|
|
|
|
type,
|
|
|
|
property: creationProp,
|
|
|
|
},
|
|
|
|
update: {
|
|
|
|
type,
|
|
|
|
},
|
2017-03-10 04:13:12 +00:00
|
|
|
delete: {
|
|
|
|
type,
|
|
|
|
property: creationProp,
|
|
|
|
},
|
2015-03-25 02:34:12 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-05-12 22:01:24 +00:00
|
|
|
const Presets = {
|
|
|
|
easeInEaseOut: create(300, Types.easeInEaseOut, Properties.opacity),
|
|
|
|
linear: create(500, Types.linear, Properties.opacity),
|
[ReactNative] Animated infra - ValueXY, addListener, fixes, etc
Summary:
This is most of the infra necessary for the gratuitous animation demo app.
I originally had things more split up, but it was just confusing because everything is so interlinked and dependent, so lower diffs would have code that wasn't even going to survive (and thus not useful to review), so I merged it all here.
- `Animated.event` now supports mapping to multiple arguments (needed for `onPanResponderMove` events which provide the `gestureState` as the second arg.
- Vectors: new `Animated.ValueXY` class which composes two `Animated.Value`s for convenience/brevity
- Listeners: values and events can be listened to in order to trigger state updates based on their values. Intended to work as async updates from native that might lag behind truth.
- Offsets: a common pattern with pan and other gestures is to track where you left off. This is easily encoded in the Value directly with `setOffset(offset)`, typically used on grant, and can be flattened back into the base value and reset with `flattenOffset()`, typically called on release.
- Tracking: supports `Animated.Value/ValueXY` for `toValue` with all animations, enabling linking multiple values together with some curve or physics. `Animated.timing` can be used with `duration: 0` to rigidly link the values with no lag, or `Animated.spring` can be used to link them like chat heads.
- `Animated.Image` as a default export.
- Various cleanup, bug, flow and lint fixes.
2015-07-07 20:33:51 +00:00
|
|
|
spring: {
|
|
|
|
duration: 700,
|
|
|
|
create: {
|
|
|
|
type: Types.linear,
|
|
|
|
property: Properties.opacity,
|
|
|
|
},
|
|
|
|
update: {
|
|
|
|
type: Types.spring,
|
|
|
|
springDamping: 0.4,
|
|
|
|
},
|
2017-03-10 04:13:12 +00:00
|
|
|
delete: {
|
|
|
|
type: Types.linear,
|
|
|
|
property: Properties.opacity,
|
|
|
|
},
|
[ReactNative] Animated infra - ValueXY, addListener, fixes, etc
Summary:
This is most of the infra necessary for the gratuitous animation demo app.
I originally had things more split up, but it was just confusing because everything is so interlinked and dependent, so lower diffs would have code that wasn't even going to survive (and thus not useful to review), so I merged it all here.
- `Animated.event` now supports mapping to multiple arguments (needed for `onPanResponderMove` events which provide the `gestureState` as the second arg.
- Vectors: new `Animated.ValueXY` class which composes two `Animated.Value`s for convenience/brevity
- Listeners: values and events can be listened to in order to trigger state updates based on their values. Intended to work as async updates from native that might lag behind truth.
- Offsets: a common pattern with pan and other gestures is to track where you left off. This is easily encoded in the Value directly with `setOffset(offset)`, typically used on grant, and can be flattened back into the base value and reset with `flattenOffset()`, typically called on release.
- Tracking: supports `Animated.Value/ValueXY` for `toValue` with all animations, enabling linking multiple values together with some curve or physics. `Animated.timing` can be used with `duration: 0` to rigidly link the values with no lag, or `Animated.spring` can be used to link them like chat heads.
- `Animated.Image` as a default export.
- Various cleanup, bug, flow and lint fixes.
2015-07-07 20:33:51 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2015-08-03 14:43:13 +00:00
|
|
|
/**
|
|
|
|
* Automatically animates views to their new positions when the
|
|
|
|
* next layout happens.
|
|
|
|
*
|
2016-11-25 23:19:44 +00:00
|
|
|
* A common way to use this API is to call it before calling `setState`.
|
2017-03-10 04:13:12 +00:00
|
|
|
*
|
|
|
|
* Note that in order to get this to work on **Android** you need to set the following flags via `UIManager`:
|
|
|
|
*
|
|
|
|
* UIManager.setLayoutAnimationEnabledExperimental && UIManager.setLayoutAnimationEnabledExperimental(true);
|
2015-08-03 14:43:13 +00:00
|
|
|
*/
|
2017-05-12 22:01:24 +00:00
|
|
|
const LayoutAnimation = {
|
2015-08-03 14:43:13 +00:00
|
|
|
/**
|
|
|
|
* Schedules an animation to happen on the next layout.
|
|
|
|
*
|
|
|
|
* @param config Specifies animation properties:
|
|
|
|
*
|
|
|
|
* - `duration` in milliseconds
|
|
|
|
* - `create`, config for animating in new views (see `Anim` type)
|
|
|
|
* - `update`, config for animating views that have been updated
|
|
|
|
* (see `Anim` type)
|
|
|
|
*
|
|
|
|
* @param onAnimationDidEnd Called when the animation finished.
|
|
|
|
* Only supported on iOS.
|
|
|
|
* @param onError Called on error. Only supported on iOS.
|
|
|
|
*/
|
2015-03-25 02:34:12 +00:00
|
|
|
configureNext,
|
2015-08-03 14:43:13 +00:00
|
|
|
/**
|
|
|
|
* Helper for creating a config for `configureNext`.
|
|
|
|
*/
|
2015-03-25 02:34:12 +00:00
|
|
|
create,
|
|
|
|
Types,
|
|
|
|
Properties,
|
2017-03-22 22:58:29 +00:00
|
|
|
checkConfig,
|
[ReactNative] Animated infra - ValueXY, addListener, fixes, etc
Summary:
This is most of the infra necessary for the gratuitous animation demo app.
I originally had things more split up, but it was just confusing because everything is so interlinked and dependent, so lower diffs would have code that wasn't even going to survive (and thus not useful to review), so I merged it all here.
- `Animated.event` now supports mapping to multiple arguments (needed for `onPanResponderMove` events which provide the `gestureState` as the second arg.
- Vectors: new `Animated.ValueXY` class which composes two `Animated.Value`s for convenience/brevity
- Listeners: values and events can be listened to in order to trigger state updates based on their values. Intended to work as async updates from native that might lag behind truth.
- Offsets: a common pattern with pan and other gestures is to track where you left off. This is easily encoded in the Value directly with `setOffset(offset)`, typically used on grant, and can be flattened back into the base value and reset with `flattenOffset()`, typically called on release.
- Tracking: supports `Animated.Value/ValueXY` for `toValue` with all animations, enabling linking multiple values together with some curve or physics. `Animated.timing` can be used with `duration: 0` to rigidly link the values with no lag, or `Animated.spring` can be used to link them like chat heads.
- `Animated.Image` as a default export.
- Various cleanup, bug, flow and lint fixes.
2015-07-07 20:33:51 +00:00
|
|
|
Presets,
|
2017-05-12 22:01:24 +00:00
|
|
|
easeInEaseOut: configureNext.bind(null, Presets.easeInEaseOut),
|
|
|
|
linear: configureNext.bind(null, Presets.linear),
|
|
|
|
spring: configureNext.bind(null, Presets.spring),
|
2015-02-19 01:39:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = LayoutAnimation;
|