Skip to main content
The median-js-bridge NPM package allows you to register listener functions that respond to native events triggered within your app. These listeners function similarly to standard JavaScript callbacks but offer a more streamlined and reliable integration with native mobile features. Listeners are event-driven functions that execute when a native event is triggered. Even if an event occurs before the listener is registered, the event will be queued and delivered once the listener initializes, ensuring reliable event capture.

Listener implementation

Registering event listeners

Listeners are added using the .addListener() method available on specific plugin interfaces. Each listener returns a listenerId, which can be used later to remove the listener.

Example: App resumed event

Example: OneSignal push notification

Respond to push notifications sent via OneSignal. Related: Handling Notifications Taps

Example: Share into app

Handle data shared into your app using the share intent. Related: Share into app

Example: Device shake (haptics plugin)

Capture device shake gestures for enhanced interaction. Related: Haptics

Example: AppsFlyer conversion data

Receive install attribution and conversion data from AppsFlyer. Related: AppsFlyer

Removing event listeners

To stop listening for a specific event, use the .removeListener() method with the stored listenerId.

Best practices for listener management

  • Always store the listenerId if you intend to remove the listener later.
  • Register listeners early, ideally within a component’s useEffect or lifecycle hook.
  • Remove listeners on unmount to avoid memory leaks in Single-Page Applications (SPAs).
Last modified on November 7, 2026