Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle new APP_DATA event type #25

Merged
merged 2 commits into from
Apr 7, 2020
Merged
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
28 changes: 27 additions & 1 deletion src/components/navigation-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ import AppNavigator from './app-navigator';

/**
* @typedef {Object} NavigationEvent
* @property {('BUTTON_CLICK' | 'DID_FOCUS' | 'DID_BLUR')} eventType - The type of the event.
* @property {('BUTTON_CLICK' | 'DID_FOCUS' | 'DID_BLUR' | 'APP_DATA')} eventType - The type of the event.
* @property {string} viewId - The UUID for the view on which the event was fired.
* @property {?string} jsonPayload - The payload for the event as stringified JSON.
*/
Expand Down Expand Up @@ -189,6 +189,9 @@ class Component extends React.Component {
case 'DID_BLUR':
this.constructor._handleBlurEvent.bind(this)(payload);
break;
case 'APP_DATA':
this.constructor._handleAppDataEvent.bind(this)(payload);
break;
default:
console.warn('Received invalid event: ', event);
break;
Expand Down Expand Up @@ -244,6 +247,21 @@ class Component extends React.Component {
}
}

/**
* Make a call to <code>onAppData()</code> (if available) whenever this view receives data.
*
* If a subclassed instance contains the <code>onAppData</code> method, it will be
* called on appData events.
*
* @private
* @param {string} payload - The stringified JSON payload for the event.
*/
static _handleAppDataEvent(payload) {
if (this.onAppData) {
this.onAppData.bind(this)(payload);
}
}

/**
* Get the navigation bar for the given route.
*
Expand Down Expand Up @@ -302,6 +320,14 @@ class Component extends React.Component {
*/
static onBlur() {}

/**
* Handle appData events.
*
* @abstract
* @static
*/
static onAppData() {}

/**
* Reset the navigation bar for the current screen to its defaults.
*
Expand Down