2017-11-13 13:35:01 +00:00
|
|
|
import { NavigationActions } from 'react-navigation';
|
|
|
|
|
|
|
|
const config = {};
|
|
|
|
|
|
|
|
export function setNavigator(nav) {
|
|
|
|
if (nav) {
|
|
|
|
config.navigator = nav;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function navigate(routeName, params) {
|
|
|
|
if (config.navigator && routeName) {
|
2018-04-10 13:03:54 +00:00
|
|
|
const action = NavigationActions.navigate({ key: routeName, routeName, params });
|
2017-11-13 13:35:01 +00:00
|
|
|
config.navigator.dispatch(action);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function goBack() {
|
|
|
|
if (config.navigator) {
|
|
|
|
const action = NavigationActions.back({});
|
|
|
|
config.navigator.dispatch(action);
|
|
|
|
}
|
|
|
|
}
|
2017-11-28 17:47:56 +00:00
|
|
|
|
2018-03-23 16:49:51 +00:00
|
|
|
export function goRoomsList() {
|
|
|
|
if (config.navigator) {
|
|
|
|
const action = NavigationActions.reset({
|
|
|
|
index: 0,
|
2018-04-10 13:03:54 +00:00
|
|
|
actions: [NavigationActions.navigate({ key: 'RoomsList', routeName: 'RoomsList' })]
|
2018-03-23 16:49:51 +00:00
|
|
|
});
|
|
|
|
config.navigator.dispatch(action);
|
|
|
|
}
|
|
|
|
}
|
2017-11-28 17:47:56 +00:00
|
|
|
|
|
|
|
export function goRoom({ rid, name }, counter = 0) {
|
|
|
|
// about counter: we can call this method before navigator be set. so we have to wait, if we tried a lot, we give up ...
|
2018-05-07 20:43:26 +00:00
|
|
|
if (!rid || counter > 10) {
|
2017-11-28 17:47:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!config.navigator) {
|
2018-03-02 21:31:44 +00:00
|
|
|
return setTimeout(() => goRoom({ rid, name }, counter + 1), 100);
|
2017-11-28 17:47:56 +00:00
|
|
|
}
|
2017-12-01 15:06:56 +00:00
|
|
|
|
2017-11-28 17:47:56 +00:00
|
|
|
const action = NavigationActions.reset({
|
|
|
|
index: 1,
|
|
|
|
actions: [
|
2018-04-10 13:03:54 +00:00
|
|
|
NavigationActions.navigate({ key: 'RoomsList', routeName: 'RoomsList' }),
|
|
|
|
NavigationActions.navigate({ key: `Room-${ rid }`, routeName: 'Room', params: { room: { rid, name }, rid, name } })
|
2017-11-28 17:47:56 +00:00
|
|
|
]
|
|
|
|
});
|
2018-03-02 21:31:44 +00:00
|
|
|
config.navigator.dispatch(action);
|
2017-11-28 17:47:56 +00:00
|
|
|
}
|
2018-04-24 19:34:03 +00:00
|
|
|
|
|
|
|
export function dispatch(action) {
|
|
|
|
if (config.navigator) {
|
|
|
|
config.navigator.dispatch(action);
|
|
|
|
}
|
|
|
|
}
|