forked from osdio/noder-react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRouter.js
More file actions
126 lines (100 loc) · 2.49 KB
/
Router.js
File metadata and controls
126 lines (100 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import React from 'react';
import ReactNative from 'react-native';
import {Navigator, Platform, BackAndroid} from 'react-native';
import _ from 'lodash';
import * as About from '../layouts/About';
import * as QRCode from '../layouts/QRCode';
import * as Login from '../layouts/Login';
import * as User from '../layouts/User';
import * as Message from '../layouts/Message';
import * as Topic from '../layouts/Topic';
import * as Comment from '../layouts/Comment';
import * as Publish from '../layouts/Publish';
import * as HomeComponent from '../layouts/Home';
import * as CustomSceneConfigs from '../configs/sceneConfig';
import connectComponent from '../utils/connectComponent';
const Home = connectComponent(HomeComponent);
const {
SceneConfigs,
} = ReactNative;
class Router {
constructor(navigator) {
this.navigator = navigator;
if (Platform.OS === 'android') {
BackAndroid.addEventListener('hardwareBackPress', ()=> {
const routesList = this.navigator.getCurrentRoutes();
const currentRoute = routesList[routesList.length - 1];
if (currentRoute.name !== 'home') {
navigator.pop();
return true;
}
return false;
});
}
}
push(props = {}, route) {
let routesList = this.navigator.getCurrentRoutes();
let nextIndex = routesList[routesList.length - 1].index + 1;
route.props = props;
route.index = nextIndex;
route.sceneConfig = route.sceneConfig ? route.sceneConfig : CustomSceneConfigs.customFloatFromRight;
route.id = _.uniqueId();
route.component = connectComponent(route.component);
this.navigator.push(route);
}
pop() {
this.navigator.pop();
}
toAbout(props) {
this.push(props, {
component: About,
name: 'about',
sceneConfig: CustomSceneConfigs.customFloatFromBottom
});
}
toLogin(props) {
this.push(props, {
component: Login,
name: 'login',
sceneConfig: CustomSceneConfigs.customFloatFromBottom
})
}
toQRCode(props) {
this.push(props, {
component: QRCode,
name: 'qrcode',
sceneConfig: CustomSceneConfigs.customFloatFromBottom
});
}
toUser(props) {
this.push(props, {
component: User,
name: 'user'
});
}
toMessage(props) {
this.push(props, {
component: Message,
name: 'message'
})
}
toTopic(props) {
this.push(props, {
component: Topic,
name: 'topic'
})
}
toComment(props) {
this.push(props, {
component: Comment,
name: 'comment'
})
}
toPublish(props) {
this.push(props, {
component: Publish,
name: 'publish'
})
}
}
export default Router;