From b1f574a6454aaac07439dfdaa94e79a3da26093c Mon Sep 17 00:00:00 2001 From: Website Deployment Script Date: Mon, 1 May 2017 13:31:30 +0000 Subject: [PATCH] Updated docs for next --- releases/next/docs/native-components-ios.html | 2 +- releases/next/docs/native-modules-ios.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/releases/next/docs/native-components-ios.html b/releases/next/docs/native-components-ios.html index 473bea98725..9949b218e6c 100644 --- a/releases/next/docs/native-components-ios.html +++ b/releases/next/docs/native-components-ios.html @@ -189,7 +189,7 @@ MapView.propTypes }

You can see we're adding an event handler property to the view by subclassing MKMapView. Then we're exposing the onChange event handler property and setting the manager as the delegate for every view that it vends. Finally, in the delegate method -mapView:regionDidChangeAnimated: the event handler block is called on the corresponding view with the region data. Calling the onChange event handler block results in calling the same callback prop in JavaScript. This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

// MapView.js class MapView extends React.Component { - constructor() { + constructor(props) { super(props) this._onChange = this._onChange.bind(this); } diff --git a/releases/next/docs/native-modules-ios.html b/releases/next/docs/native-modules-ios.html index 7dee9019fc9..d23a9b4ada1 100644 --- a/releases/next/docs/native-modules-ios.html +++ b/releases/next/docs/native-modules-ios.html @@ -32,7 +32,7 @@ CalendarManager.}

But by using the automatic type conversion feature, we can skip the manual conversion step completely, and just write:

RCT_EXPORT_METHOD(addEvent:(NSString *)name location:(NSString *)location date:(NSDate *)date) { // Date is ready to use! -}

You would then call this from JavaScript by using either:

CalendarManager.addEvent('Birthday Party', '4 Privet Drive, Surrey', date.getTime()); // passing date as number of seconds since Unix epoch

or

CalendarManager.addEvent('Birthday Party', '4 Privet Drive, Surrey', date.toISOString()); // passing date as ISO-8601 string

And both values would get converted correctly to the native NSDate. A bad value, like an Array, would generate a helpful "RedBox" error message.

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:

#import <React/RCTConvert.h> +}

You would then call this from JavaScript by using either:

CalendarManager.addEvent('Birthday Party', '4 Privet Drive, Surrey', date.getTime()); // passing date as number of milliseconds since Unix epoch

or

CalendarManager.addEvent('Birthday Party', '4 Privet Drive, Surrey', date.toISOString()); // passing date as ISO-8601 string

And both values would get converted correctly to the native NSDate. A bad value, like an Array, would generate a helpful "RedBox" error message.

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:

#import <React/RCTConvert.h> RCT_EXPORT_METHOD(addEvent:(NSString *)name details:(NSDictionary *)details) {