Skip to content

Commit 29015b8

Browse files
committed
1. 为WebView添加加载提示
2. 提交全局navigation
1 parent d2af2bc commit 29015b8

File tree

4 files changed

+46
-5
lines changed

4 files changed

+46
-5
lines changed

app/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import * as rootStore from './store/RootStore';
1111

1212
import SplashScreen from 'react-native-splash-screen';
1313
import { StoreContext } from './utils/Tool';
14+
import NavigationModule from './utils/NavigationMoudle';
1415

1516
const navigationPersistenceKey = __DEV__ ? 'NavigationStateDEV' : null;
1617
let lastBackPressed: number;
@@ -45,6 +46,9 @@ function index() {
4546
<AuthLoadingRouter
4647
// persistenceKey={navigationPersistenceKey}
4748
renderLoadingExperimental={() => <ActivityIndicator size="large" color="black" />}
49+
ref={navigatorRef => {
50+
NavigationModule.setNavigatorRef(navigatorRef);
51+
}}
4852
onNavigationStateChange={(prevState, currentState) => {
4953
const AppRouter = currentState.routes[1];
5054
if (AppRouter.routes && AppRouter.routes.length > 1) {

app/pages/News/Welfare/index_old.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { ActionSheet, Overlay } from 'teaset';
1919
import { inject } from 'mobx-react';
2020

2121
type Props = {
22-
navigate: NavigationState,
22+
navigate: NavigationState
2323
};
2424

2525
@inject('shiTuStore')

app/pages/WebView/index.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import ActionButton from 'react-native-action-button';
1313
import Icon from 'react-native-vector-icons/Ionicons';
1414
import { Theme } from 'teaset';
1515
import BaseContainer from '../../components/BaseContainer';
16-
import { inject } from 'mobx-react';
16+
import { StoreContext } from '../../utils/Tool';
1717

1818
type Props = {
1919
uri?: string,
@@ -31,6 +31,7 @@ type State = {
3131
// @inject('configStore')
3232
export default class index extends React.Component<Props, State> {
3333
webView: WebView;
34+
static contextType = {};
3435

3536
constructor(props: Props) {
3637
super(props);
@@ -48,6 +49,11 @@ export default class index extends React.Component<Props, State> {
4849
};
4950
}
5051

52+
componentDidMount(): void {
53+
const { configStore } = this.context;
54+
configStore.showLoading();
55+
}
56+
5157
componentWillUnmount() {
5258
// this.props.configStore.hideLoading();
5359
StatusBar.setHidden(false);
@@ -110,14 +116,17 @@ export default class index extends React.Component<Props, State> {
110116
};
111117
onLoadEnd = () => {
112118
console.log('加载结束,成功或失败都会走到这里');
113-
// this.props.configStore.hideLoading();
119+
const { configStore } = this.context;
120+
configStore.hideLoading();
114121
};
115122
onLoadStart = () => {
116123
console.log('开始加载');
117-
// this.props.configStore.showLoading();
124+
// const {configStore} = this.context;
125+
// configStore.showLoading();
118126
};
119127
onError = () => {
120-
// this.props.configStore.hideLoading();
128+
const { configStore } = this.context;
129+
configStore.hideLoading();
121130
Alert.alert(
122131
'加载失败',
123132
null,
@@ -208,6 +217,8 @@ export default class index extends React.Component<Props, State> {
208217
}
209218
}
210219

220+
index.contextType = StoreContext;
221+
211222
const styles = StyleSheet.create({
212223
container: {
213224
flex: 1,

app/utils/NavigationMoudle.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @flow
3+
* Created by Rabbit on 2019/04/08.
4+
*/
5+
6+
import { NavigationActions } from 'react-navigation';
7+
8+
let _navigator;
9+
10+
function setNavigatorRef(navigatorRef) {
11+
_navigator = navigatorRef;
12+
}
13+
14+
function navigate(routeName, params) {
15+
_navigator.dispatch(
16+
NavigationActions.navigate({
17+
routeName,
18+
params,
19+
})
20+
);
21+
}
22+
23+
export default {
24+
navigate,
25+
setNavigatorRef,
26+
};

0 commit comments

Comments
 (0)