mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-26 05:15:49 +08:00
supports event capturing and bubbling phases in Navigation context.
Summary: Adds the API that enables the navigation events capturing and bubbling which is the feature that is enabled if the nested navigation contexts is created by the navigator. This would allow developer to observe or reconcile navigation events within the navigation tree. public ./Libraries/FBReactKit/jest Reviewed By: zjj010104 Differential Revision: D2546451 fb-gh-sync-id: dfc9d16defaa563b9e80fd751a20570f6e524b74
This commit is contained in:
committed by
facebook-github-bot-9
parent
1076f4a172
commit
73b80773ba
@@ -30,14 +30,15 @@
|
||||
var EventEmitter = require('EventEmitter');
|
||||
var NavigationEvent = require('NavigationEvent');
|
||||
|
||||
type EventParams = {
|
||||
data: any;
|
||||
didEmitCallback: ?Function;
|
||||
eventType: string;
|
||||
type ExtraInfo = {
|
||||
defaultPrevented: ?boolean,
|
||||
eventPhase: ?number,
|
||||
propagationStopped: ?boolean,
|
||||
target: ?Object,
|
||||
};
|
||||
|
||||
class NavigationEventEmitter extends EventEmitter {
|
||||
_emitQueue: Array<EventParams>;
|
||||
_emitQueue: Array<any>;
|
||||
_emitting: boolean;
|
||||
_target: Object;
|
||||
|
||||
@@ -51,18 +52,38 @@ class NavigationEventEmitter extends EventEmitter {
|
||||
emit(
|
||||
eventType: string,
|
||||
data: any,
|
||||
didEmitCallback: ?Function
|
||||
didEmitCallback: ?Function,
|
||||
extraInfo: ?ExtraInfo
|
||||
): void {
|
||||
if (this._emitting) {
|
||||
// An event cycle that was previously created hasn't finished yet.
|
||||
// Put this event cycle into the queue and will finish them later.
|
||||
this._emitQueue.push({eventType, data, didEmitCallback});
|
||||
var args: any = Array.prototype.slice.call(arguments);
|
||||
this._emitQueue.unshift(args);
|
||||
return;
|
||||
}
|
||||
|
||||
this._emitting = true;
|
||||
|
||||
var event = new NavigationEvent(eventType, this._target, data);
|
||||
var event = NavigationEvent.pool(eventType, this._target, data);
|
||||
|
||||
if (extraInfo) {
|
||||
if (extraInfo.target) {
|
||||
event.target = extraInfo.target;
|
||||
}
|
||||
|
||||
if (extraInfo.eventPhase) {
|
||||
event.eventPhase = extraInfo.eventPhase;
|
||||
}
|
||||
|
||||
if (extraInfo.defaultPrevented) {
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
if (extraInfo.propagationStopped) {
|
||||
event.stopPropagation();
|
||||
}
|
||||
}
|
||||
|
||||
// EventEmitter#emit only takes `eventType` as `String`. Casting `eventType`
|
||||
// to `String` to make @flow happy.
|
||||
@@ -76,8 +97,8 @@ class NavigationEventEmitter extends EventEmitter {
|
||||
this._emitting = false;
|
||||
|
||||
while (this._emitQueue.length) {
|
||||
var arg = this._emitQueue.shift();
|
||||
this.emit(arg.eventType, arg.data, arg.didEmitCallback);
|
||||
var args: any = this._emitQueue.shift();
|
||||
this.emit.apply(this, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user