update website

This commit is contained in:
Travis CI
2015-07-22 04:00:56 +00:00
parent aa05040a32
commit ed23174d11
+18 -1
View File
@@ -58,7 +58,24 @@ CalendarManager<span class="token punctuation">.</span><span class="token functi
<span class="token punctuation">}</span></div><blockquote><p><strong>NOTE</strong>: Sharing dispatch queues between modules</p><p>The <code>methodQueue</code> method will be called once when the module is initialized, and then retained by the bridge, so there is no need to retain the queue yourself, unless you wish to make use of it within your module. However, if you wish to share the same queue between multiple modules then you will need to ensure that you retain and return the same queue instance for each of them; merely returning a queue of the same name for each won&#x27;t work.</p></blockquote><h2><a class="anchor" name="exporting-constants"></a>Exporting Constants <a class="hash-link" href="#exporting-constants">#</a></h2><p>A native module can export constants that are immediately available to JavaScript at runtime. This is useful for communicating static data that would otherwise require a round-trip through the bridge.</p><div class="prism language-javascript"><span class="token operator">-</span> <span class="token punctuation">(</span>NSDictionary <span class="token operator">*</span><span class="token punctuation">)</span>constantsToExport
<span class="token punctuation">{</span>
<span class="token keyword">return</span> @<span class="token punctuation">{</span> @<span class="token string">&quot;firstDayOfTheWeek&quot;</span><span class="token punctuation">:</span> @<span class="token string">&quot;Monday&quot;</span> <span class="token punctuation">}</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></div><p>JavaScript can use this value right away, synchronously:</p><div class="prism language-javascript">console<span class="token punctuation">.</span><span class="token function">log<span class="token punctuation">(</span></span>CalendarManager<span class="token punctuation">.</span>firstDayOfTheWeek<span class="token punctuation">)</span><span class="token punctuation">;</span></div><p>Note that the constants are exported only at initialization time, so if you change <code>constantsToExport</code> values at runtime it won&#x27;t affect the JavaScript environment.</p><h2><a class="anchor" name="sending-events-to-javascript"></a>Sending Events to JavaScript <a class="hash-link" href="#sending-events-to-javascript">#</a></h2><p>The native module can signal events to JavaScript without being invoked directly. The easiest way to do this is to use <code>eventDispatcher</code>:</p><div class="prism language-javascript">#import <span class="token string">&quot;RCTBridge.h&quot;</span>
<span class="token punctuation">}</span></div><p>JavaScript can use this value right away, synchronously:</p><div class="prism language-javascript">console<span class="token punctuation">.</span><span class="token function">log<span class="token punctuation">(</span></span>CalendarManager<span class="token punctuation">.</span>firstDayOfTheWeek<span class="token punctuation">)</span><span class="token punctuation">;</span></div><p>Note that the constants are exported only at initialization time, so if you change <code>constantsToExport</code> values at runtime it won&#x27;t affect the JavaScript environment.</p><h3><a class="anchor" name="enum-constants"></a>Enum Constants <a class="hash-link" href="#enum-constants">#</a></h3><p>Enums that are defined via <code>NS_ENUM</code> cannot be used as method arguments without first extending RCTConvert.</p><p>In order to export the following <code>NS_ENUM</code> definition:</p><div class="prism language-javascript">typedef <span class="token function">NS_ENUM<span class="token punctuation">(</span></span>NSInteger<span class="token punctuation">,</span> UIStatusBarAnimation<span class="token punctuation">)</span> <span class="token punctuation">{</span>
UIStatusBarAnimationNone<span class="token punctuation">,</span>
UIStatusBarAnimationFade<span class="token punctuation">,</span>
UIStatusBarAnimationSlide<span class="token punctuation">,</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span></div><p>You must create a class extension of RCTConvert like so:</p><div class="prism language-javascript">@implementation RCTConvert <span class="token punctuation">(</span>StatusBarAnimation<span class="token punctuation">)</span>
<span class="token function">RCT_ENUM_CONVERTER<span class="token punctuation">(</span></span>UIStatusBarAnimation<span class="token punctuation">,</span> <span class="token punctuation">(</span>@<span class="token punctuation">{</span> @<span class="token string">&quot;statusBarAnimationNone&quot;</span> <span class="token punctuation">:</span> @<span class="token punctuation">(</span>UIStatusBarAnimationNone<span class="token punctuation">)</span><span class="token punctuation">,</span>
@<span class="token string">&quot;statusBarAnimationFade&quot;</span> <span class="token punctuation">:</span> @<span class="token punctuation">(</span>UIStatusBarAnimationFade<span class="token punctuation">)</span><span class="token punctuation">,</span>
@<span class="token string">&quot;statusBarAnimationSlide&quot;</span> <span class="token punctuation">:</span> @<span class="token punctuation">(</span>UIStatusBarAnimationSlide<span class="token punctuation">)</span><span class="token punctuation">,</span>
UIStatusBarAnimationNone<span class="token punctuation">,</span> integerValue<span class="token punctuation">)</span>
@end</div><p>You can then define methods and export your enum constants like this:</p><div class="prism language-javascript"><span class="token operator">-</span> <span class="token punctuation">(</span>NSDictionary <span class="token operator">*</span><span class="token punctuation">)</span>constantsToExport
<span class="token punctuation">{</span>
<span class="token keyword">return</span> @<span class="token punctuation">{</span> @<span class="token string">&quot;statusBarAnimationNone&quot;</span> <span class="token punctuation">:</span> @<span class="token punctuation">(</span>UIStatusBarAnimationNone<span class="token punctuation">)</span><span class="token punctuation">,</span>
@<span class="token string">&quot;statusBarAnimationFade&quot;</span> <span class="token punctuation">:</span> @<span class="token punctuation">(</span>UIStatusBarAnimationFade<span class="token punctuation">)</span><span class="token punctuation">,</span>
@<span class="token string">&quot;statusBarAnimationSlide&quot;</span> <span class="token punctuation">:</span> @<span class="token punctuation">(</span>UIStatusBarAnimationSlide<span class="token punctuation">)</span> <span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>
<span class="token function">RCT_EXPORT_METHOD<span class="token punctuation">(</span></span>updateStatusBarAnimation<span class="token punctuation">:</span><span class="token punctuation">(</span>UIStatusBarAnimation<span class="token punctuation">)</span>animation
completion<span class="token punctuation">:</span><span class="token punctuation">(</span>RCTResponseSenderBlock<span class="token punctuation">)</span>callback<span class="token punctuation">)</span></div><p>Your enum will then be automatically unwrapped using the selector provided (<code>integerValue</code> in the above example) before being passed to your exported method.</p><h2><a class="anchor" name="sending-events-to-javascript"></a>Sending Events to JavaScript <a class="hash-link" href="#sending-events-to-javascript">#</a></h2><p>The native module can signal events to JavaScript without being invoked directly. The easiest way to do this is to use <code>eventDispatcher</code>:</p><div class="prism language-javascript">#import <span class="token string">&quot;RCTBridge.h&quot;</span>
#import <span class="token string">&quot;RCTEventDispatcher.h&quot;</span>
@implementation CalendarManager