mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Deploy website
Deploy website version based on 6e737eab6c012850a79ab8c5d6b93d52a7407f11
This commit is contained in:
+1
-1
File diff suppressed because one or more lines are too long
@@ -111,7 +111,7 @@ RCT_EXPORT_METHOD(addEvent:(<span class="hljs-built_in">NSString</span> *)name l
|
||||
|
||||
<span class="hljs-keyword">@end</span>
|
||||
</code></pre>
|
||||
<p>Now, from your JavaScript file you can call the method like this:</p>
|
||||
<p>Now, from your JavaScript file you can call the method like this (after making sure to rebuild):</p>
|
||||
<pre><code class="hljs css language-jsx"><span class="token keyword">import</span> <span class="token punctuation">{</span> NativeModules <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'react-native'</span><span class="token punctuation">;</span>
|
||||
<span class="token keyword">var</span> CalendarManager <span class="token operator">=</span> NativeModules<span class="token punctuation">.</span>CalendarManager<span class="token punctuation">;</span>
|
||||
CalendarManager<span class="token punctuation">.</span><span class="token function">addEvent</span><span class="token punctuation">(</span>
|
||||
@@ -194,7 +194,7 @@ RCT_EXPORT_METHOD(addEvent:(<span class="hljs-built_in">NSString</span> *)name d
|
||||
<p><strong>WARNING</strong></p>
|
||||
<p>This section is more experimental than others because we don't have a solid set of best practices around callbacks yet.</p>
|
||||
</blockquote>
|
||||
<p>Native modules also supports a unique kind of argument- a callback. In most cases it is used to provide the function call result to JavaScript.</p>
|
||||
<p>Native modules also supports a unique type of argument- a callback. In most cases it is used to provide the function call result to JavaScript.</p>
|
||||
<pre><code class="hljs css language-objectivec">RCT_EXPORT_METHOD(findEvents:(RCTResponseSenderBlock)callback)
|
||||
{
|
||||
<span class="hljs-built_in">NSArray</span> *events = ...
|
||||
@@ -299,6 +299,21 @@ RCTRootView *rootView = [[RCTRootView alloc]
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-literal">YES</span>; <span class="hljs-comment">// only do this if your module initialization relies on calling UIKit!</span>
|
||||
}
|
||||
</code></pre>
|
||||
<pre><code class="hljs css language-Swift"><span class="hljs-comment">//Swift</span>
|
||||
|
||||
<span class="hljs-comment">// CalendarManager.swift</span>
|
||||
|
||||
<span class="hljs-meta">@objc</span>(<span class="hljs-type">CalendarManager</span>)
|
||||
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CalendarManager</span>: <span class="hljs-title">NSObject</span>, <span class="hljs-title">RCTBridgeModule</span> </span>{
|
||||
|
||||
<span class="hljs-keyword">static</span> <span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">moduleName</span><span class="hljs-params">()</span></span> -> <span class="hljs-type">String!</span> {
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-string">"CalendarManager"</span>;
|
||||
}
|
||||
|
||||
<span class="hljs-keyword">static</span> <span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">requiresMainQueueSetup</span><span class="hljs-params">()</span></span> -> <span class="hljs-type">Bool</span> {
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>
|
||||
}
|
||||
</code></pre>
|
||||
<p>If your module does not require access to UIKit, then you should respond to <code>+ requiresMainQueueSetup</code> with <code>NO</code>.</p>
|
||||
<h3><a class="anchor" aria-hidden="true" id="enum-constants"></a><a href="#enum-constants" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Enum Constants</h3>
|
||||
<p>Enums that are defined via <code>NS_ENUM</code> cannot be used as method arguments without first extending RCTConvert.</p>
|
||||
@@ -373,7 +388,6 @@ RCT_EXPORT_MODULE();
|
||||
<span class="token comment">// Don't forget to unsubscribe, typically in componentWillUnmount</span>
|
||||
subscription<span class="token punctuation">.</span><span class="token function">remove</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||||
</code></pre>
|
||||
<p>For more examples of sending events to JavaScript, see <a href="https://github.com/facebook/react-native/blob/master/Libraries/Geolocation/RCTLocationObserver.m"><code>RCTLocationObserver</code></a>.</p>
|
||||
<h3><a class="anchor" aria-hidden="true" id="optimizing-for-zero-listeners"></a><a href="#optimizing-for-zero-listeners" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Optimizing for zero listeners</h3>
|
||||
<p>You will receive a warning if you expend resources unnecessarily by emitting an event while there are no listeners. To avoid this, and to optimize your module's workload (e.g. by unsubscribing from upstream notifications or pausing background tasks), you can override <code>startObserving</code> and <code>stopObserving</code> in your <code>RCTEventEmitter</code> subclass.</p>
|
||||
<pre><code class="hljs css language-objectivec"><span class="hljs-class"><span class="hljs-keyword">@implementation</span> <span class="hljs-title">CalendarManager</span></span>
|
||||
|
||||
@@ -111,7 +111,7 @@ RCT_EXPORT_METHOD(addEvent:(<span class="hljs-built_in">NSString</span> *)name l
|
||||
|
||||
<span class="hljs-keyword">@end</span>
|
||||
</code></pre>
|
||||
<p>Now, from your JavaScript file you can call the method like this:</p>
|
||||
<p>Now, from your JavaScript file you can call the method like this (after making sure to rebuild):</p>
|
||||
<pre><code class="hljs css language-jsx"><span class="token keyword">import</span> <span class="token punctuation">{</span> NativeModules <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'react-native'</span><span class="token punctuation">;</span>
|
||||
<span class="token keyword">var</span> CalendarManager <span class="token operator">=</span> NativeModules<span class="token punctuation">.</span>CalendarManager<span class="token punctuation">;</span>
|
||||
CalendarManager<span class="token punctuation">.</span><span class="token function">addEvent</span><span class="token punctuation">(</span>
|
||||
@@ -194,7 +194,7 @@ RCT_EXPORT_METHOD(addEvent:(<span class="hljs-built_in">NSString</span> *)name d
|
||||
<p><strong>WARNING</strong></p>
|
||||
<p>This section is more experimental than others because we don't have a solid set of best practices around callbacks yet.</p>
|
||||
</blockquote>
|
||||
<p>Native modules also supports a unique kind of argument- a callback. In most cases it is used to provide the function call result to JavaScript.</p>
|
||||
<p>Native modules also supports a unique type of argument- a callback. In most cases it is used to provide the function call result to JavaScript.</p>
|
||||
<pre><code class="hljs css language-objectivec">RCT_EXPORT_METHOD(findEvents:(RCTResponseSenderBlock)callback)
|
||||
{
|
||||
<span class="hljs-built_in">NSArray</span> *events = ...
|
||||
@@ -299,6 +299,21 @@ RCTRootView *rootView = [[RCTRootView alloc]
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-literal">YES</span>; <span class="hljs-comment">// only do this if your module initialization relies on calling UIKit!</span>
|
||||
}
|
||||
</code></pre>
|
||||
<pre><code class="hljs css language-Swift"><span class="hljs-comment">//Swift</span>
|
||||
|
||||
<span class="hljs-comment">// CalendarManager.swift</span>
|
||||
|
||||
<span class="hljs-meta">@objc</span>(<span class="hljs-type">CalendarManager</span>)
|
||||
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CalendarManager</span>: <span class="hljs-title">NSObject</span>, <span class="hljs-title">RCTBridgeModule</span> </span>{
|
||||
|
||||
<span class="hljs-keyword">static</span> <span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">moduleName</span><span class="hljs-params">()</span></span> -> <span class="hljs-type">String!</span> {
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-string">"CalendarManager"</span>;
|
||||
}
|
||||
|
||||
<span class="hljs-keyword">static</span> <span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">requiresMainQueueSetup</span><span class="hljs-params">()</span></span> -> <span class="hljs-type">Bool</span> {
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>
|
||||
}
|
||||
</code></pre>
|
||||
<p>If your module does not require access to UIKit, then you should respond to <code>+ requiresMainQueueSetup</code> with <code>NO</code>.</p>
|
||||
<h3><a class="anchor" aria-hidden="true" id="enum-constants"></a><a href="#enum-constants" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Enum Constants</h3>
|
||||
<p>Enums that are defined via <code>NS_ENUM</code> cannot be used as method arguments without first extending RCTConvert.</p>
|
||||
@@ -373,7 +388,6 @@ RCT_EXPORT_MODULE();
|
||||
<span class="token comment">// Don't forget to unsubscribe, typically in componentWillUnmount</span>
|
||||
subscription<span class="token punctuation">.</span><span class="token function">remove</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||||
</code></pre>
|
||||
<p>For more examples of sending events to JavaScript, see <a href="https://github.com/facebook/react-native/blob/master/Libraries/Geolocation/RCTLocationObserver.m"><code>RCTLocationObserver</code></a>.</p>
|
||||
<h3><a class="anchor" aria-hidden="true" id="optimizing-for-zero-listeners"></a><a href="#optimizing-for-zero-listeners" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Optimizing for zero listeners</h3>
|
||||
<p>You will receive a warning if you expend resources unnecessarily by emitting an event while there are no listeners. To avoid this, and to optimize your module's workload (e.g. by unsubscribing from upstream notifications or pausing background tasks), you can override <code>startObserving</code> and <code>stopObserving</code> in your <code>RCTEventEmitter</code> subclass.</p>
|
||||
<pre><code class="hljs css language-objectivec"><span class="hljs-class"><span class="hljs-keyword">@implementation</span> <span class="hljs-title">CalendarManager</span></span>
|
||||
|
||||
@@ -111,7 +111,7 @@ RCT_EXPORT_METHOD(addEvent:(<span class="hljs-built_in">NSString</span> *)name l
|
||||
|
||||
<span class="hljs-keyword">@end</span>
|
||||
</code></pre>
|
||||
<p>Now, from your JavaScript file you can call the method like this:</p>
|
||||
<p>Now, from your JavaScript file you can call the method like this (after making sure to rebuild):</p>
|
||||
<pre><code class="hljs css language-jsx"><span class="token keyword">import</span> <span class="token punctuation">{</span> NativeModules <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'react-native'</span><span class="token punctuation">;</span>
|
||||
<span class="token keyword">var</span> CalendarManager <span class="token operator">=</span> NativeModules<span class="token punctuation">.</span>CalendarManager<span class="token punctuation">;</span>
|
||||
CalendarManager<span class="token punctuation">.</span><span class="token function">addEvent</span><span class="token punctuation">(</span>
|
||||
@@ -194,7 +194,7 @@ RCT_EXPORT_METHOD(addEvent:(<span class="hljs-built_in">NSString</span> *)name d
|
||||
<p><strong>WARNING</strong></p>
|
||||
<p>This section is more experimental than others because we don't have a solid set of best practices around callbacks yet.</p>
|
||||
</blockquote>
|
||||
<p>Native modules also supports a unique kind of argument- a callback. In most cases it is used to provide the function call result to JavaScript.</p>
|
||||
<p>Native modules also supports a unique type of argument- a callback. In most cases it is used to provide the function call result to JavaScript.</p>
|
||||
<pre><code class="hljs css language-objectivec">RCT_EXPORT_METHOD(findEvents:(RCTResponseSenderBlock)callback)
|
||||
{
|
||||
<span class="hljs-built_in">NSArray</span> *events = ...
|
||||
@@ -299,6 +299,21 @@ RCTRootView *rootView = [[RCTRootView alloc]
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-literal">YES</span>; <span class="hljs-comment">// only do this if your module initialization relies on calling UIKit!</span>
|
||||
}
|
||||
</code></pre>
|
||||
<pre><code class="hljs css language-Swift"><span class="hljs-comment">//Swift</span>
|
||||
|
||||
<span class="hljs-comment">// CalendarManager.swift</span>
|
||||
|
||||
<span class="hljs-meta">@objc</span>(<span class="hljs-type">CalendarManager</span>)
|
||||
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CalendarManager</span>: <span class="hljs-title">NSObject</span>, <span class="hljs-title">RCTBridgeModule</span> </span>{
|
||||
|
||||
<span class="hljs-keyword">static</span> <span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">moduleName</span><span class="hljs-params">()</span></span> -> <span class="hljs-type">String!</span> {
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-string">"CalendarManager"</span>;
|
||||
}
|
||||
|
||||
<span class="hljs-keyword">static</span> <span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">requiresMainQueueSetup</span><span class="hljs-params">()</span></span> -> <span class="hljs-type">Bool</span> {
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>
|
||||
}
|
||||
</code></pre>
|
||||
<p>If your module does not require access to UIKit, then you should respond to <code>+ requiresMainQueueSetup</code> with <code>NO</code>.</p>
|
||||
<h3><a class="anchor" aria-hidden="true" id="enum-constants"></a><a href="#enum-constants" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Enum Constants</h3>
|
||||
<p>Enums that are defined via <code>NS_ENUM</code> cannot be used as method arguments without first extending RCTConvert.</p>
|
||||
@@ -373,7 +388,6 @@ RCT_EXPORT_MODULE();
|
||||
<span class="token comment">// Don't forget to unsubscribe, typically in componentWillUnmount</span>
|
||||
subscription<span class="token punctuation">.</span><span class="token function">remove</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||||
</code></pre>
|
||||
<p>For more examples of sending events to JavaScript, see <a href="https://github.com/facebook/react-native/blob/master/Libraries/Geolocation/RCTLocationObserver.m"><code>RCTLocationObserver</code></a>.</p>
|
||||
<h3><a class="anchor" aria-hidden="true" id="optimizing-for-zero-listeners"></a><a href="#optimizing-for-zero-listeners" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Optimizing for zero listeners</h3>
|
||||
<p>You will receive a warning if you expend resources unnecessarily by emitting an event while there are no listeners. To avoid this, and to optimize your module's workload (e.g. by unsubscribing from upstream notifications or pausing background tasks), you can override <code>startObserving</code> and <code>stopObserving</code> in your <code>RCTEventEmitter</code> subclass.</p>
|
||||
<pre><code class="hljs css language-objectivec"><span class="hljs-class"><span class="hljs-keyword">@implementation</span> <span class="hljs-title">CalendarManager</span></span>
|
||||
|
||||
@@ -111,7 +111,7 @@ RCT_EXPORT_METHOD(addEvent:(<span class="hljs-built_in">NSString</span> *)name l
|
||||
|
||||
<span class="hljs-keyword">@end</span>
|
||||
</code></pre>
|
||||
<p>Now, from your JavaScript file you can call the method like this:</p>
|
||||
<p>Now, from your JavaScript file you can call the method like this (after making sure to rebuild):</p>
|
||||
<pre><code class="hljs css language-jsx"><span class="token keyword">import</span> <span class="token punctuation">{</span> NativeModules <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'react-native'</span><span class="token punctuation">;</span>
|
||||
<span class="token keyword">var</span> CalendarManager <span class="token operator">=</span> NativeModules<span class="token punctuation">.</span>CalendarManager<span class="token punctuation">;</span>
|
||||
CalendarManager<span class="token punctuation">.</span><span class="token function">addEvent</span><span class="token punctuation">(</span>
|
||||
@@ -194,7 +194,7 @@ RCT_EXPORT_METHOD(addEvent:(<span class="hljs-built_in">NSString</span> *)name d
|
||||
<p><strong>WARNING</strong></p>
|
||||
<p>This section is more experimental than others because we don't have a solid set of best practices around callbacks yet.</p>
|
||||
</blockquote>
|
||||
<p>Native modules also supports a unique kind of argument- a callback. In most cases it is used to provide the function call result to JavaScript.</p>
|
||||
<p>Native modules also supports a unique type of argument- a callback. In most cases it is used to provide the function call result to JavaScript.</p>
|
||||
<pre><code class="hljs css language-objectivec">RCT_EXPORT_METHOD(findEvents:(RCTResponseSenderBlock)callback)
|
||||
{
|
||||
<span class="hljs-built_in">NSArray</span> *events = ...
|
||||
@@ -299,6 +299,21 @@ RCTRootView *rootView = [[RCTRootView alloc]
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-literal">YES</span>; <span class="hljs-comment">// only do this if your module initialization relies on calling UIKit!</span>
|
||||
}
|
||||
</code></pre>
|
||||
<pre><code class="hljs css language-Swift"><span class="hljs-comment">//Swift</span>
|
||||
|
||||
<span class="hljs-comment">// CalendarManager.swift</span>
|
||||
|
||||
<span class="hljs-meta">@objc</span>(<span class="hljs-type">CalendarManager</span>)
|
||||
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CalendarManager</span>: <span class="hljs-title">NSObject</span>, <span class="hljs-title">RCTBridgeModule</span> </span>{
|
||||
|
||||
<span class="hljs-keyword">static</span> <span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">moduleName</span><span class="hljs-params">()</span></span> -> <span class="hljs-type">String!</span> {
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-string">"CalendarManager"</span>;
|
||||
}
|
||||
|
||||
<span class="hljs-keyword">static</span> <span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">requiresMainQueueSetup</span><span class="hljs-params">()</span></span> -> <span class="hljs-type">Bool</span> {
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>
|
||||
}
|
||||
</code></pre>
|
||||
<p>If your module does not require access to UIKit, then you should respond to <code>+ requiresMainQueueSetup</code> with <code>NO</code>.</p>
|
||||
<h3><a class="anchor" aria-hidden="true" id="enum-constants"></a><a href="#enum-constants" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Enum Constants</h3>
|
||||
<p>Enums that are defined via <code>NS_ENUM</code> cannot be used as method arguments without first extending RCTConvert.</p>
|
||||
@@ -373,7 +388,6 @@ RCT_EXPORT_MODULE();
|
||||
<span class="token comment">// Don't forget to unsubscribe, typically in componentWillUnmount</span>
|
||||
subscription<span class="token punctuation">.</span><span class="token function">remove</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||||
</code></pre>
|
||||
<p>For more examples of sending events to JavaScript, see <a href="https://github.com/facebook/react-native/blob/master/Libraries/Geolocation/RCTLocationObserver.m"><code>RCTLocationObserver</code></a>.</p>
|
||||
<h3><a class="anchor" aria-hidden="true" id="optimizing-for-zero-listeners"></a><a href="#optimizing-for-zero-listeners" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Optimizing for zero listeners</h3>
|
||||
<p>You will receive a warning if you expend resources unnecessarily by emitting an event while there are no listeners. To avoid this, and to optimize your module's workload (e.g. by unsubscribing from upstream notifications or pausing background tasks), you can override <code>startObserving</code> and <code>stopObserving</code> in your <code>RCTEventEmitter</code> subclass.</p>
|
||||
<pre><code class="hljs css language-objectivec"><span class="hljs-class"><span class="hljs-keyword">@implementation</span> <span class="hljs-title">CalendarManager</span></span>
|
||||
|
||||
@@ -388,7 +388,6 @@ RCT_EXPORT_MODULE();
|
||||
<span class="token comment">// Don't forget to unsubscribe, typically in componentWillUnmount</span>
|
||||
subscription<span class="token punctuation">.</span><span class="token function">remove</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||||
</code></pre>
|
||||
<p>For more examples of sending events to JavaScript, see <a href="https://github.com/facebook/react-native/blob/master/Libraries/Geolocation/RCTLocationObserver.m"><code>RCTLocationObserver</code></a>.</p>
|
||||
<h3><a class="anchor" aria-hidden="true" id="optimizing-for-zero-listeners"></a><a href="#optimizing-for-zero-listeners" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Optimizing for zero listeners</h3>
|
||||
<p>You will receive a warning if you expend resources unnecessarily by emitting an event while there are no listeners. To avoid this, and to optimize your module's workload (e.g. by unsubscribing from upstream notifications or pausing background tasks), you can override <code>startObserving</code> and <code>stopObserving</code> in your <code>RCTEventEmitter</code> subclass.</p>
|
||||
<pre><code class="hljs css language-objectivec"><span class="hljs-class"><span class="hljs-keyword">@implementation</span> <span class="hljs-title">CalendarManager</span></span>
|
||||
@@ -459,7 +458,7 @@ RCT_EXTERN_METHOD(addEvent:(<span class="hljs-built_in">NSString</span> *)name l
|
||||
</blockquote>
|
||||
<h2><a class="anchor" aria-hidden="true" id="reserved-method-names"></a><a href="#reserved-method-names" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Reserved Method Names</h2>
|
||||
<h3><a class="anchor" aria-hidden="true" id="invalidate"></a><a href="#invalidate" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>invalidate()</h3>
|
||||
<p>Native modules can conform to the <a href="https://github.com/facebook/react-native/blob/aa0ef15335fe27c0c193e3e968789886d82e82ed/React/Base/RCTInvalidating.h">RCTInvalidating</a> protocol on iOS by implementing the <code>invalidate</code> method. This method <a href="https://github.com/facebook/react-native/blob/18e3303cd46a72668caae46e28c7c6ae69fbf8f8/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm#L456">can be invoked</a> when the native bridge is invalidated (ie: on devmode reload). You should avoid implementing this method in general, as this mechanism exists for backwards compatibility and may be removed in the future.</p>
|
||||
<p>Native modules can conform to the <a href="https://github.com/facebook/react-native/blob/0.62-stable/React/Base/RCTInvalidating.h">RCTInvalidating</a> protocol on iOS by implementing the <code>invalidate</code> method. This method <a href="https://github.com/facebook/react-native/blob/0.62-stable/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm#L456">can be invoked</a> when the native bridge is invalidated (ie: on devmode reload). You should avoid implementing this method in general, as this mechanism exists for backwards compatibility and may be removed in the future.</p>
|
||||
</span></div></article></div><div class="docs-prevnext"><a class="docs-prev button" href="/docs/removing-default-permissions"><span class="arrow-prev">← </span><span>Removing Default Permissions</span></a><a class="docs-next button" href="/docs/native-components-ios"><span>Native UI Components</span><span class="arrow-next"> →</span></a></div></div></div><nav class="onPageNav"><ul class="toc-headings"><li><a href="#native-module-setup">Native Module Setup</a></li><li><a href="#ios-calendar-module-example">iOS Calendar Module Example</a></li><li><a href="#argument-types">Argument Types</a></li><li><a href="#callbacks">Callbacks</a></li><li><a href="#promises">Promises</a></li><li><a href="#threading">Threading</a></li><li><a href="#dependency-injection">Dependency Injection</a></li><li><a href="#exporting-constants">Exporting Constants</a><ul class="toc-headings"><li><a href="#implementing--requiresmainqueuesetup">Implementing <code>+ requiresMainQueueSetup</code></a></li><li><a href="#enum-constants">Enum Constants</a></li></ul></li><li><a href="#sending-events-to-javascript">Sending Events to JavaScript</a><ul class="toc-headings"><li><a href="#optimizing-for-zero-listeners">Optimizing for zero listeners</a></li></ul></li><li><a href="#exporting-swift">Exporting Swift</a></li><li><a href="#reserved-method-names">Reserved Method Names</a><ul class="toc-headings"><li><a href="#invalidate">invalidate()</a></li></ul></li></ul></nav></div><footer class="nav-footer" id="footer"><section class="sitemap"><div><h5>Docs</h5><a href="/docs/getting-started.html">Getting Started</a><a href="/docs/tutorial.html">Tutorial</a><a href="/docs/components-and-apis.html">Components and APIs</a><a href="/docs/more-resources.html">More Resources</a></div><div><h5>Community</h5><a href="/help.html">The React Native Community</a><a href="/showcase.html">Who's using React Native?</a><a href="http://stackoverflow.com/questions/tagged/react-native" target="_blank">Ask Questions on Stack Overflow</a><a href="https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md">Contributor Guide</a><a href="https://dev.to/t/reactnative" target="_blank">DEV Community</a></div><div><h5>More Resources</h5><a href="/blog/">Blog</a><a href="https://twitter.com/reactnative" target="_blank">Twitter</a><a href="https://github.com/facebook/react-native" target="_blank">GitHub</a><a href="https://reactjs.org" target="_blank">React</a></div></section><a href="https://code.facebook.com/projects/" target="_blank" class="fbOpenSource"><img src="/img/oss_logo.png" alt="Facebook Open Source" width="170" height="45"/></a><section class="copyright">Copyright © 2020 Facebook Inc.</section></footer></div><script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.js"></script><script>window.fbAsyncInit = function() {FB.init({appId:'1677033832619985',xfbml:true,version:'v2.7'});};(function(d, s, id){var js, fjs = d.getElementsByTagName(s)[0];if (d.getElementById(id)) {return;}js = d.createElement(s); js.id = id;js.src = '//connect.facebook.net/en_US/sdk.js';fjs.parentNode.insertBefore(js, fjs);}(document, 'script','facebook-jssdk'));
|
||||
</script><script>window.twttr=(function(d,s, id){var js,fjs=d.getElementsByTagName(s)[0],t=window.twttr||{};if(d.getElementById(id))return t;js=d.createElement(s);js.id=id;js.src='https://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js, fjs);t._e = [];t.ready = function(f) {t._e.push(f);};return t;}(document, 'script', 'twitter-wjs'));</script><script>
|
||||
document.addEventListener('keyup', function(e) {
|
||||
|
||||
@@ -388,7 +388,6 @@ RCT_EXPORT_MODULE();
|
||||
<span class="token comment">// Don't forget to unsubscribe, typically in componentWillUnmount</span>
|
||||
subscription<span class="token punctuation">.</span><span class="token function">remove</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||||
</code></pre>
|
||||
<p>For more examples of sending events to JavaScript, see <a href="https://github.com/facebook/react-native/blob/master/Libraries/Geolocation/RCTLocationObserver.m"><code>RCTLocationObserver</code></a>.</p>
|
||||
<h3><a class="anchor" aria-hidden="true" id="optimizing-for-zero-listeners"></a><a href="#optimizing-for-zero-listeners" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Optimizing for zero listeners</h3>
|
||||
<p>You will receive a warning if you expend resources unnecessarily by emitting an event while there are no listeners. To avoid this, and to optimize your module's workload (e.g. by unsubscribing from upstream notifications or pausing background tasks), you can override <code>startObserving</code> and <code>stopObserving</code> in your <code>RCTEventEmitter</code> subclass.</p>
|
||||
<pre><code class="hljs css language-objectivec"><span class="hljs-class"><span class="hljs-keyword">@implementation</span> <span class="hljs-title">CalendarManager</span></span>
|
||||
@@ -459,7 +458,7 @@ RCT_EXTERN_METHOD(addEvent:(<span class="hljs-built_in">NSString</span> *)name l
|
||||
</blockquote>
|
||||
<h2><a class="anchor" aria-hidden="true" id="reserved-method-names"></a><a href="#reserved-method-names" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Reserved Method Names</h2>
|
||||
<h3><a class="anchor" aria-hidden="true" id="invalidate"></a><a href="#invalidate" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>invalidate()</h3>
|
||||
<p>Native modules can conform to the <a href="https://github.com/facebook/react-native/blob/aa0ef15335fe27c0c193e3e968789886d82e82ed/React/Base/RCTInvalidating.h">RCTInvalidating</a> protocol on iOS by implementing the <code>invalidate</code> method. This method <a href="https://github.com/facebook/react-native/blob/18e3303cd46a72668caae46e28c7c6ae69fbf8f8/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm#L456">can be invoked</a> when the native bridge is invalidated (ie: on devmode reload). You should avoid implementing this method in general, as this mechanism exists for backwards compatibility and may be removed in the future.</p>
|
||||
<p>Native modules can conform to the <a href="https://github.com/facebook/react-native/blob/0.62-stable/React/Base/RCTInvalidating.h">RCTInvalidating</a> protocol on iOS by implementing the <code>invalidate</code> method. This method <a href="https://github.com/facebook/react-native/blob/0.62-stable/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm#L456">can be invoked</a> when the native bridge is invalidated (ie: on devmode reload). You should avoid implementing this method in general, as this mechanism exists for backwards compatibility and may be removed in the future.</p>
|
||||
</span></div></article></div><div class="docs-prevnext"><a class="docs-prev button" href="/docs/removing-default-permissions"><span class="arrow-prev">← </span><span>Removing Default Permissions</span></a><a class="docs-next button" href="/docs/native-components-ios"><span>Native UI Components</span><span class="arrow-next"> →</span></a></div></div></div><nav class="onPageNav"><ul class="toc-headings"><li><a href="#native-module-setup">Native Module Setup</a></li><li><a href="#ios-calendar-module-example">iOS Calendar Module Example</a></li><li><a href="#argument-types">Argument Types</a></li><li><a href="#callbacks">Callbacks</a></li><li><a href="#promises">Promises</a></li><li><a href="#threading">Threading</a></li><li><a href="#dependency-injection">Dependency Injection</a></li><li><a href="#exporting-constants">Exporting Constants</a><ul class="toc-headings"><li><a href="#implementing--requiresmainqueuesetup">Implementing <code>+ requiresMainQueueSetup</code></a></li><li><a href="#enum-constants">Enum Constants</a></li></ul></li><li><a href="#sending-events-to-javascript">Sending Events to JavaScript</a><ul class="toc-headings"><li><a href="#optimizing-for-zero-listeners">Optimizing for zero listeners</a></li></ul></li><li><a href="#exporting-swift">Exporting Swift</a></li><li><a href="#reserved-method-names">Reserved Method Names</a><ul class="toc-headings"><li><a href="#invalidate">invalidate()</a></li></ul></li></ul></nav></div><footer class="nav-footer" id="footer"><section class="sitemap"><div><h5>Docs</h5><a href="/docs/getting-started.html">Getting Started</a><a href="/docs/tutorial.html">Tutorial</a><a href="/docs/components-and-apis.html">Components and APIs</a><a href="/docs/more-resources.html">More Resources</a></div><div><h5>Community</h5><a href="/help.html">The React Native Community</a><a href="/showcase.html">Who's using React Native?</a><a href="http://stackoverflow.com/questions/tagged/react-native" target="_blank">Ask Questions on Stack Overflow</a><a href="https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md">Contributor Guide</a><a href="https://dev.to/t/reactnative" target="_blank">DEV Community</a></div><div><h5>More Resources</h5><a href="/blog/">Blog</a><a href="https://twitter.com/reactnative" target="_blank">Twitter</a><a href="https://github.com/facebook/react-native" target="_blank">GitHub</a><a href="https://reactjs.org" target="_blank">React</a></div></section><a href="https://code.facebook.com/projects/" target="_blank" class="fbOpenSource"><img src="/img/oss_logo.png" alt="Facebook Open Source" width="170" height="45"/></a><section class="copyright">Copyright © 2020 Facebook Inc.</section></footer></div><script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.js"></script><script>window.fbAsyncInit = function() {FB.init({appId:'1677033832619985',xfbml:true,version:'v2.7'});};(function(d, s, id){var js, fjs = d.getElementsByTagName(s)[0];if (d.getElementById(id)) {return;}js = d.createElement(s); js.id = id;js.src = '//connect.facebook.net/en_US/sdk.js';fjs.parentNode.insertBefore(js, fjs);}(document, 'script','facebook-jssdk'));
|
||||
</script><script>window.twttr=(function(d,s, id){var js,fjs=d.getElementsByTagName(s)[0],t=window.twttr||{};if(d.getElementById(id))return t;js=d.createElement(s);js.id=id;js.src='https://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js, fjs);t._e = [];t.ready = function(f) {t._e.push(f);};return t;}(document, 'script', 'twitter-wjs'));</script><script>
|
||||
document.addEventListener('keyup', function(e) {
|
||||
|
||||
@@ -388,7 +388,6 @@ RCT_EXPORT_MODULE();
|
||||
<span class="token comment">// Don't forget to unsubscribe, typically in componentWillUnmount</span>
|
||||
subscription<span class="token punctuation">.</span><span class="token function">remove</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||||
</code></pre>
|
||||
<p>For more examples of sending events to JavaScript, see <a href="https://github.com/facebook/react-native/blob/master/Libraries/Geolocation/RCTLocationObserver.m"><code>RCTLocationObserver</code></a>.</p>
|
||||
<h3><a class="anchor" aria-hidden="true" id="optimizing-for-zero-listeners"></a><a href="#optimizing-for-zero-listeners" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Optimizing for zero listeners</h3>
|
||||
<p>You will receive a warning if you expend resources unnecessarily by emitting an event while there are no listeners. To avoid this, and to optimize your module's workload (e.g. by unsubscribing from upstream notifications or pausing background tasks), you can override <code>startObserving</code> and <code>stopObserving</code> in your <code>RCTEventEmitter</code> subclass.</p>
|
||||
<pre><code class="hljs css language-objectivec"><span class="hljs-class"><span class="hljs-keyword">@implementation</span> <span class="hljs-title">CalendarManager</span></span>
|
||||
@@ -459,7 +458,7 @@ RCT_EXTERN_METHOD(addEvent:(<span class="hljs-built_in">NSString</span> *)name l
|
||||
</blockquote>
|
||||
<h2><a class="anchor" aria-hidden="true" id="reserved-method-names"></a><a href="#reserved-method-names" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Reserved Method Names</h2>
|
||||
<h3><a class="anchor" aria-hidden="true" id="invalidate"></a><a href="#invalidate" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>invalidate()</h3>
|
||||
<p>Native modules can conform to the <a href="https://github.com/facebook/react-native/blob/aa0ef15335fe27c0c193e3e968789886d82e82ed/React/Base/RCTInvalidating.h">RCTInvalidating</a> protocol on iOS by implementing the <code>invalidate</code> method. This method <a href="https://github.com/facebook/react-native/blob/18e3303cd46a72668caae46e28c7c6ae69fbf8f8/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm#L456">can be invoked</a> when the native bridge is invalidated (ie: on devmode reload). You should avoid implementing this method in general, as this mechanism exists for backwards compatibility and may be removed in the future.</p>
|
||||
<p>Native modules can conform to the <a href="https://github.com/facebook/react-native/blob/master/React/Base/RCTInvalidating.h">RCTInvalidating</a> protocol on iOS by implementing the <code>invalidate</code> method. This method <a href="https://github.com/facebook/react-native/blob/master/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm#L756">can be invoked</a> when the native bridge is invalidated (ie: on devmode reload). You should avoid implementing this method in general, as this mechanism exists for backwards compatibility and may be removed in the future.</p>
|
||||
</span></div></article></div><div class="docs-prevnext"><a class="docs-prev button" href="/docs/next/removing-default-permissions"><span class="arrow-prev">← </span><span>Removing Default Permissions</span></a><a class="docs-next button" href="/docs/next/native-components-ios"><span>Native UI Components</span><span class="arrow-next"> →</span></a></div></div></div><nav class="onPageNav"><ul class="toc-headings"><li><a href="#native-module-setup">Native Module Setup</a></li><li><a href="#ios-calendar-module-example">iOS Calendar Module Example</a></li><li><a href="#argument-types">Argument Types</a></li><li><a href="#callbacks">Callbacks</a></li><li><a href="#promises">Promises</a></li><li><a href="#threading">Threading</a></li><li><a href="#dependency-injection">Dependency Injection</a></li><li><a href="#exporting-constants">Exporting Constants</a><ul class="toc-headings"><li><a href="#implementing--requiresmainqueuesetup">Implementing <code>+ requiresMainQueueSetup</code></a></li><li><a href="#enum-constants">Enum Constants</a></li></ul></li><li><a href="#sending-events-to-javascript">Sending Events to JavaScript</a><ul class="toc-headings"><li><a href="#optimizing-for-zero-listeners">Optimizing for zero listeners</a></li></ul></li><li><a href="#exporting-swift">Exporting Swift</a></li><li><a href="#reserved-method-names">Reserved Method Names</a><ul class="toc-headings"><li><a href="#invalidate">invalidate()</a></li></ul></li></ul></nav></div><footer class="nav-footer" id="footer"><section class="sitemap"><div><h5>Docs</h5><a href="/docs/getting-started.html">Getting Started</a><a href="/docs/tutorial.html">Tutorial</a><a href="/docs/components-and-apis.html">Components and APIs</a><a href="/docs/more-resources.html">More Resources</a></div><div><h5>Community</h5><a href="/help.html">The React Native Community</a><a href="/showcase.html">Who's using React Native?</a><a href="http://stackoverflow.com/questions/tagged/react-native" target="_blank">Ask Questions on Stack Overflow</a><a href="https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md">Contributor Guide</a><a href="https://dev.to/t/reactnative" target="_blank">DEV Community</a></div><div><h5>More Resources</h5><a href="/blog/">Blog</a><a href="https://twitter.com/reactnative" target="_blank">Twitter</a><a href="https://github.com/facebook/react-native" target="_blank">GitHub</a><a href="https://reactjs.org" target="_blank">React</a></div></section><a href="https://code.facebook.com/projects/" target="_blank" class="fbOpenSource"><img src="/img/oss_logo.png" alt="Facebook Open Source" width="170" height="45"/></a><section class="copyright">Copyright © 2020 Facebook Inc.</section></footer></div><script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.js"></script><script>window.fbAsyncInit = function() {FB.init({appId:'1677033832619985',xfbml:true,version:'v2.7'});};(function(d, s, id){var js, fjs = d.getElementsByTagName(s)[0];if (d.getElementById(id)) {return;}js = d.createElement(s); js.id = id;js.src = '//connect.facebook.net/en_US/sdk.js';fjs.parentNode.insertBefore(js, fjs);}(document, 'script','facebook-jssdk'));
|
||||
</script><script>window.twttr=(function(d,s, id){var js,fjs=d.getElementsByTagName(s)[0],t=window.twttr||{};if(d.getElementById(id))return t;js=d.createElement(s);js.id=id;js.src='https://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js, fjs);t._e = [];t.ready = function(f) {t._e.push(f);};return t;}(document, 'script', 'twitter-wjs'));</script><script>
|
||||
document.addEventListener('keyup', function(e) {
|
||||
|
||||
@@ -388,7 +388,6 @@ RCT_EXPORT_MODULE();
|
||||
<span class="token comment">// Don't forget to unsubscribe, typically in componentWillUnmount</span>
|
||||
subscription<span class="token punctuation">.</span><span class="token function">remove</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||||
</code></pre>
|
||||
<p>For more examples of sending events to JavaScript, see <a href="https://github.com/facebook/react-native/blob/master/Libraries/Geolocation/RCTLocationObserver.m"><code>RCTLocationObserver</code></a>.</p>
|
||||
<h3><a class="anchor" aria-hidden="true" id="optimizing-for-zero-listeners"></a><a href="#optimizing-for-zero-listeners" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Optimizing for zero listeners</h3>
|
||||
<p>You will receive a warning if you expend resources unnecessarily by emitting an event while there are no listeners. To avoid this, and to optimize your module's workload (e.g. by unsubscribing from upstream notifications or pausing background tasks), you can override <code>startObserving</code> and <code>stopObserving</code> in your <code>RCTEventEmitter</code> subclass.</p>
|
||||
<pre><code class="hljs css language-objectivec"><span class="hljs-class"><span class="hljs-keyword">@implementation</span> <span class="hljs-title">CalendarManager</span></span>
|
||||
@@ -459,7 +458,7 @@ RCT_EXTERN_METHOD(addEvent:(<span class="hljs-built_in">NSString</span> *)name l
|
||||
</blockquote>
|
||||
<h2><a class="anchor" aria-hidden="true" id="reserved-method-names"></a><a href="#reserved-method-names" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Reserved Method Names</h2>
|
||||
<h3><a class="anchor" aria-hidden="true" id="invalidate"></a><a href="#invalidate" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>invalidate()</h3>
|
||||
<p>Native modules can conform to the <a href="https://github.com/facebook/react-native/blob/aa0ef15335fe27c0c193e3e968789886d82e82ed/React/Base/RCTInvalidating.h">RCTInvalidating</a> protocol on iOS by implementing the <code>invalidate</code> method. This method <a href="https://github.com/facebook/react-native/blob/18e3303cd46a72668caae46e28c7c6ae69fbf8f8/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm#L456">can be invoked</a> when the native bridge is invalidated (ie: on devmode reload). You should avoid implementing this method in general, as this mechanism exists for backwards compatibility and may be removed in the future.</p>
|
||||
<p>Native modules can conform to the <a href="https://github.com/facebook/react-native/blob/master/React/Base/RCTInvalidating.h">RCTInvalidating</a> protocol on iOS by implementing the <code>invalidate</code> method. This method <a href="https://github.com/facebook/react-native/blob/master/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm#L756">can be invoked</a> when the native bridge is invalidated (ie: on devmode reload). You should avoid implementing this method in general, as this mechanism exists for backwards compatibility and may be removed in the future.</p>
|
||||
</span></div></article></div><div class="docs-prevnext"><a class="docs-prev button" href="/docs/next/removing-default-permissions"><span class="arrow-prev">← </span><span>Removing Default Permissions</span></a><a class="docs-next button" href="/docs/next/native-components-ios"><span>Native UI Components</span><span class="arrow-next"> →</span></a></div></div></div><nav class="onPageNav"><ul class="toc-headings"><li><a href="#native-module-setup">Native Module Setup</a></li><li><a href="#ios-calendar-module-example">iOS Calendar Module Example</a></li><li><a href="#argument-types">Argument Types</a></li><li><a href="#callbacks">Callbacks</a></li><li><a href="#promises">Promises</a></li><li><a href="#threading">Threading</a></li><li><a href="#dependency-injection">Dependency Injection</a></li><li><a href="#exporting-constants">Exporting Constants</a><ul class="toc-headings"><li><a href="#implementing--requiresmainqueuesetup">Implementing <code>+ requiresMainQueueSetup</code></a></li><li><a href="#enum-constants">Enum Constants</a></li></ul></li><li><a href="#sending-events-to-javascript">Sending Events to JavaScript</a><ul class="toc-headings"><li><a href="#optimizing-for-zero-listeners">Optimizing for zero listeners</a></li></ul></li><li><a href="#exporting-swift">Exporting Swift</a></li><li><a href="#reserved-method-names">Reserved Method Names</a><ul class="toc-headings"><li><a href="#invalidate">invalidate()</a></li></ul></li></ul></nav></div><footer class="nav-footer" id="footer"><section class="sitemap"><div><h5>Docs</h5><a href="/docs/getting-started.html">Getting Started</a><a href="/docs/tutorial.html">Tutorial</a><a href="/docs/components-and-apis.html">Components and APIs</a><a href="/docs/more-resources.html">More Resources</a></div><div><h5>Community</h5><a href="/help.html">The React Native Community</a><a href="/showcase.html">Who's using React Native?</a><a href="http://stackoverflow.com/questions/tagged/react-native" target="_blank">Ask Questions on Stack Overflow</a><a href="https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md">Contributor Guide</a><a href="https://dev.to/t/reactnative" target="_blank">DEV Community</a></div><div><h5>More Resources</h5><a href="/blog/">Blog</a><a href="https://twitter.com/reactnative" target="_blank">Twitter</a><a href="https://github.com/facebook/react-native" target="_blank">GitHub</a><a href="https://reactjs.org" target="_blank">React</a></div></section><a href="https://code.facebook.com/projects/" target="_blank" class="fbOpenSource"><img src="/img/oss_logo.png" alt="Facebook Open Source" width="170" height="45"/></a><section class="copyright">Copyright © 2020 Facebook Inc.</section></footer></div><script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.js"></script><script>window.fbAsyncInit = function() {FB.init({appId:'1677033832619985',xfbml:true,version:'v2.7'});};(function(d, s, id){var js, fjs = d.getElementsByTagName(s)[0];if (d.getElementById(id)) {return;}js = d.createElement(s); js.id = id;js.src = '//connect.facebook.net/en_US/sdk.js';fjs.parentNode.insertBefore(js, fjs);}(document, 'script','facebook-jssdk'));
|
||||
</script><script>window.twttr=(function(d,s, id){var js,fjs=d.getElementsByTagName(s)[0],t=window.twttr||{};if(d.getElementById(id))return t;js=d.createElement(s);js.id=id;js.src='https://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js, fjs);t._e = [];t.ready = function(f) {t._e.push(f);};return t;}(document, 'script', 'twitter-wjs'));</script><script>
|
||||
document.addEventListener('keyup', function(e) {
|
||||
|
||||
Reference in New Issue
Block a user