Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/screen-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,20 @@ this.props.navigator.toggleNavBar({
## setOnNavigatorEvent(callback)

Set a handler for navigator events (like nav button press). This would normally go in your component constructor.
Can not be used in conjuction with `addOnNavigatorEvent`.

```js
// this.onNavigatorEvent will be our handler
this.props.navigator.setOnNavigatorEvent(this.onNavigatorEvent.bind(this));
```

## addOnNavigatorEvent(callback)

Add a handler for navigator events (like nav button press). This would normally go in your component constructor.
If you choose to use `addOnNavigatorEvent` instead of `setOnNavigatorEvent` you will be able to add multiple handlers.
Bear in mind that you can't use both `addOnNavigatorEvent` and `setOnNavigatorEvent`.
`addOnNavigatorEvent` returns a function, that once called will remove the registered handler.

# Screen Visibility

`const isVisible = await this.props.navigator.screenIsCurrentlyVisible()`
Expand Down
9 changes: 6 additions & 3 deletions src/Screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,23 @@ class Navigator {

setOnNavigatorEvent(callback) {
if (this.navigatorEventHandlers.length > 0) {
throw 'setOnNavigatorEvent can not be used after addOnNavigatorEvent has been called';
throw new Error('setOnNavigatorEvent can not be used after addOnNavigatorEvent has been called');
}
this.navigatorEventHandler = callback;
this._registerNavigatorEvent();
}

addOnNavigatorEvent(callback) {
if (this.navigatorEventHandler) {
throw 'addOnNavigatorEvent can not be used after setOnNavigatorEvent has been called';
throw new Error('addOnNavigatorEvent can not be used after setOnNavigatorEvent has been called');
}
if (this.navigatorEventHandlers.indexOf(callback) === -1) {
this.navigatorEventHandlers.push(callback);
}
this._registerNavigatorEvent();

return () => this._removeOnNavigatorEvent(callback)

}

_registerNavigatorEvent() {
Expand All @@ -167,7 +170,7 @@ class Navigator {
}
}

removeOnNavigatorEvent(callback) {
_removeOnNavigatorEvent(callback) {
const index = this.navigatorEventHandlers.indexOf(callback);
if (index !== -1) {
this.navigatorEventHandlers.splice(index, 1);
Expand Down