diff --git a/docs/nativemodulesios.html b/docs/nativemodulesios.html index c371646f6d4..fd6c312ebaf 100644 --- a/docs/nativemodulesios.html +++ b/docs/nativemodulesios.html @@ -14,7 +14,8 @@ } @end
Now from your JavaScript file you can call the method like this:
The return type of bridge methods is always void. React Native bridge is asynchronous, so the only way to pass a result to JavaScript is by using callbacks or emitting events (see below).
React Native supports several types of arguments that can be passed from JavaScript code to native module:
NSString)NSInteger, float, double, CGFloat, NSNumber)BOOL, NSNumber)NSArray) of any types from this listNSDictionary) with string keys and values of any type from this listRCTResponseSenderBlock)In our CalendarManager example, if we want to pass event date to native, we have to convert it to a string or a number:
NOTE: JavaScript method names +The name of the method exported to JavaScript is the native method's name up to the first colon. React Native also defines a macro called
RCT_REMAP_METHODto specify the JavaScript method's name. This is useful when multiple native methods are the same up to the first colon and would have conflicting JavaScript names.
The return type of bridge methods is always void. React Native bridge is asynchronous, so the only way to pass a result to JavaScript is by using callbacks or emitting events (see below).
React Native supports several types of arguments that can be passed from JavaScript code to native module:
NSString)NSInteger, float, double, CGFloat, NSNumber)BOOL, NSNumber)NSArray) of any types from this listNSDictionary) with string keys and values of any type from this listRCTResponseSenderBlock)In our CalendarManager example, if we want to pass event date to native, we have to convert it to a string or a number:
As CalendarManager.addEvent method gets more and more complex, the number of arguments will grow. Some of them might be optional. In this case it's worth considering changing the API a little bit to accept a dictionary of event attributes, like this:
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 an array of strings, but if JavaScript calls your method with an array containing numbers and strings, you'll get
NSArraywithNSNumberandNSString. It is the developer's responsibility to check array/map value types (seeRCTConvertfor helper methods).
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- a callback. In most cases it is used to provide the function call result to JavaScript.
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 an array of strings, but if JavaScript calls your method with an array containing numbers and strings, you'll get
NSArraywithNSNumberandNSString. It is the developer's responsibility to check array/map value types (seeRCTConvertfor helper methods).
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- a callback. In most cases it is used to provide the function call result to JavaScript.