mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Updated docs for 0.20
This commit is contained in:
1 parent
312698bd16
commit
305982cfb5
102 files changed
+875
-371
No files matched your search
+19
-6
@@ -1,12 +1,25 @@
|
||||
<!DOCTYPE html><html><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><title>IntentAndroid – React Native | A framework for building native apps using React</title><meta name="viewport" content="width=device-width"><meta property="og:title" content="IntentAndroid – React Native | A framework for building native apps using React"><meta property="og:type" content="website"><meta property="og:url" content="http://facebook.github.io/react-native/index.html"><meta property="og:image" content="http://facebook.github.io/react-native/img/opengraph.png?2"><meta property="og:description" content="A framework for building native apps using React"><base href="/react-native/"><link rel="stylesheet" href="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.css"><link rel="shortcut icon" href="img/favicon.png?2"><link rel="stylesheet" href="css/react-native.css"><script type="text/javascript" src="//use.typekit.net/vqa1hcx.js"></script><script type="text/javascript">try{Typekit.load();}catch(e){}</script></head><body><div class="container"><div class="nav-main"><div class="wrap"><a class="nav-home" href=""><img src="img/header_logo.png">React Native</a><a class="nav-version" href="/react-native/versions.html">0.19</a><div class="nav-site-wrapper"><ul class="nav-site nav-site-internal"><li><a href="docs/getting-started.html" class="active">Docs</a></li><li><a href="support.html" class="">Support</a></li><li><a href="https://github.com/facebook/react-native/releases" class="">Releases</a></li><li><a href="http://reactnative.cc" class="">Newsletter</a></li><li><a href="showcase.html" class="">Showcase</a></li></ul><div class="algolia-search-wrapper"><input id="algolia-doc-search" type="text" placeholder="Search docs..."></div><ul class="nav-site nav-site-external"><li><a href="https://github.com/facebook/react-native" class="">GitHub</a></li><li><a href="http://facebook.github.io/react" class="">React</a></li></ul></div></div></div><section class="content wrap documentationContent"><div class="nav-docs"><div class="nav-docs-section"><h3>Quick Start</h3><ul><li><a style="margin-left:0;" class="" href="docs/getting-started.html#content">Getting Started</a></li><li><a style="margin-left:0;" class="" href="docs/android-setup.html#content">Android Setup</a></li><li><a style="margin-left:0;" class="" href="docs/linux-windows-support.html#content">Linux and Windows Support</a></li><li><a style="margin-left:0;" class="" href="docs/tutorial.html#content">Tutorial</a></li><li><a style="margin-left:0;" class="" href="docs/videos.html#content">Videos</a></li></ul></div><div class="nav-docs-section"><h3>Guides</h3><ul><li><a style="margin-left:0;" class="" href="docs/style.html#content">Style</a></li><li><a style="margin-left:0;" class="" href="docs/images.html#content">Images</a></li><li><a style="margin-left:0;" class="" href="docs/gesture-responder-system.html#content">Gesture Responder System</a></li><li><a style="margin-left:0;" class="" href="docs/animations.html#content">Animations</a></li><li><a style="margin-left:0;" class="" href="docs/accessibility.html#content">Accessibility</a></li><li><a style="margin-left:0;" class="" href="docs/direct-manipulation.html#content">Direct Manipulation</a></li><li><a style="margin-left:0;" class="" href="docs/debugging.html#content">Debugging</a></li><li><a style="margin-left:0;" class="" href="docs/testing.html#content">Testing</a></li><li><a style="margin-left:0;" class="" href="docs/javascript-environment.html#content">JavaScript Environment</a></li><li><a style="margin-left:0;" class="" href="docs/navigator-comparison.html#content">Navigator Comparison</a></li><li><a style="margin-left:0;" class="" href="docs/known-issues.html#content">Known Issues</a></li><li><a style="margin-left:0;" class="" href="docs/performance.html#content">Performance</a></li><li><a style="margin-left:0;" class="" href="docs/upgrading.html#content">Upgrading</a></li><li><a style="margin-left:0;" class="" href="docs/platform-specific-code.html#content">Platform Specific Code</a></li></ul></div><div class="nav-docs-section"><h3>Guides (iOS)</h3><ul><li><a style="margin-left:0;" class="" href="docs/native-modules-ios.html#content">Native Modules</a></li><li><a style="margin-left:0;" class="" href="docs/native-components-ios.html#content">Native UI Components</a></li><li><a style="margin-left:0;" class="" href="docs/linking-libraries-ios.html#content">Linking Libraries</a></li><li><a style="margin-left:0;" class="" href="docs/running-on-device-ios.html#content">Running On Device</a></li><li><a style="margin-left:0;" class="" href="docs/embedded-app-ios.html#content">Integrating with Existing Apps</a></li><li><a style="margin-left:0;" class="" href="docs/communication-ios.html#content">Communication between native and React Native</a></li></ul></div><div class="nav-docs-section"><h3>Guides (Android)</h3><ul><li><a style="margin-left:0;" class="" href="docs/native-modules-aLine truncated
|
||||
<!DOCTYPE html><html><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><title>IntentAndroid – React Native | A framework for building native apps using React</title><meta name="viewport" content="width=device-width"><meta property="og:title" content="IntentAndroid – React Native | A framework for building native apps using React"><meta property="og:type" content="website"><meta property="og:url" content="http://facebook.github.io/react-native/index.html"><meta property="og:image" content="http://facebook.github.io/react-native/img/opengraph.png?2"><meta property="og:description" content="A framework for building native apps using React"><base href="/react-native/"><link rel="stylesheet" href="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.css"><link rel="shortcut icon" href="img/favicon.png?2"><link rel="stylesheet" href="css/react-native.css"><script type="text/javascript" src="//use.typekit.net/vqa1hcx.js"></script><script type="text/javascript">try{Typekit.load();}catch(e){}</script></head><body><div class="container"><div class="nav-main"><div class="wrap"><a class="nav-home" href=""><img src="img/header_logo.png">React Native</a><a class="nav-version" href="/react-native/versions.html">0.20</a><div class="nav-site-wrapper"><ul class="nav-site nav-site-internal"><li><a href="docs/getting-started.html" class="active">Docs</a></li><li><a href="support.html" class="">Support</a></li><li><a href="https://github.com/facebook/react-native/releases" class="">Releases</a></li><li><a href="http://reactnative.cc" class="">Newsletter</a></li><li><a href="showcase.html" class="">Showcase</a></li></ul><div class="algolia-search-wrapper"><input id="algolia-doc-search" type="text" placeholder="Search docs..."></div><ul class="nav-site nav-site-external"><li><a href="https://github.com/facebook/react-native" class="">GitHub</a></li><li><a href="http://facebook.github.io/react" class="">React</a></li></ul></div></div></div><section class="content wrap documentationContent"><div class="nav-docs"><div class="nav-docs-section"><h3>Quick Start</h3><ul><li><a style="margin-left:0;" class="" href="docs/getting-started.html#content">Getting Started</a></li><li><a style="margin-left:0;" class="" href="docs/android-setup.html#content">Android Setup</a></li><li><a style="margin-left:0;" class="" href="docs/linux-windows-support.html#content">Linux and Windows Support</a></li><li><a style="margin-left:0;" class="" href="docs/tutorial.html#content">Tutorial</a></li><li><a style="margin-left:0;" class="" href="docs/videos.html#content">Videos</a></li></ul></div><div class="nav-docs-section"><h3>Guides</h3><ul><li><a style="margin-left:0;" class="" href="docs/style.html#content">Style</a></li><li><a style="margin-left:0;" class="" href="docs/images.html#content">Images</a></li><li><a style="margin-left:0;" class="" href="docs/gesture-responder-system.html#content">Gesture Responder System</a></li><li><a style="margin-left:0;" class="" href="docs/animations.html#content">Animations</a></li><li><a style="margin-left:0;" class="" href="docs/accessibility.html#content">Accessibility</a></li><li><a style="margin-left:0;" class="" href="docs/direct-manipulation.html#content">Direct Manipulation</a></li><li><a style="margin-left:0;" class="" href="docs/debugging.html#content">Debugging</a></li><li><a style="margin-left:0;" class="" href="docs/testing.html#content">Testing</a></li><li><a style="margin-left:0;" class="" href="docs/javascript-environment.html#content">JavaScript Environment</a></li><li><a style="margin-left:0;" class="" href="docs/navigator-comparison.html#content">Navigator Comparison</a></li><li><a style="margin-left:0;" class="" href="docs/known-issues.html#content">Known Issues</a></li><li><a style="margin-left:0;" class="" href="docs/performance.html#content">Performance</a></li><li><a style="margin-left:0;" class="" href="docs/upgrading.html#content">Upgrading</a></li><li><a style="margin-left:0;" class="" href="docs/platform-specific-code.html#content">Platform Specific Code</a></li></ul></div><div class="nav-docs-section"><h3>Guides (iOS)</h3><ul><li><a style="margin-left:0;" class="" href="docs/native-modules-ios.html#content">Native Modules</a></li><li><a style="margin-left:0;" class="" href="docs/native-components-ios.html#content">Native UI Components</a></li><li><a style="margin-left:0;" class="" href="docs/linking-libraries-ios.html#content">Linking Libraries</a></li><li><a style="margin-left:0;" class="" href="docs/running-on-device-ios.html#content">Running On Device</a></li><li><a style="margin-left:0;" class="" href="docs/embedded-app-ios.html#content">Integrating with Existing Apps</a></li><li><a style="margin-left:0;" class="" href="docs/communication-ios.html#content">Communication between native and React Native</a></li></ul></div><div class="nav-docs-section"><h3>Guides (Android)</h3><ul><li><a style="margin-left:0;" class="" href="docs/native-modules-aLine truncated
|
||||
access and handle it from any component you want with</p><div class="prism language-javascript"><span class="token function">componentDidMount<span class="token punctuation">(</span></span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
||||
<span class="token keyword">var</span> url <span class="token operator">=</span> IntentAndroid<span class="token punctuation">.</span><span class="token function">getInitialURL<span class="token punctuation">(</span></span>url <span class="token operator">=</span><span class="token operator">></span> <span class="token punctuation">{</span>
|
||||
<span class="token keyword">if</span> <span class="token punctuation">(</span>url<span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
||||
console<span class="token punctuation">.</span><span class="token function">log<span class="token punctuation">(</span></span><span class="token string">'Initial url is: '</span> <span class="token operator">+</span> url<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><p>NOTE: For instructions on how to add support for deep linking,
|
||||
refer <a href="http://developer.android.com/training/app-indexing/deep-linking.html#adding-filters" target="_blank">Enabling Deep Links for App Content - Add Intent Filters for Your Deep Links</a>.</p><h4><a class="anchor" name="opening-external-links"></a>Opening external links <a class="hash-link" href="#opening-external-links">#</a></h4><p>To start the corresponding activity for a link (web URL, email, contact etc.), call</p><div class="prism language-javascript">IntentAndroid<span class="token punctuation">.</span><span class="token function">openURL<span class="token punctuation">(</span></span>url<span class="token punctuation">)</span></div><p>If you want to check if any installed app can handle a given URL beforehand you can call</p><div class="prism language-javascript">IntentAndroid<span class="token punctuation">.</span><span class="token function">canOpenURL<span class="token punctuation">(</span></span>url<span class="token punctuation">,</span> <span class="token punctuation">(</span>supported<span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token punctuation">{</span>
|
||||
<span class="token punctuation">}</span></div><p>Example to add support for deep linking inside your React Native app.
|
||||
More Info: <a href="http://developer.android.com/training/app-indexing/deep-linking.html#adding-filters" target="_blank">Enabling Deep Links for App Content - Add Intent Filters for Your Deep Links</a>.</p><p>Edit in <code>android/app/src/main/AndroidManifest.xml</code></p><div class="prism language-javascript"> <intent<span class="token operator">-</span>filter<span class="token operator">></span>
|
||||
<action android<span class="token punctuation">:</span>name<span class="token operator">=</span><span class="token string">"android.intent.action.VIEW"</span> <span class="token operator">/</span><span class="token operator">></span>
|
||||
<category android<span class="token punctuation">:</span>name<span class="token operator">=</span><span class="token string">"android.intent.category.DEFAULT"</span> <span class="token operator">/</span><span class="token operator">></span>
|
||||
<category android<span class="token punctuation">:</span>name<span class="token operator">=</span><span class="token string">"android.intent.category.BROWSABLE"</span> <span class="token operator">/</span><span class="token operator">></span>
|
||||
|
||||
<<span class="token operator">!</span><span class="token operator">--</span> Accepts URIs that begin <span class="token keyword">with</span> "http<span class="token punctuation">:</span><span class="token operator">/</span><span class="token operator">/</span>www<span class="token punctuation">.</span>facebook<span class="token punctuation">.</span>com<span class="token operator">/</span>react <span class="token operator">--</span><span class="token operator">></span>
|
||||
<data android<span class="token punctuation">:</span>scheme<span class="token operator">=</span><span class="token string">"http"</span>
|
||||
android<span class="token punctuation">:</span>host<span class="token operator">=</span><span class="token string">"www.facebook.com"</span>
|
||||
android<span class="token punctuation">:</span>pathPrefix<span class="token operator">=</span><span class="token string">"/react"</span> <span class="token operator">/</span><span class="token operator">></span>
|
||||
<<span class="token operator">!</span><span class="token operator">--</span> note that the leading <span class="token string">"/"</span> is required <span class="token keyword">for</span> pathPrefix<span class="token operator">--</span><span class="token operator">></span>
|
||||
|
||||
<<span class="token operator">!</span><span class="token operator">--</span> Accepts URIs that begin <span class="token keyword">with</span> "facebook<span class="token punctuation">:</span><span class="token operator">/</span><span class="token operator">/</span>react <span class="token operator">--</span><span class="token operator">></span>
|
||||
<<span class="token operator">!</span><span class="token operator">--</span> <data android<span class="token punctuation">:</span>scheme<span class="token operator">=</span><span class="token string">"facebook"</span> android<span class="token punctuation">:</span>host<span class="token operator">=</span><span class="token string">"react"</span> <span class="token operator">/</span><span class="token operator">></span> <span class="token operator">--</span><span class="token operator">></span>
|
||||
<<span class="token operator">/</span>intent<span class="token operator">-</span>filter<span class="token operator">></span></div><h4><a class="anchor" name="opening-external-links"></a>Opening external links <a class="hash-link" href="#opening-external-links">#</a></h4><p>To start the corresponding activity for a link (web URL, email, contact etc.), call</p><div class="prism language-javascript">IntentAndroid<span class="token punctuation">.</span><span class="token function">openURL<span class="token punctuation">(</span></span>url<span class="token punctuation">)</span></div><p>If you want to check if any installed app can handle a given URL beforehand you can call</p><div class="prism language-javascript">IntentAndroid<span class="token punctuation">.</span><span class="token function">canOpenURL<span class="token punctuation">(</span></span>url<span class="token punctuation">,</span> <span class="token punctuation">(</span>supported<span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token punctuation">{</span>
|
||||
<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>supported<span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
||||
console<span class="token punctuation">.</span><span class="token function">log<span class="token punctuation">(</span></span><span class="token string">'Can\'t handle url: '</span> <span class="token operator">+</span> url<span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||||
<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
|
||||
@@ -15,9 +28,9 @@ refer <a href="http://developer.android.com/training/app-indexing/deep-linking.h
|
||||
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></div></div><span><h3><a class="anchor" name="methods"></a>Methods <a class="hash-link" href="#methods">#</a></h3><div class="props"><div class="prop"><h4 class="propTitle"><a class="anchor" name="openurl"></a><span class="propType">static </span>openURL<span class="propType">(url: string)</span> <a class="hash-link" href="#openurl">#</a></h4><div><p>Starts a corresponding external activity for the given URL.</p><p>For example, if the URL is "<a href="https://www.facebook.com">https://www.facebook.com</a>", the system browser will be opened,
|
||||
or the "choose application" dialog will be shown.</p><p>You can use other URLs, like a location (e.g. "geo:37.484847,-122.148386"), a contact,
|
||||
or any other URL that can be opened with {@code Intent.ACTION_VIEW}.</p><p>NOTE: This method will fail if the system doesn't know how to open the specified URL.
|
||||
If you're passing in a non-http(s) URL, it's best to check {@code canOpenURL} first.</p><p>NOTE: For web URLs, the protocol ("http://", "https://") must be set accordingly!</p></div></div><div class="prop"><h4 class="propTitle"><a class="anchor" name="canopenurl"></a><span class="propType">static </span>canOpenURL<span class="propType">(url: string, callback: Function)</span> <a class="hash-link" href="#canopenurl">#</a></h4><div><p>Determine whether or not an installed app can handle a given URL.</p><p>You can use other URLs, like a location (e.g. "geo:37.484847,-122.148386"), a contact,
|
||||
or any other URL that can be opened with {@code Intent.ACTION_VIEW}.</p><p>NOTE: For web URLs, the protocol ("http://", "https://") must be set accordingly!</p><p>@param URL the URL to open</p></div></div><div class="prop"><h4 class="propTitle"><a class="anchor" name="getinitialurl"></a><span class="propType">static </span>getInitialURL<span class="propType">(callback: Function)</span> <a class="hash-link" href="#getinitialurl">#</a></h4><div><p>If the app launch was triggered by an app link with {@code Intent.ACTION_VIEW},
|
||||
it will give the link url, otherwise it will give <code>null</code></p><p>Refer <a href="http://developer.android.com/training/app-indexing/deep-linking.html#handling-intents">http://developer.android.com/training/app-indexing/deep-linking.html#handling-intents</a></p></div></div></div></span></div><div><h3><a class="anchor" name="examples"></a><a class="edit-github" href="https://github.com/facebook/react-native/blob/master/Examples/UIExplorer/IntentAndroidExample.android.js">Edit on GitHub</a>Examples <a class="hash-link" href="#examples">#</a></h3><div class="prism language-javascript"><span class="token string">'use strict'</span><span class="token punctuation">;</span>
|
||||
If you're passing in a non-http(s) URL, it's best to check {@code canOpenURL} first.</p><p>NOTE: For web URLs, the protocol ("http://", "https://") must be set accordingly!</p><p>@deprecated</p></div></div><div class="prop"><h4 class="propTitle"><a class="anchor" name="canopenurl"></a><span class="propType">static </span>canOpenURL<span class="propType">(url: string, callback: Function)</span> <a class="hash-link" href="#canopenurl">#</a></h4><div><p>Determine whether or not an installed app can handle a given URL.</p><p>You can use other URLs, like a location (e.g. "geo:37.484847,-122.148386"), a contact,
|
||||
or any other URL that can be opened with {@code Intent.ACTION_VIEW}.</p><p>NOTE: For web URLs, the protocol ("http://", "https://") must be set accordingly!</p><p>@param URL the URL to open</p><p>@deprecated</p></div></div><div class="prop"><h4 class="propTitle"><a class="anchor" name="getinitialurl"></a><span class="propType">static </span>getInitialURL<span class="propType">(callback: Function)</span> <a class="hash-link" href="#getinitialurl">#</a></h4><div><p>If the app launch was triggered by an app link with {@code Intent.ACTION_VIEW},
|
||||
it will give the link url, otherwise it will give <code>null</code></p><p>Refer <a href="http://developer.android.com/training/app-indexing/deep-linking.html#handling-intents">http://developer.android.com/training/app-indexing/deep-linking.html#handling-intents</a></p><p>@deprecated</p></div></div></div></span></div><div><table width="100%"><tbody><tr><td><h3><a class="anchor" name="examples"></a>Examples <a class="hash-link" href="#examples">#</a></h3></td><td style="text-align:right;"><a target="_blank" href="https://github.com/facebook/react-native/blob/master/Examples/UIExplorer/IntentAndroidExample.android.js">Edit on GitHub</a></td></tr></tbody></table><div class="prism language-javascript"><span class="token string">'use strict'</span><span class="token punctuation">;</span>
|
||||
|
||||
<span class="token keyword">var</span> React <span class="token operator">=</span> <span class="token function">require<span class="token punctuation">(</span></span><span class="token string">'react-native'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||||
<span class="token keyword">var</span> <span class="token punctuation">{</span>
|
||||
|
||||
Reference in new issue
Block a user