mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-29 04:35:36 +08:00
[Navigator]: Allow developer to observe the focus change events from the owner or the children
of the navigator component.
Summary:
Per offline discussion with @evv, we'd like to deprecate the `onDidFocus` and `onWillFocus`
API that makes it really hard for the descendent children of a navigator to observe its focus
change events.
@public
Since for now the descendent children do have access to the navigator via `this.props.navigator`,
this diff makes it easy to observe the focus change event by doing:
```
this.props.navigator.addListener('willfocus', this._onFocus);
```
The goal is to make the event system in navigator more useful and maintainable.
Test Plan:
Test Video: https://www.facebook.com/pxlcld/mrzS
1. jest: ./Libraries/FBReactKit/js/runTests.js NavigationEventEmitter
2. Load UI Explorer: <Navigator />, see console logs that shows the focus change events fires.
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2004-present Facebook. All Rights Reserved.
|
||||
*
|
||||
* @providesModule NavigationEvent
|
||||
* @flow
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
class NavigationEvent {
|
||||
type: String;
|
||||
target: Object;
|
||||
data: any;
|
||||
|
||||
constructor(type: String, target: Object, data: any) {
|
||||
this.type = type;
|
||||
this.target = target;
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = NavigationEvent;
|
||||
Reference in New Issue
Block a user