diff --git a/docs/nativemodulesios.html b/docs/nativemodulesios.html index 62e32a00c8d..8a5ae1b568a 100644 --- a/docs/nativemodulesios.html +++ b/docs/nativemodulesios.html @@ -48,21 +48,12 @@ CalendarManager.}

The same way if the operation can take a long time to complete, the native module should not block. It is a good idea to use dispatch_async to schedule expensive work on background queue.

Exporting constants #

Native module can export constants that are instantly available to JavaScript at runtime. This is useful to export some initial data that would otherwise require a bridge round-trip.

- (NSDictionary *)constantsToExport { return @{ @"firstDayOfTheWeek": @"Monday" }; -}

JavaScript can use this value right away:

console.log(CalendarManager.firstDayOfTheWeek);

Note that the constants are exported only at initialization time, so if you change constantsToExport value at runtime it won't affect JavaScript environment.

Sending events to JavaScript #

The native module can signal events to JavaScript without being invoked directly. The easiest way to do this is to use eventDispatcher:

#import "RCTBridge.h" -#import "RCTEventDispatcher.h" - -@implementation CalendarManager - -@synthesize bridge = _bridge; - -- (void)calendarEventReminderReceived:(NSNotification *)notification +}

JavaScript can use this value right away:

console.log(CalendarManager.firstDayOfTheWeek);

Note that the constants are exported only at initialization time, so if you change constantsToExport value at runtime it won't affect JavaScript environment.

Sending events to JavaScript #

The native module can signal events to JavaScript without being invoked directly. The easiest way to do this is to use eventDispatcher:

- (void)calendarEventReminderReceived:(NSNotification *)notification { NSString *eventName = notification.userInfo[@"name"]; [self.bridge.eventDispatcher sendAppEventWithName:@"EventReminder" body:@{@"name": eventName}]; -} - -@end

JavaScript code can subscribe to these events:

var subscription = DeviceEventEmitter.addListener( +}

JavaScript code can subscribe to these events:

var subscription = DeviceEventEmitter.addListener( 'EventReminder', (reminder) => console.log(reminder.name) );