mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Updated docs for next
This commit is contained in:
@@ -77,7 +77,14 @@ CalendarManager<span class="token punctuation">.</span><span class="token functi
|
||||
<span class="token comment" spellcheck="true"> // You can invoke callback from any thread/queue
|
||||
</span> <span class="token function">callback<span class="token punctuation">(</span></span>@<span class="token punctuation">[</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||||
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||||
<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't work.</p></blockquote><h2><a class="anchor" name="exporting-constants"></a>Exporting Constants <a class="hash-link" href="docs/native-modules-ios.html#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></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't work.</p></blockquote><h2><a class="anchor" name="depedency-injection"></a>Depedency Injection <a class="hash-link" href="docs/native-modules-ios.html#depedency-injection">#</a></h2><p>The bridge initializes any registered RCTBridgeModules automatically, however you may wish to instantiate your own module instances (so you may inject dependencies, for example).</p><p>You can do this by creating a class that implements the RTCBridgeDelegate Protocol, initializing an RTCBridge with the delegate as an argument and initialising a RTCRootView with the initialized bridge.</p><div class="prism language-javascript">id<RCTBridgeDelegate<span class="token operator">></span> moduleInitialiser <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">[</span>classThatImplementsRTCBridgeDelegate alloc<span class="token punctuation">]</span> init<span class="token punctuation">]</span><span class="token punctuation">;</span>
|
||||
|
||||
RCTBridge <span class="token operator">*</span>bridge <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">[</span>RCTBridge alloc<span class="token punctuation">]</span> initWithDelegate<span class="token punctuation">:</span>moduleInitialiser launchOptions<span class="token punctuation">:</span>nil<span class="token punctuation">]</span><span class="token punctuation">;</span>
|
||||
|
||||
RCTRootView <span class="token operator">*</span>rootView <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">[</span>RCTRootView alloc<span class="token punctuation">]</span>
|
||||
initWithBridge<span class="token punctuation">:</span>bridge
|
||||
moduleName<span class="token punctuation">:</span>kModuleName
|
||||
initialProperties<span class="token punctuation">:</span>nil<span class="token punctuation">]</span><span class="token punctuation">;</span></div><h2><a class="anchor" name="exporting-constants"></a>Exporting Constants <a class="hash-link" href="docs/native-modules-ios.html#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">"firstDayOfTheWeek"</span><span class="token punctuation">:</span> @<span class="token string">"Monday"</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't affect the JavaScript environment.</p><h3><a class="anchor" name="enum-constants"></a>Enum Constants <a class="hash-link" href="docs/native-modules-ios.html#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>
|
||||
|
||||
Reference in New Issue
Block a user