Skip to content

Commit

Permalink
优化Nativehost多bundle加载+
Browse files Browse the repository at this point in the history
  • Loading branch information
smartzhao committed Apr 18, 2018
1 parent 1e9b4a8 commit 73ed7fc
Show file tree
Hide file tree
Showing 161 changed files with 7,458 additions and 8 deletions.
Binary file modified android/.idea/caches/build_file_checksums.ser
Binary file not shown.
3 changes: 2 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:replace="android:name">
<activity android:name=".MainActivity">
<activity android:name=".MainActivity"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
22 changes: 18 additions & 4 deletions android/app/src/main/java/com/zhaochong/android/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.view.View;
import android.widget.Toast;

import com.facebook.react.ReactApplication;
import com.kaopiz.kprogresshud.KProgressHUD;
import com.rnbridge.RNBridgeManager;
import com.rnbridge.callback.RNPushlishMsgListener;
Expand Down Expand Up @@ -43,9 +44,19 @@ protected void onCreate(Bundle savedInstanceState) {
showRxPermissions();
}

@Override
protected void onResume() {
super.onResume();
Log.d(TAG, "onResume: ");
}

protected void onPause() {
super.onPause();
Log.d(TAG, "onPause: ");
}

protected void onStop() {
super.onStop();
Log.d(TAG, "onStop: ");
}

@Override
Expand All @@ -60,11 +71,11 @@ public void onWindowFocusChanged(boolean hasFocus) {
"index.VPCenter.bundle",
((ReactApplication)getApplication()).getReactNativeHost().getReactInstanceManager(),
bundle);*/
/* RNBridgeManager.getInstance().preLoad(MainActivity.this,
RNBridgeManager.getInstance().preLoad(MainActivity.this,
"RnBase",
"index.dataMall.bundle",
((ReactApplication)getApplication()).getReactNativeHost().getReactInstanceManager(),
bundle);*/
bundle);
}
}

Expand Down Expand Up @@ -164,7 +175,9 @@ public String rnCallNativeFromCallback(String msg, String params) {

@Override
public void rnCallNative(String s, String s1) {
RNBridgeManager.destoryActivity("BaseReactActivity");
// RNBridgeManager.destoryActivity("BaseReactActivity");
Intent intent = new Intent(MainActivity.this, MainActivity.class);
startActivity(intent);

}
})
Expand Down Expand Up @@ -223,6 +236,7 @@ public void accept(Permission permission) throws Exception {
protected void onDestroy() {
super.onDestroy();
unregisterReceiver(localReceiver);
Log.d(TAG, "onDestroy: ");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ private ReactNativeHost getReactNativeHost() {
* @return
*/
private ReactInstanceManager getReactInstanceManager() {
return getReactNativeHost().getReactInstanceManager();
return RNBridgeManager.getInstance().getReactNativeHost().getReactInstanceManager();
}


Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 68 additions & 0 deletions rn/VPCenter/AppWithNavigationState.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* Created by zhaochong on 2017/12/15.
*/
import React, {Component} from 'react';
import {
BackAndroid,
Platform, NativeModules, NativeEventEmitter, DeviceEventEmitter, ToastAndroid
} from 'react-native';

import {connect} from 'react-redux';
import {addNavigationHelpers} from 'react-navigation';
import MemberRouters from './routers/memberRouters'

class AppWithNavigationState extends Component {
componentWillMount() {
// ToastAndroid.show("发送成功" +NativeModules.commModule.RNContants, ToastAndroid.SHORT);
/* NativeModules.commModule.rnCallNativeFromPromise("zhaochong").then(
(result) =>{
ToastAndroid.show("Promise收到消息:" + result, ToastAndroid.SHORT)
}
).catch((error) =>{console.log(error)});*/

/* DeviceEventEmitter.addListener('Payeco_Event',(msg)=>{
let title = "React Native界面,收到数据:会员中心" + msg;
ToastAndroid.show("发送成功" +title, ToastAndroid.SHORT);
})*/

/* NativeModules.commModule.rnCallNativeFromCallback("zhaochong",(result) => {
ToastAndroid.show("CallBack收到消息:" + result, ToastAndroid.SHORT);
})*/

//进入RN界面存下认证等相关信息
let author = {
Authorization: this.props.params.accessToken,
uId: this.props.params.userId
}
console.log('%%%%%%%%%%%%%', this.props.params, this.props);
this.props.dispatch({type: 'AUTH_INFO', data: author})
console.log('收到事件', author)
}


componentWillUnmount() {

}


render() {
const {dispatch, nav, params} = this.props;
//console.log('%%%%%%%%%%%%%',nav);
return (
<MemberRouters navigation={addNavigationHelpers({
dispatch: dispatch,
state: nav
})}
/>
);
}
}

function mapStateToProps(state) {
const {nav} = state;
return {
nav
}
}

export default connect(mapStateToProps)(AppWithNavigationState);
51 changes: 51 additions & 0 deletions rn/VPCenter/action/VpCenterAction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Created by zhaochong on 2018/1/1.
*/

'use strict';

//获取banner图列表
import request from "../api/request";
import * as types from "../../VPCenter/constants/VPCenterActionType";

export function getBanners(){
console.log('^^^^^1111^^^^^^12122');
return dispatch =>{
return request.get(`user/promotion`)
.then(data=>{
console.log('^^^^^^^^^^^12122',data.data.image);
dispatch({type:types.VPCENTER_BANNER,data:data.data});//
})
.catch(response =>{

});
}
}
//获取成长值明细
export function getVpGrowthDetails(params){
return dispatch =>{
return request.get(`integration/log`,{params:params})
.then(data=>{
console.log('^^^^^^^^^^^',data);
dispatch({type:types.VPCENTER_VPGROWTHDETAILSLIST,data:data.data});//
})
.catch(response =>{

});
}
}
//获取会员规则说明
export function getVPInstructions(params){
return dispatch =>{
return request.get(`member/info`,{params:params})
.then(data=>{
console.log('^^^^^^^^^^^data.rules',data.rules);
dispatch({type:types.VPCENTER_VPINSTRUCTION,data:data.data});//
})
.catch(response =>{
/* if(response){
alert(response)
}*/
});
}
}
43 changes: 43 additions & 0 deletions rn/VPCenter/api/request.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Created by zhaochong on 2018/1/1.
*/
'use strict';
import axios from 'axios';
import * as configs from "../constants/configs";
import store from "../../VPCenter/store/createStore";

const httpConfig={
baseURL:__DEV__? configs.API_DEV:configs.API_PRO,
headers: {
'Content-type': 'application/json',
'Accept': 'application/json;responseformat=3',
// 'Authorization': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMDAwMDgwIiwiYXVkIjoiYnJvd3NlciIsImlhdCI6MTUxNDI3NTE0MSwibmJmIjoxNTE0Mjc1MTQxLCJleHAiOjE1MjIwNTExNDEsImlzcyI6ImVjYXJ4IiwianRpIjoxNTE0Mjc1MTQxLCJjbGllbnRJZCI6ImJyb3dzZXIiLCJ1aWQiOiIxMDAwMDgwIiwiZW52IjoidGVzdGluZyJ9.XxKP0LqTLa1tUeoCu7TNipr01W_KaK_AXtCutrSri-o',
'X-STORE': 'FLOW',
'X-ENV-TYPE':__DEV__? configs.ENV_TYPE_DEV:configs.ENV_TYPE_PRO,
'X-APP-ID':'M820igii5lL4tcy'


},
timeout: __DEV__? configs.API_TIMEOUT_DEV:configs.API_TIMEOUT_PRO
};

const request=axios.create(httpConfig);

request.interceptors.request.use(config=>{
let commonData = store.getState().commonData;
console.log('---store---',commonData);
config.headers.Authorization = commonData.authInfo.Authorization;
return config;
});

request.interceptors.response.use(response=>{
//console.log("************************",response);
if(response.status==200){
return response.data;
}
return response;

});


export default request;
78 changes: 78 additions & 0 deletions rn/VPCenter/common/ListRequest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* Copyright (c) 2017-present, Liu Jinyong
* All rights reserved.
*
* https://github.com/huanxsd/MeiTuan
* @flow
*/

import { urlByAppendingParams } from './tool'

const kFirstPage = 1
const kCurrentPageKey = 'page'
const kPageSizeKey = 'count'
const kPageSize = 20
const kDefaultListNode = 'list'
const host = ''

class ListRequest {
requestNode: string
isFirstLoad: boolean
dataList: Array<Object>
isReload: boolean
currentPage: number
noMoreData: boolean
onSuccess: function
onFailure: function

constructor(requestNode: string) {
this.requestNode = requestNode
this.isFirstLoad = true
this.dataList = []
this.isReload = true
this.currentPage = kFirstPage
this.noMoreData = false
}

requestFirstPage(params: Object) {
this.isReload = true
this.startRequest(params, kFirstPage)
}

requestNextPage(params: Object) {
this.isReload = false
this.startRequest(params, this.currentPage + 1)
}

startRequest(params: Object, page: number) {
let requestParams = { ...params }
requestParams[kCurrentPageKey] = page
requestParams[kPageSizeKey] = kPageSize

let url = urlByAppendingParams(host + this.requestNode, requestParams);
fetch(url)
.then((response) => {
return response.json()
})
.then((json) => {
if (this.isReload) {
this.dataList = json.items
} else {
this.dataList.push(...json.items)
}
this.currentPage = page
this.noMoreData = json.items.count < kPageSize

this.onSuccess && this.onSuccess()

console.log(`ListRequest - Success node:${this.requestNode}`);
}).catch((error) => {
if (this.onFailure) {
this.onFailure()
}
console.log(`ListRequest - Error node:${this.requestNode} error:${error}`);
});
}
}

export default ListRequest;
13 changes: 13 additions & 0 deletions rn/VPCenter/common/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Copyright (c) 2017-present, Liu Jinyong
* All rights reserved.
*
* https://github.com/huanxsd/MeiTuan
* @flow
*/

import screen from './screen'
import system from './system'
import tool from './tool'

export {screen, system, tool}
16 changes: 16 additions & 0 deletions rn/VPCenter/common/screen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Copyright (c) 2017-present, Liu Jinyong
* All rights reserved.
*
* https://github.com/huanxsd/MeiTuan
* @flow
*/

import { Dimensions, Platform, PixelRatio } from 'react-native'

export default {
width: Dimensions.get('window').width,
height: Dimensions.get('window').height,
onePixel: 1 / PixelRatio.get(),
statusBarHeight: (Platform.OS === 'ios' ? 20 : 0)
}
15 changes: 15 additions & 0 deletions rn/VPCenter/common/system.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Copyright (c) 2017-present, Liu Jinyong
* All rights reserved.
*
* https://github.com/huanxsd/MeiTuan
* @flow
*/

// System
import { Platform } from 'react-native'

export default {
isIOS: Platform.OS === 'ios',

}
Loading

0 comments on commit 73ed7fc

Please sign in to comment.