Conforms to NSObject
Declared in RCTBridgeModule.h

Overview

Provides the interface needed to register a bridge module.

Tasks

  •   bridge

    A reference to the RCTBridge. Useful for modules that require access to bridge features, such as sending events or making JS calls. This will be set automatically by the bridge when it initializes the module. To implement this in your module, just add @synthesize bridge = _bridge;

    property
  •   methodQueue

    The queue that will be used to call all exported methods. If omitted, this will call on a default background queue, which is avoids blocking the main thread.

    property
  • + moduleName

    Place this macro in your class implementation to automatically register your module with the bridge when it loads. The optional js_name argument will be used as the JS module name. If omitted, the JS module name will match the Objective-C class name.

  • + load
  • – method

    Similar to RCT_EXPORT_METHOD but lets you set the JS name of the exported method. Example usage:

  • – constantsToExport

    Injects constants into JS. These constants are made accessible via NativeModules.ModuleName.X. This method is called when the module is registered by the bridge. It is only called once for the lifetime of the bridge, so it is not suitable for returning dynamic values, but may be used for long-lived values such as session keys, that are regenerated only as part of a reload of the entire React application.

  • – batchDidComplete

    Notifies the module that a batch of JS method invocations has just completed.

Properties

bridge

@property (nonatomic, weak) RCTBridge *bridge
Discussion

A reference to the RCTBridge. Useful for modules that require access to bridge features, such as sending events or making JS calls. This will be set automatically by the bridge when it initializes the module. To implement this in your module, just add @synthesize bridge = _bridge;

Declared In

RCTBridgeModule.h

methodQueue

@property (nonatomic, strong, readonly) dispatch_queue_t methodQueue
Discussion

The queue that will be used to call all exported methods. If omitted, this will call on a default background queue, which is avoids blocking the main thread.

If the methods in your module need to interact with UIKit methods, they will probably need to call those on the main thread, as most of UIKit is main- thread-only. You can tell React Native to call your module methods on the main thread by returning a reference to the main queue, like this:

  • (dispatch_queue_t)methodQueue { return dispatch_get_main_queue(); }

If you don’t want to specify the queue yourself, but you need to use it inside your class (e.g. if you have internal methods that need to disaptch onto that queue), you can just add @synthesize methodQueue = _methodQueue; and the bridge will populate the methodQueue property for you automatically when it initializes the module.

Declared In

RCTBridgeModule.h

Class Methods

load

+ (void)load

moduleName

+ (NSString *)moduleName
Discussion

Place this macro in your class implementation to automatically register your module with the bridge when it loads. The optional js_name argument will be used as the JS module name. If omitted, the JS module name will match the Objective-C class name.

Declared In

RCTBridgeModule.h

Instance Methods

batchDidComplete

- (void)batchDidComplete
Discussion

Notifies the module that a batch of JS method invocations has just completed.

Declared In

RCTBridgeModule.h

constantsToExport

- (NSDictionary *)constantsToExport
Discussion

Injects constants into JS. These constants are made accessible via NativeModules.ModuleName.X. This method is called when the module is registered by the bridge. It is only called once for the lifetime of the bridge, so it is not suitable for returning dynamic values, but may be used for long-lived values such as session keys, that are regenerated only as part of a reload of the entire React application.

Declared In

RCTBridgeModule.h

method

- (void)method
Discussion

Similar to RCT_EXPORT_METHOD but lets you set the JS name of the exported method. Example usage:

RCT_REMAP_METHOD(executeQueryWithParameters, executeQuery:(NSString )query parameters:(NSDictionary )parameters) { … }

Declared In

RCTBridgeModule.h