-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathindex.js
135 lines (114 loc) · 4.37 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
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
127
128
129
130
131
132
133
134
135
import * as React from 'react';
import * as navigationModule from 'react-native-navigation';
import * as layoutGenerator from './layoutConverter';
import * as optionsConverter from './optionsConverter';
import { wrapReduxComponent, logExecution } from './utils';
import ScreenVisibilityListener from './ScreenVisibilityListener';
navigationModule.ScreenVisibilityListener = ScreenVisibilityListener;
const Navigation = navigationModule.Navigation;
let appLaunched = false;
const originalRegisterComponent = Navigation.registerComponent.bind(Navigation);
const originalBindComponent = Navigation.events().bindComponent.bind(Navigation);
Navigation.events().bindComponent = (component) => {
if (!component.props.componentId && component.props.navigator) {
component.props = {componentId: component.props.navigator.id, ...component.props};
}
return originalBindComponent(component);
}
Navigation.events().registerAppLaunchedListener(() => {
appLaunched = true;
});
Navigation.startTabBasedApp = ({ tabs, tabsStyle, appStyle, drawer }) => {
const onAppLaunched = () => {
appLaunched = true;
Navigation.setDefaultOptions(optionsConverter.convertStyle({ ...tabsStyle, ...appStyle }));
Navigation.setRoot({ root: layoutGenerator.convertBottomTabs(tabs, drawer) });
}
appLaunched ? onAppLaunched() : Navigation.events().registerAppLaunchedListener(onAppLaunched);
};
Navigation.startSingleScreenApp = ({ screen, tabsStyle, appStyle, drawer, components, passProps }) => {
const onAppLaunched = () => {
appLaunched = true;
Navigation.setDefaultOptions(optionsConverter.convertStyle({ ...tabsStyle, ...appStyle }));
screen.passProps = passProps;
Navigation.setRoot({ root: layoutGenerator.convertSingleScreen(screen, drawer, components) });
}
appLaunched ? onAppLaunched() : Navigation.events().registerAppLaunchedListener(onAppLaunched);
};
Navigation.registerComponent = (name, generator, store, provider) => {
const Wrapped = class extends React.Component {
static get options() {
const Component = generator();
if (Component.options) {
return Component.options;
}
const navigatorStyle = Component.navigatorStyle;
const navigatorButtons = Component.navigatorButtons;
if (navigatorStyle || navigatorButtons) {
return optionsConverter.convertStyle(navigatorStyle, navigatorButtons);
} else {
return undefined;
}
}
constructor(props) {
super(props);
Navigation.events().bindComponent(this);
}
componentDidAppear() {
Navigation.events().registerBottomTabSelectedListener(({selectedTabIndex, unselectedTabIndex}) => {
if (this._isRegisteredToNavigatorEvents()) {
const eventType = selectedTabIndex === unselectedTabIndex ? 'bottomTabReselected' : 'bottomTabSelected';
this.props.navigator.eventFunc({ id: eventType, type: eventType });
}
});
if (this.props && this.props.navigator) {
this.props.navigator.isVisible = true;
}
if (this._isRegisteredToNavigatorEvents()) {
this.props.navigator.eventFunc({ id: 'willAppear' });
this.props.navigator.eventFunc({ id: 'didAppear' });
}
}
componentDidDisappear() {
if (this.props && this.props.navigator) {
this.props.navigator.isVisible = false;
}
if (this._isRegisteredToNavigatorEvents()) {
this.props.navigator.eventFunc({ id: 'willDisappear' });
this.props.navigator.eventFunc({ id: 'didDisappear' });
}
}
navigationButtonPressed({buttonId}) {
if (this._isRegisteredToNavigatorEvents()) {
this.props.navigator.eventFunc(
{
id: buttonId,
type: 'NavBarButtonPress'
}
);
}
}
handleDeepLink(event){
if (this._isRegisteredToNavigatorEvents()) {
this.props.navigator.eventFunc(event);
}
}
_isRegisteredToNavigatorEvents() {
return this.props && this.props.navigator && this.props.navigator.eventListeners.length > 0;
}
render() {
const Component = store ? wrapReduxComponent(generator, store, provider) : generator();
return (
<Component {...this.props} />
);
}
}
originalRegisterComponent(name, () => Wrapped);
};
Navigation.logExecution = () => {
logExecution(Navigation);
};
module.exports = {
Navigation,
ScreenVisibilityListener
};