mirror of
https://github.com/status-im/react-native.git
synced 2025-01-15 03:56:03 +00:00
31c4ff0dd6
- [React Native] Sync from github | Amjad Masad - [react-packager] Watch asset roots for changes to update dependency graph | Amjad Masad - Fix sourceTree of RCTActionSheet.xcodeproj | Alex Kotliarskyi - Cancel contents animation before setting new contents in RCTNetworkImageView | Alex Akers - [react-packager] move dependencies to root package.json | Amjad Masad - Fix font crash on iOS < 8.2 | Nick Lockwood - [react-packager] Fix node v0.11.14 query parse bug | Amjad Masad - [ReactNative][Docs] Remove references to ReactNavigator from docs | Tadeu Zagallo - [CLI] react-native start won't run from dir with spaces | Amjad Masad - Revert .buckversion bumps. | Jakub Zika - [react_native] Update default bundle name to org.reactjs.native.* | Krzysztof Magiera - [react-packager] better error when main file not found | Amjad Masad - [React Kit] Remove embarrassing TODOs | Alex Akers - [ReactNative][MAdMan] Clean up after D1942269 | Philipp von Weitershausen - flowify a few more Libraries | Basil Hosmer - [ReactNative] PushNotificationIOS documentation | Eric Vicenti - [ReactNative][CustomComponents] Update old headers | Tadeu Zagallo - [ReactNative] UIViewControllerBasedStatusBarAppearance = NO in SampleApp | Alex Kotliarskyi - [React Native] Fix CocoaPods spec | Alex Akers - [ReactNative] Navigator Example Overhaul | Eric Vicenti - [React Native] Fix incorrect if-statement in RCTGeolocation | Alex Akers - [ReactNative] s/ReactKit/React/g | Tadeu Zagallo - [React Native] [FRC - Don't accept] View border support | Nick Lockwood - [Assets] Allow scripts to override assetRoots | Amjad Masad - [ReactNative] Navigator docs | Eric Vicenti - [ReactNative] License headers and renaming | Eric Vicenti - [React Native] Add CocoaPods spec | Tadeu Zagallo - Added explicit types for all view properties | Nick Lockwood - [ReactNative] s/ReactNavigator/Navigator/ | Tadeu Zagallo - [ReactNative] Add copyright header for code copied from the jQuery UI project | Martin Konicek - [ReactNative] PanResponder documentation | Eric Vicenti - [ReactNative] Add deep linking api | Tadeu Zagallo - [ReactNative] Add gitignore example for SampleApp | Alex Kotliarskyi - [ReactNative] Add react-native-start bin to react-native packge | Alex Kotliarskyi - [ReactNative] Update package.json to be npm-ready | Christopher Chedeau - [RFC][ReactNative] Integrate dev menu directly into RootView | Alex Kotliarskyi - flowify Libraries/ReactIOS | Marshall Roch - [WIP] Added support for italics and additional font weights | Nick Lockwood - [ReactNative] Improve View documentation | Christopher Chedeau - [react-packager] Readme | Amjad Masad - Fix for incorrect contentSize reported by RCTScrollView | Nick Lockwood - [ReactNative] Flow and doc formatting for NetInfo | Eric Vicenti - [ReactNative] Document AppStateIOS | Eric Vicenti - [MAdMan][Android] Make things look more Androidy | Philipp von Weitershausen - flowified Libraries from Avik | Basil Hosmer - flowify some Libraries | Basil Hosmer - [ReactKit] Add shake development menu | Alex Kotliarskyi - [ReactNative] Add debugger and change SampleApp files structure | Alex Kotliarskyi - Flowify ReactIOSEventEmitter | Marshall Roch - [react_native] JS files from D1941151: Allow fontWeight to be 100,200,...,900 | Krzysztof Magiera - [ReactNative] Add snapshot tests for examples | Spencer Ahrens - [ReactNative] bring back some native modules | Spencer Ahrens - [ReactNative] Rename JSNavigationStack to ReactNavigator, rename scene config | Eric Vicenti - [ReactNative] cleanup view example | Spencer Ahrens - Flowify a bunch of Libraries | Marshall Roch - [ReactNative] JSNavigationStack - Use key to blow away old scenes | Eric Vicenti - [ReactNative] Add more logging to RCTJSONParse | Sumeet Vaidya - Unfork UIManager | Nick Lockwood - [react-packager] kill non-standard RAW_SOURCE_MAP | Amjad Masad - Flowify Libraries/StyleSheet and Libraries/Text | Marshall Roch - [ReactNative] Fix OSS Dependency Issues | Eric Vicenti - [react-packager] Fix more issues with node modules | Amjad Masad - [ReactNative] rename navigationOperations to navigator | Eric Vicenti - JS files from D1936817: Add to XMLHttpRequest android and share code with ios | Olivia Bishop - flowify some Libraries | Basil Hosmer - last batch of UIExplorer flowification | Basil Hosmer - [ReactNative] JSNavigationStack rename routeMapper to renderSceneForRoute | Eric Vicenti - Flowify renderApplication | Marshall Roch - [ReactNative] OSS Responder example | Eric Vicenti - [ReactNative] Use oss TimerMixin | Tadeu Zagallo - [ReactNative] Remove auto permission request from setAppIconBadgeNumber | Tadeu Zagallo - [ReactNative] OSS snapshot tests | Spencer Ahrens - [ReactNative] OSS JSNavigationStack w/ Examples | Eric Vicenti - Fix build - remove relative import path | Jakub Zika - Bump .buckversion to a5b8b8ef45d714018ba3542cf98d48ef6aab7088. | Jakub Zika - [ReactNative] Open Source PushNotifications and move Badge Number methods and permission into it | Tadeu Zagallo - [react-packager] Fix regression with transform errors | Amjad Masad - Flowify TextStylePropTypes and fix a bug with unsupported props | Marshall Roch - [ReactNative] Remove `arc build` instructions from require | Alex Kotliarskyi - Flowify Library/Utilities/ | Marshall Roch - [react-packager] Default to index.js from main if it's a dir | Amjad Masad - [ReactNative] Use deprecated ix in TabBarExample | Amjad Masad - [ReactNative] Expanded license on obj-c files | Christopher Chedeau - [ReactNative] Expanded license on js files | Christopher Chedeau - [ReactNative] Fix React Devtools integration | Alex Kotliarskyi - [Text] Account for font leading so descenders are not clipped | Alex Kotliarskyi - [ReactNative] Expanded license on js packager files | Christopher Chedeau - more UIExplorer flow | Basil Hosmer - [react-packager] Pick up package changes while running | Amjad Masad - Added a graph view and a ReactNative metric that displays current queue and execution time for the JS thread. | Bryce Redd - [ReactNative] Add NativeModules and DeviceEventEmitter to react-native exports | Alex Kotliarskyi - [React Native] Fix iOS 7 crashes b/c missing Photos.fmwk | Alex Akers - UIExplorer flowification | Basil Hosmer - Add clearImmediate module | Marshall Roch - [ReactNative] Print directories packager is serving files from | Alex Kotliarskyi - Work around flow bug with exports | Marshall Roch - [ReactNative] Move packager/init.sh to GitHub | Alex Kotliarskyi - [ReactNative] Remove react-native/package.json | Christopher Chedeau - [ReactNative] Returning actual contentSize for RCTScrollViewManager | Henry Lung - declare timeoutID | Basil Hosmer - [ReactNative] Add root package.json name back | Tadeu Zagallo - [react-packager] Allow entry point extensions like .ios.js | Amjad Masad - [react-native] Use SpreadProperty to make react-docgen happy | Felix Kling - clean Examples/2048 | Basil Hosmer - [ReactNative] Adjust packager default root when running from within node_modules | Alex Kotliarskyi - [ReactNative] Add missing websocket dependency | Alex Kotliarskyi - [react-packager] change all but one `ix` to `require` | Amjad Masad - [react-packager] Make sure projectRoots is converted to an array | Amjad Masad - [ReactNative] Init script that bootstraps new Xcode project | Alex Kotliarskyi - [ReactNative] New SampleApp | Alex Kotliarskyi - [ReactNative] Touchable invoke press on longPress when longPress handler missing | Eric Vicenti - [ReactNative] Commit missing RCTWebSocketDebugger.xcodeproj | Alex Kotliarskyi
259 lines
8.3 KiB
JavaScript
259 lines
8.3 KiB
JavaScript
/**
|
|
* 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.
|
|
*
|
|
* @providesModule POPAnimationMixin
|
|
* @flow
|
|
*/
|
|
'use strict';
|
|
|
|
var POPAnimationOrNull = require('POPAnimation');
|
|
|
|
if (!POPAnimationOrNull) {
|
|
// POP animation isn't available in the OSS fork - this is a temporary
|
|
// workaround to enable its availability to be determined at runtime.
|
|
module.exports = (null : ?{});
|
|
} else {
|
|
|
|
// At this point, POPAnimationOrNull is guaranteed to be
|
|
// non-null. Bring it local to preserve type refinement.
|
|
var POPAnimation = POPAnimationOrNull;
|
|
|
|
var invariant = require('invariant');
|
|
var warning = require('warning');
|
|
|
|
var POPAnimationMixin = {
|
|
/**
|
|
* Different ways to interpolate between beginning and end states
|
|
* of properties during animation, such as spring, linear, and decay.
|
|
*/
|
|
AnimationTypes: POPAnimation.Types,
|
|
AnimationProperties: POPAnimation.Properties,
|
|
|
|
getInitialState: function(): Object {
|
|
return {
|
|
_currentAnimationsByNodeHandle: {},
|
|
};
|
|
},
|
|
|
|
_ensureBookkeepingSetup: function(nodeHandle: any) {
|
|
if (!this.state._currentAnimationsByNodeHandle[nodeHandle]) {
|
|
this.state._currentAnimationsByNodeHandle[nodeHandle] = [];
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Start animating the View with ref `refKey`.
|
|
*
|
|
* @param {key} refKey The key to reference the View to be animated.
|
|
*
|
|
* @param {number|Object} anim Either the identifier returned by
|
|
* POPAnimation.create* or an object defining all the necessary
|
|
* properties of the animation you wish to start (including type, matching
|
|
* an entry in AnimationTypes).
|
|
*
|
|
* @param {func} doneCallback A callback fired when the animation is done, and
|
|
* is passed a `finished` param that indicates whether the animation
|
|
* completely finished, or was interrupted.
|
|
*/
|
|
startAnimation: function(
|
|
refKey: string,
|
|
anim: number | {type: number; property: number;},
|
|
doneCallback: (finished: bool) => void
|
|
) {
|
|
var animID: number = 0;
|
|
if (typeof anim === 'number') {
|
|
animID = anim;
|
|
} else {
|
|
invariant(
|
|
anim instanceof Object &&
|
|
anim.type !== undefined &&
|
|
anim.property !== undefined,
|
|
'Animation definitions must specify a type of animation and a ' +
|
|
'property to animate.'
|
|
);
|
|
animID = POPAnimation.createAnimation(anim.type, anim);
|
|
}
|
|
invariant(
|
|
this.refs[refKey],
|
|
'Invalid refKey ' + refKey + ' for anim:\n' + JSON.stringify(anim) +
|
|
'\nvalid refs: ' + JSON.stringify(Object.keys(this.refs))
|
|
);
|
|
var refNodeHandle = this.refs[refKey].getNodeHandle();
|
|
this.startAnimationWithNodeHandle(refNodeHandle, animID, doneCallback);
|
|
},
|
|
|
|
/**
|
|
* Starts an animation on a native node.
|
|
*
|
|
* @param {NodeHandle} nodeHandle Handle to underlying native node.
|
|
* @see `startAnimation`.
|
|
*/
|
|
startAnimationWithNodeHandle: function(
|
|
nodeHandle: any,
|
|
animID: number,
|
|
doneCallback: (finished: bool) => void
|
|
) {
|
|
this._ensureBookkeepingSetup(nodeHandle);
|
|
var animations = this.state._currentAnimationsByNodeHandle[nodeHandle];
|
|
var animIndex = animations.length;
|
|
animations.push(animID);
|
|
var cleanupWrapper = (finished) => {
|
|
if (!this.isMounted()) {
|
|
return;
|
|
}
|
|
animations[animIndex] = 0; // zero it out so we don't try to stop it
|
|
var allDone = true;
|
|
for (var ii = 0; ii < animations.length; ii++) {
|
|
if (animations[ii]) {
|
|
allDone = false;
|
|
break;
|
|
}
|
|
}
|
|
if (allDone) {
|
|
this.state._currentAnimationsByNodeHandle[nodeHandle] = undefined;
|
|
}
|
|
doneCallback && doneCallback(finished);
|
|
};
|
|
POPAnimation.addAnimation(nodeHandle, animID, cleanupWrapper);
|
|
},
|
|
|
|
/**
|
|
* Starts multiple animations with one shared callback that is called when all
|
|
* animations complete.
|
|
*
|
|
* @param {Array(Object} animations Array of objects defining all the
|
|
* animations to start, each with shape `{ref|nodeHandle, anim}`.
|
|
* @param {func} onSuccess A callback fired when all animations have returned,
|
|
* and is passed a finished arg that is true if all animations finished
|
|
* completely.
|
|
* @param {func} onFailure Not supported yet.
|
|
*/
|
|
startAnimations: function(
|
|
animations: Array<Object>,
|
|
onSuccess: (finished: boolean) => void,
|
|
onFailure: () => void
|
|
) {
|
|
var numReturned = 0;
|
|
var numFinished = 0;
|
|
var numAnimations = animations.length;
|
|
var metaCallback = (finished) => {
|
|
if (finished) {
|
|
++numFinished;
|
|
}
|
|
if (++numReturned === numAnimations) {
|
|
onSuccess && onSuccess(numFinished === numAnimations);
|
|
}
|
|
};
|
|
animations.forEach((anim) => {
|
|
warning(
|
|
anim.ref != null || anim.nodeHandle != null &&
|
|
!anim.ref !== !anim.nodeHandle,
|
|
'Animations must be specified with either ref xor nodeHandle'
|
|
);
|
|
if (anim.ref) {
|
|
this.startAnimation(anim.ref, anim.anim, metaCallback);
|
|
} else if (anim.nodeHandle) {
|
|
this.startAnimationWithNodeHandle(anim.nodeHandle, anim.anim, metaCallback);
|
|
}
|
|
});
|
|
},
|
|
|
|
/**
|
|
* Stop any and all animations operating on the View with native node handle
|
|
* `nodeHandle`.
|
|
*
|
|
* @param {NodeHandle} component The instance to stop animations
|
|
* on. Do not pass a composite component.
|
|
*/
|
|
stopNodeHandleAnimations: function(nodeHandle: any) {
|
|
if (!this.state._currentAnimationsByNodeHandle[nodeHandle]) {
|
|
return;
|
|
}
|
|
var anims = this.state._currentAnimationsByNodeHandle[nodeHandle];
|
|
for (var i = 0; i < anims.length; i++) {
|
|
var anim = anims[i];
|
|
if (anim) {
|
|
// Note: Converting the string key to a number `nodeHandle`.
|
|
POPAnimation.removeAnimation(+nodeHandle, anim);
|
|
}
|
|
}
|
|
this.state._currentAnimationsByNodeHandle[nodeHandle] = undefined;
|
|
},
|
|
|
|
/**
|
|
* Stop any and all animations operating on the View with ref `refKey`.
|
|
*
|
|
* @param {key} refKey The key to reference the View to be animated.
|
|
*/
|
|
stopAnimations: function(refKey: string) {
|
|
invariant(this.refs[refKey], 'invalid ref');
|
|
this.stopNodeHandleAnimations(this.refs[refKey].getNodeHandle());
|
|
},
|
|
|
|
/**
|
|
* Stop any and all animations created by this component on itself and
|
|
* subviews.
|
|
*/
|
|
stopAllAnimations: function() {
|
|
for (var nodeHandle in this.state._currentAnimationsByNodeHandle) {
|
|
this.stopNodeHandleAnimations(nodeHandle);
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Animates size and position of a view referenced by `refKey` to a specific
|
|
* frame.
|
|
*
|
|
* @param {key} refKey ref key for view to animate.
|
|
* @param {Object} frame The frame to animate the view to, specified as {left,
|
|
* top, width, height}.
|
|
* @param {const} type What type of interpolation to use, selected from
|
|
* `inperpolationTypes`.
|
|
* @param {Object} event Event encapsulating synthetic and native data that
|
|
* may have triggered this animation. Velocity is extracted from it if
|
|
* possible and applied to the animation.
|
|
* @param {func} doneCallback A callback fired when the animation is done, and
|
|
* is passed a `finished` param that indicates whether the animation
|
|
* completely finished, or was interrupted.
|
|
*/
|
|
animateToFrame: function(
|
|
refKey: string,
|
|
frame: {left: number; top: number; width: number; height: number;},
|
|
type: number,
|
|
velocity: number,
|
|
doneCallback: (finished: boolean) => void
|
|
) {
|
|
var animFrame = { // Animations use a centered coordinate system.
|
|
x: frame.left + frame.width / 2,
|
|
y: frame.top + frame.height / 2,
|
|
w: frame.width,
|
|
h: frame.height
|
|
};
|
|
var posAnim = POPAnimation.createAnimation(type, {
|
|
property: POPAnimation.Properties.position,
|
|
toValue: [animFrame.x, animFrame.y],
|
|
velocity: velocity || [0, 0],
|
|
});
|
|
var sizeAnim = POPAnimation.createAnimation(type, {
|
|
property: POPAnimation.Properties.size,
|
|
toValue: [animFrame.w, animFrame.h]
|
|
});
|
|
this.startAnimation(refKey, posAnim, doneCallback);
|
|
this.startAnimation(refKey, sizeAnim);
|
|
},
|
|
|
|
// Cleanup any potentially leaked animations.
|
|
componentWillUnmount: function() {
|
|
this.stopAllAnimations();
|
|
}
|
|
};
|
|
|
|
module.exports = POPAnimationMixin;
|
|
|
|
}
|