Skip to content

Commit ffcdf21

Browse files
author
Brent Vatne
committed
[Docs] Clarify the variables provided to RCT_CUSTOM_VIEW_PROPERTY body
1 parent 571aa55 commit ffcdf21

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

docs/NativeComponentsIOS.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ This is now a fully-functioning native map view component in JavaScript, complet
5858

5959
## Properties
6060

61-
The first thing we can do to make this component more usable is to bridge over some native properties. Let's say we want to be able to disable pitch control and specify the visible region. Disabling pitch is a simple boolean, so we just add this one line:
61+
The first thing we can do to make this component more usable is to bridge over some native properties. Let's say we want to be able to disable pitch control and specify the visible region. Disabling pitch is a simple boolean, so we add this one line:
6262

6363
```objective-c
6464
// RCTMapManager.m
@@ -67,7 +67,7 @@ RCT_EXPORT_VIEW_PROPERTY(pitchEnabled, BOOL)
6767
6868
Note that we explicitly specify the type as `BOOL` - React Native uses `RCTConvert` under the hood to convert all sorts of different data types when talking over the bridge, and bad values will show convenient "RedBox" errors to let you know there is an issue ASAP. When things are straightforward like this, the whole implementation is taken care of for you by this macro.
6969
70-
Now to actually disable pitch, we just set the property in JS:
70+
Now to actually disable pitch, we set the property in JS:
7171
7272
```javascript
7373
// MyApp.js
@@ -115,9 +115,9 @@ RCT_CUSTOM_VIEW_PROPERTY(region, MKCoordinateRegion, RCTMap)
115115
}
116116
```
117117
118-
Ok, this is clearly more complicated than the simple `BOOL` case we had before. Now we have a `MKCoordinateRegion` type that needs a conversion function, and we have custom code so that the view will animate when we set the region from JS. There is also a `defaultView` that we use to reset the property back to the default value if JS sends us a null sentinel.
118+
Ok, this is more complicated than the simple `BOOL` case we had before. Now we have a `MKCoordinateRegion` type that needs a conversion function, and we have custom code so that the view will animate when we set the region from JS. Within the function body that we provide, `json` refers to the raw value that has been passed from JS. There is also a `view` variable which gives us access to the manager's view instance, and a `defaultView` that we use to reset the property back to the default value if JS sends us a null sentinel.
119119
120-
You could of course write any conversion function you want for your view - here is the implementation for `MKCoordinateRegion` via two categories on `RCTConvert`:
120+
You could write any conversion function you want for your view - here is the implementation for `MKCoordinateRegion` via two categories on `RCTConvert`:
121121
122122
```objective-c
123123
@implementation RCTConvert(CoreLocation)

0 commit comments

Comments
 (0)