From 1fa55c23ce2371cc9b65659f6fb61c32aa91a114 Mon Sep 17 00:00:00 2001 From: Spencer Ahrens Date: Mon, 20 Apr 2015 17:51:57 -0700 Subject: [PATCH] Update custom iOS component section to use requireNativeComponent --- README.md | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index bcbb21154..684795417 100644 --- a/README.md +++ b/README.md @@ -165,7 +165,7 @@ var Message = React.createClass({ }); ``` -Custom iOS views can be exposed by subclassing `RCTViewManager`, implementing a `-view` method, and exporting properties with the `RCT_EXPORT_VIEW_PROPERTY` macro. Then a simple JavaScript file connects the dots. +Custom iOS views can be exposed by subclassing `RCTViewManager`, implementing a `-view` method, and exporting properties with the `RCT_EXPORT_VIEW_PROPERTY` macro. Then use `requireNativeComponent` in JavaScript to use the component in your app. ```objc // Objective-C @@ -190,10 +190,20 @@ RCT_EXPORT_VIEW_PROPERTY(myCustomProperty, NSString); ```javascript // JavaScript -var MyCustomView = createReactIOSNativeComponentClass({ - validAttributes: { myCustomProperty: true }, - uiViewClassName: 'MyCustomView', -}); +var React = require('react-native'); +var { requireNativeComponent } = React; + +class MyCustomView extends React.Component { + render() { + return ; + } +} +MyCustomView.propTypes = { + myCustomProperty: React.PropTypes.oneOf(['a', 'b']), +}; + +var NativeMyCustomView = requireNativeComponent('MyCustomView', MyCustomView); +module.exports = MyCustomView; ``` ## Running the Examples