npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-native-event-bridge-x

v0.7.0

Published

Send and Receive events between React Native and native.

Downloads

1

Readme

react-native-event-bridge

Send and Receive events between React Native and native.

DISCLAIMER

This project is currently in beta.

Core APIs are subject to change. We encourage people to try this library out and provide us feedback as we get it to a stable state.

Getting started

$ npm install react-native-event-bridge --save

Mostly automatic installation

$ react-native link react-native-event-bridge

Manual installation

iOS

  1. In Xcode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modulesreact-native-event-bridge and add MSREventBridge.xcodeproj
  3. In Xcode, in the project navigator, select your project. Add libMSREventBridge.a to your project's Build PhasesLink Binary With Libraries
  4. Run your project (Cmd+R)<

Android

  1. Open up android/app/src/main/java/[...]/MainActivity.java
  • Add import net.mischneider.MSREventBridgePackage; to the imports at the top of the file
  • Add new MSREventBridgePackage() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:
    include ':react-native-event-bridge'
    project(':react-native-event-bridge').projectDir = new File(rootProject.projectDir, 	'../node_modules/react-native-event-bridge/android')
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
      compile project(':react-native-event-bridge')

Usage

For different usage examples look into the example and example-swift folder.

Emit events from React Native

JavaScript

import EventBridge from 'react-native-event-bridge';

// Emit an event from within a React component
EventBridge.emitEvent(this, 'PresentScreen');

// Emit an event with callback from within a React component
EventBridge.emitEventCallback(this, 'EventWithCallback', () => {
  Alert.alert("Callback Response", "Some Callback Response");
});

Handle events from native

iOS:

// Receiver needs to conform to the MSREventBridgeEventReceiver protocol
@interface ViewController () <MSREventBridgeEventReceiver>
// ...
@end

// Implement the following two methods by receiver that conforms to MSREventBridgeEventReceiver

// Handle events
- (void)onEventWithName:(NSString *)eventName info:(nullable NSDictionary *)info
{
  // Handle events dispatched from React Native
  RCTLog(@"%@ - Received event: '%@', with info: %@", self.UUID.UUIDString, eventName, info);

  // Example for PresentScreen event
  if ([eventName isEqualToString:PresentScreenEvent] ) {
    ViewController *newViewController = [ViewController new];
    [self presentViewController:newViewController animated:YES completion:nil];
    return;
  }
  // ...
}

// Handle events with callback
- (void)onEventWithName:(NSString *)eventName info:(nullable NSDictionary *)info callback:(MSREventBridgeReventReceiverCallback)callback;
{
  // ...
}

Android:

@Override
public void onEvent(final String name, final ReadableMap info) {
    Log.d(ReactConstants.TAG, this.getClass().getName() + ": Received event: ".concat(name));

    // Example to just present a new activity
    if (name.equals(PresentScreenEventName)) {
        Intent myIntent = new Intent(getBaseContext(), SecondActivity.class);
        startActivity(myIntent);
        return;
    }
    // ...
}

Subscribe to events in React Native

JavaScript

// Import EventBridge from the react-native-event-bridge native module
import EventBridge from 'react-native-event-bridge';

// Event listener need to define a rootTag contextType
static contextTypes = {
  rootTag: React.PropTypes.number,
};

// Add and remove as event listener
componentDidMount() {
  // Register for any kind of event that will be sent from the native side
  this._eventSubscription = EventBridge.addEventListener(this, (name, info) => {
    console.log("Received event from native: '" + name + "' with info: " + JSON.stringify(info));
  });
}

componentWillUnmount() {
  this._eventSubscription && this._eventSubscription.remove();
}

Sending events from native

iOS

//...
// Get the RCTBridge
RCTBridge *bridge = ...;

// Send an event with name 'eventName' to listeners for this event within the React Native component hierarchy
// of that is managed by this view
[bridge.viewControllerEventEmitter emitEventForView:self.view name:@"eventName" info:@{
  @"rowSelected" : info[@"rowID"]
}];
/...

Android

// Get the MSREventBridgeInstanceManagerProvider somehow
MSREventBridgeInstanceManagerProvider instanceManagerProvider =
        (MSREventBridgeInstanceManagerProvider)this.getApplicationContext();

// Emit event via MSREventBridgeModule
String rowID = ...;
WritableMap map = new WritableNativeMap();
map.putString("rowSelected", rowID);
MSREventBridgeModule.emitEventForActivity(this, instanceManagerProvider, "eventName", map);

Example fetching data

JavaScript

// Fetch some data
this.setState({
  isLoading: true
})

// Load some data and update the data source
EventBridge.emitEventInfoCallback(this, 'LoadData', {'count' : 10}, (error, result) => {
  this.setState({
    isLoading: false,
    dataSource: this.state.dataSource.cloneWithRows(result),
  });
});

iOS

- (void)onEventWithName:(NSString *)eventName info:(nullable NSDictionary *)info callback:(MSREventBridgeReventReceiverCallback)callback
{
  RCTLog(@"%@ - Received event that expects callback: '%@', with info: %@", self.UUID.UUIDString, eventName, info);

  // Example for LoadData event
  if ([eventName isEqualToString:LoadDataEvent]) {

    // Get the count parameter from the LoadDataEvent
    NSNumber *count = info[LoadDataEventCountParameterKey];

    // Simulate some data fetching
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
      NSMutableArray *responseData = [NSMutableArray array];
      for (int i = 0; i < count.integerValue; i++) {
        [responseData addObject:[NSString stringWithFormat:@"row %i", i]];
      }

      // Call callback with some error as first parameter if so and second with response data
      if (callback) {
        callback(nil, responseData);
      }

    });
    return;
  }
  // ...
}

Android

@Override
public void onEventCallback(final String name, final ReadableMap info, final MSREventBridgeReceiverCallback callback) {
    Log.d(ReactConstants.TAG, this.getClass().getName() + ": Received event with callback: ".concat(name));

    final String activityClassName = this.getClass().getSimpleName();

    // Example how to load some async data
    if (name.equals(LoadDataEventName)) {
        final int count = info.getInt("count");

        // Simulate some data loading delay
        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                WritableArray array = new WritableNativeArray();
                for (int i = 0; i < count; i++) {
                    array.pushString("Row " + i + " - " + activityClassName);
                }

                callback.onSuccess(array);
            }
        }, 2000);

        return;
    }
    //...
}

Development / Example

  1. In one terminal session, run $ cd example && npm run-script sync-rneb. This will make changes that you make to the module available to the example app, in a way that will trigger the Example app’s ‘packager’ to reload those files.
  2. In another terminal session, run $ cd example && react-native run-ios. This will start the ‘packager’ for the example app, which serves the processed JS source to the Example app.

TODO:

  • API refinements
  • Improve general documentation
  • Improve documentation around "enhanced" features

License

Copyright 2017 Michael Schneider

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.