国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

ReactNative嵌入到現(xiàn)有原生安卓應(yīng)用

2019-11-09 18:43:41
字體:
供稿:網(wǎng)友

嵌入到現(xiàn)有原生應(yīng)用

嵌入到現(xiàn)有原生應(yīng)用

簡書:React Native起步-將RN嵌入到現(xiàn)有的Android應(yīng)用中

CSDN:Android原生嵌入React Native 過程中遇見的各種坑

build.gradle

allPRojects { repositories { mavenLocal() jcenter() maven { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm url "$rootDir/../reactNativeTest/node_modules/react-native/android" } }}

修改app/build.gradle

ndk { abiFilters "armeabi-v7a", "x86"}compile "com.facebook.react:react-native:+"

創(chuàng)建 ReactActivity

package com.cyb.reactnativetestproj;import android.app.Activity;import android.os.Bundle;import android.view.KeyEvent;import com.facebook.react.ReactInstanceManager;import com.facebook.react.ReactRootView;import com.facebook.react.common.LifecycleState;import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;import com.facebook.react.shell.MainReactPackage;/** * ReactNative * Created by cyb on 2016/11/26. */public class ReactActivity extends Activity implements DefaultHardwareBackBtnHandler{ private ReactRootView mReactRootView; private ReactInstanceManager mReactInstanceManager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mReactRootView = new ReactRootView(this); mReactInstanceManager = ReactInstanceManager.builder() .setapplication(getApplication()) .setBundleAssetName("index.android.bundle") .setJSMainModuleName("index.android") .addPackage(new MainReactPackage()) .setUseDeveloperSupport(BuildConfig.DEBUG) .setInitialLifecycleState(LifecycleState.RESUMED) .build(); mReactRootView.startReactApplication(mReactInstanceManager, "reactNativeTest", null); setContentView(mReactRootView); } @Override public void invokeDefaultOnBackPressed() { super.onBackPressed(); } @Override public void onBackPressed() { super.onBackPressed(); if(mReactInstanceManager != null){ mReactInstanceManager.onBackPressed(); } } @Override protected void onResume() { super.onResume(); if(mReactInstanceManager != null){ mReactInstanceManager.onHostResume(this, this); } } @Override protected void onPause() { super.onPause(); if(mReactInstanceManager != null){ mReactInstanceManager.onHostPause(this); } } @Override protected void onDestroy() { super.onDestroy(); if(mReactInstanceManager != null){ mReactInstanceManager.onHostDestroy(this); } } //我們需要改動(dòng)一下開發(fā)者菜單。默認(rèn)情況下,任何開發(fā)者菜單都可以通過搖晃或者設(shè)備類觸發(fā) // ,不過這對(duì)模擬器不是很有用。所以我們讓它在按下Menu鍵的時(shí)候可以顯示 @Override public boolean onKeyUp(int keyCode, KeyEvent event) { if(keyCode == KeyEvent.KEYCODE_MENU && mReactInstanceManager != null){ mReactInstanceManager.showDevOptionsDialog(); return true; } return super.onKeyUp(keyCode, event); }}
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 偃师市| 黄浦区| 天津市| 洪洞县| 永福县| 大名县| 丽江市| 安乡县| 平山县| 长岛县| 柳江县| 马龙县| 古交市| 塔城市| 基隆市| 库尔勒市| 延长县| 南雄市| 通许县| 台南市| 微山县| 黄大仙区| 阜宁县| 双柏县| 东乌| 鹿泉市| 丰镇市| 涡阳县| 巴南区| 丹巴县| 祥云县| 商水县| 老河口市| 林周县| 胶南市| 同仁县| 东港市| 桃江县| 长垣县| 景德镇市| 沈丘县|