diff --git a/docs/nativemodulesios.html b/docs/nativemodulesios.html index 7aea9317c50..a0d7aa1e599 100644 --- a/docs/nativemodulesios.html +++ b/docs/nativemodulesios.html @@ -25,7 +25,7 @@ CalendarManager.: '4 Privet Drive, Surrey', time: date.toTime(), description: '...' -})

NOTE about array and map - React Native doesn't provide any guarantees about the types of values in these structures. Your native module might expect array of strings, but if JavaScript calls your method with an array that contains number and string you'll get NSArray with NSNumber and NSString. It's developer's responsibility to check array/map values types (see RCTConvert for helper methods).

Callbacks #

WARNING: This section is even more experimental than others, we don't have a set of best practices around callbacks yet.

Native module also supports a special kind of argument - callback. In most cases it is used to provide function call result to JavaScript.

- (void)findEvents:(RCTResponseSenderBlock)callback +})

NOTE: About array and map

React Native doesn't provide any guarantees about the types of values in these structures. Your native module might expect array of strings, but if JavaScript calls your method with an array that contains number and string you'll get NSArray with NSNumber and NSString. It's developer's responsibility to check array/map values types (see RCTConvert for helper methods).

Callbacks #

WARNING

This section is even more experimental than others, we don't have a set of best practices around callbacks yet.

Native module also supports a special kind of argument - callback. In most cases it is used to provide function call result to JavaScript.

- (void)findEvents:(RCTResponseSenderBlock)callback { RCT_EXPORT(); NSArray *events = ... @@ -36,7 +36,7 @@ CalendarManager.} else { this.setState({events: events}); } -})

Native module is supposed to invoke callback only once. It can, however, store the callback as an ivar and invoke it later. This pattern is often used to wrap iOS APIs that require delegate. See RCTAlertManager.

If you want to pass error-like object to JavaScript, use RCTMakeError from RCTUtils.h.

Implementing native module #

The native module should not have any assumptions about what thread it is being called on. React Native invokes native modules methods on a separate serial GCD queue, but this is an implementation detail and might change. If the native module needs to call main-thread-only iOS API, it should schedule the operation on the main queue:

- (void)addEventWithName:(NSString *)name callback:(RCTResponseSenderBlock)callback +})

Native module is supposed to invoke callback only once. It can, however, store the callback as an ivar and invoke it later. This pattern is often used to wrap iOS APIs that require delegate. See RCTAlertManager.

If you want to pass error-like object to JavaScript, use RCTMakeError from RCTUtils.h.

Implementing native module #

The native module should not have any assumptions about what thread it is being called on. React Native invokes native modules methods on a separate serial GCD queue, but this is an implementation detail and might change. If the native module needs to call main-thread-only iOS API, it should schedule the operation on the main queue:

- (void)addEventWithName:(NSString *)name callback:(RCTResponseSenderBlock)callback { RCT_EXPORT(addEvent); dispatch_async(dispatch_get_main_queue(), ^{ @@ -59,7 +59,7 @@ CalendarManager.); ... // Don't forget to unsubscribe -subscription.remove();

For more examples of sending events to JavaScript, see RCTLocationObserver.

Next →