2015-03-25 02:34:12 +00:00
|
|
|
/**
|
2018-09-11 22:27:47 +00:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2017-03-08 08:51:23 +00:00
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2015-03-25 02:34:12 +00:00
|
|
|
*
|
2018-05-11 02:06:46 +00:00
|
|
|
* @format
|
2015-03-27 18:46:17 +00:00
|
|
|
* @flow
|
2015-03-25 02:34:12 +00:00
|
|
|
*/
|
2018-05-11 02:06:46 +00:00
|
|
|
|
2015-03-25 02:34:12 +00:00
|
|
|
'use strict';
|
|
|
|
|
2018-05-10 22:44:52 +00:00
|
|
|
const InteractionManager = require('InteractionManager');
|
2015-03-25 02:34:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This mixin provides safe versions of InteractionManager start/end methods
|
|
|
|
* that ensures `clearInteractionHandle` is always called
|
|
|
|
* once per start, even if the component is unmounted.
|
|
|
|
*/
|
2018-05-10 22:44:52 +00:00
|
|
|
const InteractionMixin = {
|
2015-03-25 02:34:12 +00:00
|
|
|
componentWillUnmount: function() {
|
|
|
|
while (this._interactionMixinHandles.length) {
|
|
|
|
InteractionManager.clearInteractionHandle(
|
2018-05-11 02:06:46 +00:00
|
|
|
this._interactionMixinHandles.pop(),
|
2015-03-25 02:34:12 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-03-27 18:46:17 +00:00
|
|
|
_interactionMixinHandles: ([]: Array<number>),
|
2015-03-25 02:34:12 +00:00
|
|
|
|
|
|
|
createInteractionHandle: function() {
|
2018-05-10 22:44:52 +00:00
|
|
|
const handle = InteractionManager.createInteractionHandle();
|
2015-03-25 02:34:12 +00:00
|
|
|
this._interactionMixinHandles.push(handle);
|
|
|
|
return handle;
|
|
|
|
},
|
|
|
|
|
2015-03-27 18:46:17 +00:00
|
|
|
clearInteractionHandle: function(clearHandle: number) {
|
2015-03-25 02:34:12 +00:00
|
|
|
InteractionManager.clearInteractionHandle(clearHandle);
|
|
|
|
this._interactionMixinHandles = this._interactionMixinHandles.filter(
|
2018-05-11 02:06:46 +00:00
|
|
|
handle => handle !== clearHandle,
|
2015-03-25 02:34:12 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Schedule work for after all interactions have completed.
|
|
|
|
*
|
|
|
|
* @param {function} callback
|
|
|
|
*/
|
2015-03-27 18:46:17 +00:00
|
|
|
runAfterInteractions: function(callback: Function) {
|
2015-03-25 02:34:12 +00:00
|
|
|
InteractionManager.runAfterInteractions(callback);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = InteractionMixin;
|