Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Commit ccae1af

Browse files
authored
Merge pull request #1107 from lightninglabs/dev/prevent-back-navigation-from-home
Dev/prevent back navigation from home
2 parents f39cb66 + 0431275 commit ccae1af

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

src/action/index-mobile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
// NativeEventEmitter,
1616
} from 'react-native';
1717
import { SecureStore, LocalAuthentication, Linking } from 'expo';
18-
import { NavigationActions } from 'react-navigation';
18+
import { NavigationActions, StackActions } from 'react-navigation';
1919
import { nap } from '../helper';
2020
import store from '../store';
2121
import AppStorage from './app-storage';
@@ -47,7 +47,7 @@ export const grpc = sinon.createStubInstance(GrpcAction); // STUB DURING DEVELOP
4747
// export const ipc = new IpcAction(grpc);
4848
export const ipc = sinon.createStubInstance(IpcAction); // STUB DURING DEVELOPMENT
4949
export const log = new LogAction(store, ipc, false);
50-
export const nav = new NavAction(store, NavigationActions);
50+
export const nav = new NavAction(store, NavigationActions, StackActions);
5151
export const notify = new NotificationAction(store, nav);
5252
export const wallet = new WalletAction(store, grpc, db, nav, notify);
5353
export const info = new InfoAction(store, grpc, nav, notify);

src/action/nav-mobile.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,29 @@
55
*/
66

77
class NavAction {
8-
constructor(store, Navigation) {
8+
constructor(store, NavigationActions, StackActions) {
99
this._store = store;
10-
this._Navigation = Navigation;
10+
this._navActions = NavigationActions;
11+
this._stackActions = StackActions;
1112
}
1213

1314
setTopLevelNavigator(navigatorRef) {
14-
this._navigate = (routeName, params) =>
15-
navigatorRef.dispatch(this._Navigation.navigate({ routeName, params }));
15+
this._navigate = routeName =>
16+
navigatorRef.dispatch(this._navActions.navigate({ routeName }));
17+
18+
this._reset = (stackName, routeName) =>
19+
navigatorRef.dispatch(
20+
this._stackActions.reset({
21+
index: 0,
22+
actions: [
23+
this._navActions.navigate({
24+
routeName: stackName,
25+
action: this._navActions.navigate({ routeName }),
26+
}),
27+
],
28+
})
29+
);
30+
1631
this._store.navReady = true;
1732
}
1833

@@ -70,6 +85,7 @@ class NavAction {
7085

7186
goLoaderSyncing() {
7287
this._navigate('LoaderSyncing');
88+
this._reset('Main', 'LoaderSyncing');
7389
}
7490

7591
goWait() {
@@ -78,6 +94,7 @@ class NavAction {
7894

7995
goHome() {
8096
this._navigate('Home');
97+
this._reset('Main', 'Home');
8198
}
8299

83100
goPay() {

src/view/main-mobile.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,6 @@ const MainStack = createStackNavigator(
194194
Password,
195195
LoaderSyncing,
196196
Home,
197-
Settings,
198-
SettingsUnit,
199-
SettingsFiat,
200-
CLI,
201-
Notifications,
202197
},
203198
stackOptions
204199
);
@@ -243,13 +238,25 @@ const ChannelStack = createStackNavigator(
243238
stackOptions
244239
);
245240

241+
const SettingStack = createStackNavigator(
242+
{
243+
Settings,
244+
SettingsUnit,
245+
SettingsFiat,
246+
CLI,
247+
Notifications,
248+
},
249+
stackOptions
250+
);
251+
246252
const RootStack = createStackNavigator(
247253
{
248254
Main: MainStack,
249255
Invoice: InvoiceStack,
250256
Pay: PayStack,
251257
Transactions: TransactionStack,
252258
Channels: ChannelStack,
259+
Settings: SettingStack,
253260
Deposit,
254261
},
255262
{

0 commit comments

Comments
 (0)