-
Notifications
You must be signed in to change notification settings - Fork 38
/
index.js
73 lines (67 loc) · 1.67 KB
/
index.js
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
import React from 'react';
import {
Actions,
DefaultRenderer,
Modal,
ActionConst,
NavBar,
Reducer,
Router as OriginalRouter,
Scene,
Switch,
TabBar,
getInitialState,
Util,
} from 'react-native-router-flux';
import {observer} from "mobx-react/native"
import {autorunAsync, autorun} from 'mobx';
import {InteractionManager} from 'react-native';
const handlers = {};
const originalIterate = Actions.iterate;
function addHandler(root){
if (!handlers[root.key] && root.props.state) {
const state = root.props.state;
state.listener = {
onEnter: (props) => {
console.log("RUN ACTION", root.key);
Actions[root.key](props);
//InteractionManager.runAfterInteractions(()=>Actions[root.key](props));
},
onExit: (props) => {
Actions.pop();
}
};
console.log(`add lister for ${root.key}`)
handlers[root.key] = state.listener;
}
}
Actions.iterate = (root: Scene, parentProps = {}, refsParam = {}, wrapBy) => {
let type = root.props.type || (parentProps.tabs ? ActionConst.JUMP : root.props.state ? ActionConst.PUSH_OR_POP : ActionConst.PUSH);
let list = root.props.children || [];
if (!(list instanceof Array)) {
list = [list];
}
addHandler(root);
list.forEach(addHandler);
return originalIterate({...root, props: {...root.props, type}}, parentProps, refsParam, wrapBy);
}
const Router = observer(({navBar, ...newProps}) => {
if (navBar) {
newProps.navBar = observer(navBar);
}
return <OriginalRouter wrapBy={observer} {...newProps}/>
})
export {
Actions,
ActionConst,
DefaultRenderer,
Modal,
NavBar,
Reducer,
Router,
Scene,
Switch,
TabBar,
getInitialState,
Util,
};