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:
@@ -87,6 +87,7 @@ target <span class="token string">'NumberTileGame'</span> <span class=
|
||||
pod <span class="token string">'React'</span><span class="token punctuation">,</span> <span class="token punctuation">:</span>path <span class="token operator">=</span><span class="token operator">></span> <span class="token string">'../node_modules/react-native'</span><span class="token punctuation">,</span> <span class="token punctuation">:</span>subspecs <span class="token operator">=</span><span class="token operator">></span> <span class="token punctuation">[</span>
|
||||
<span class="token string">'Core'</span><span class="token punctuation">,</span>
|
||||
<span class="token string">'RCTText'</span><span class="token punctuation">,</span>
|
||||
<span class="token string">'RCTNetwork'</span><span class="token punctuation">,</span>
|
||||
<span class="token string">'RCTWebSocket'</span><span class="token punctuation">,</span> # needed <span class="token keyword">for</span> debugging
|
||||
# Add any other subspecs you want to use <span class="token keyword">in</span> your project
|
||||
<span class="token punctuation">]</span>
|
||||
@@ -107,6 +108,7 @@ target <span class="token string">'swift-2048'</span> <span class="tok
|
||||
pod <span class="token string">'React'</span><span class="token punctuation">,</span> <span class="token punctuation">:</span>path <span class="token operator">=</span><span class="token operator">></span> <span class="token string">'../node_modules/react-native'</span><span class="token punctuation">,</span> <span class="token punctuation">:</span>subspecs <span class="token operator">=</span><span class="token operator">></span> <span class="token punctuation">[</span>
|
||||
<span class="token string">'Core'</span><span class="token punctuation">,</span>
|
||||
<span class="token string">'RCTText'</span><span class="token punctuation">,</span>
|
||||
<span class="token string">'RCTNetwork'</span><span class="token punctuation">,</span>
|
||||
<span class="token string">'RCTWebSocket'</span><span class="token punctuation">,</span> # needed <span class="token keyword">for</span> debugging
|
||||
# Add any other subspecs you want to use <span class="token keyword">in</span> your project
|
||||
<span class="token punctuation">]</span>
|
||||
@@ -289,7 +291,7 @@ AppRegistry<span class="token punctuation">.</span><span class="token function">
|
||||
<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>Make sure that the path is correct! You shouldn’t run into any “Failed to resolve: com.facebook.react:react-native:0.x.x" errors after running Gradle sync in Android Studio.</p></blockquote><p>Next, make sure you have the Internet permission in your <code>AndroidManifest.xml</code>:</p><div class="prism language-javascript"><uses<span class="token operator">-</span>permission android<span class="token punctuation">:</span>name<span class="token operator">=</span><span class="token string">"android.permission.INTERNET"</span> <span class="token operator">/</span><span class="token operator">></span></div><p>This is only really used in dev mode when reloading JavaScript from the development server, so you can strip this in release builds if you need to.</p><h2><a class="anchor" name="add-native-code"></a>Add native code <a class="hash-link" href="docs/integration-with-existing-apps.html#add-native-code">#</a></h2><p>You need to add some native code in order to start the React Native runtime and get it to render something. To do this, we're going to create an <code>Activity</code> that creates a <code>ReactRootView</code>, starts a React application inside it and sets it as the main content view.</p><blockquote><p>If you are targetting Android version <5, use the <code>AppCompatActivity</code> class from the <code>com.android.support:appcompat</code> package instead of <code>Activity</code>.</p><p>If you find out later that your app crashes due to <code>Didn't find class "com.facebook.jni.IteratorHelper"</code> exception, uncomment the <code>setUseOldBridge</code> line. <a href="https://github.com/facebook/react-native/issues/8701" target="_blank">See related issue on GitHub.</a></p></blockquote><div class="prism language-javascript">public class <span class="token class-name">MyReactActivity</span> extends <span class="token class-name">Activity</span> implements <span class="token class-name">DefaultHardwareBackBtnHandler</span> <span class="token punctuation">{</span>
|
||||
<span class="token punctuation">}</span></div><blockquote><p>Make sure that the path is correct! You shouldn’t run into any “Failed to resolve: com.facebook.react:react-native:0.x.x" errors after running Gradle sync in Android Studio.</p></blockquote><p>Next, make sure you have the Internet permission in your <code>AndroidManifest.xml</code>:</p><div class="prism language-javascript"><uses<span class="token operator">-</span>permission android<span class="token punctuation">:</span>name<span class="token operator">=</span><span class="token string">"android.permission.INTERNET"</span> <span class="token operator">/</span><span class="token operator">></span></div><p>This is only really used in dev mode when reloading JavaScript from the development server, so you can strip this in release builds if you need to.</p><h2><a class="anchor" name="add-native-code"></a>Add native code <a class="hash-link" href="docs/integration-with-existing-apps.html#add-native-code">#</a></h2><p>You need to add some native code in order to start the React Native runtime and get it to render something. To do this, we're going to create an <code>Activity</code> that creates a <code>ReactRootView</code>, starts a React application inside it and sets it as the main content view.</p><blockquote><p>If you are targetting Android version <5, use the <code>AppCompatActivity</code> class from the <code>com.android.support:appcompat</code> package instead of <code>Activity</code>.</p></blockquote><div class="prism language-javascript">public class <span class="token class-name">MyReactActivity</span> extends <span class="token class-name">Activity</span> implements <span class="token class-name">DefaultHardwareBackBtnHandler</span> <span class="token punctuation">{</span>
|
||||
private ReactRootView mReactRootView<span class="token punctuation">;</span>
|
||||
private ReactInstanceManager mReactInstanceManager<span class="token punctuation">;</span>
|
||||
|
||||
@@ -305,8 +307,7 @@ AppRegistry<span class="token punctuation">.</span><span class="token function">
|
||||
<span class="token punctuation">.</span><span class="token function">addPackage<span class="token punctuation">(</span></span><span class="token keyword">new</span> <span class="token class-name">MainReactPackage</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
|
||||
<span class="token punctuation">.</span><span class="token function">setUseDeveloperSupport<span class="token punctuation">(</span></span>BuildConfig<span class="token punctuation">.</span>DEBUG<span class="token punctuation">)</span>
|
||||
<span class="token punctuation">.</span><span class="token function">setInitialLifecycleState<span class="token punctuation">(</span></span>LifecycleState<span class="token punctuation">.</span>RESUMED<span class="token punctuation">)</span>
|
||||
<span class="token comment" spellcheck="true"> //.setUseOldBridge(true) // uncomment this line if your app crashes
|
||||
</span> <span class="token punctuation">.</span><span class="token function">build<span class="token punctuation">(</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||||
<span class="token punctuation">.</span><span class="token function">build<span class="token punctuation">(</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||||
mReactRootView<span class="token punctuation">.</span><span class="token function">startReactApplication<span class="token punctuation">(</span></span>mReactInstanceManager<span class="token punctuation">,</span> <span class="token string">"HelloWorld"</span><span class="token punctuation">,</span> <span class="token keyword">null</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||||
|
||||
<span class="token function">setContentView<span class="token punctuation">(</span></span>mReactRootView<span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||||
|
||||
Reference in New Issue
Block a user