@@ -10,7 +10,7 @@ import { SafeAreaView } from "react-native-safe-area-context";
10
10
import { Flex } from "@ledgerhq/native-ui" ;
11
11
import type { BaseNavigatorStackParamList } from "../../components/RootNavigator/BaseNavigator" ;
12
12
import RequiresBLE from "../../components/RequiresBLE" ;
13
- import { BleDevicesScanning } from "./BleDeviceScanning " ;
13
+ import { BleDevicesScanning } from "./BleDevicesScanning " ;
14
14
import { BleDevicePairing } from "./BleDevicePairing" ;
15
15
import { addKnownDevice } from "../../actions/ble" ;
16
16
@@ -20,14 +20,16 @@ export type NavigateInput = {
20
20
} ;
21
21
22
22
export type PathToDeviceParam = PropertyPath ;
23
+ export type NavigationType = "navigate" | "replace" ;
23
24
24
25
export type BleDevicePairingFlowParams = {
25
26
filterByDeviceModelId ?: DeviceModelId ;
26
27
areKnownDevicesDisplayed ?: boolean ;
27
28
onSuccessAddToKnownDevices ?: boolean ;
29
+ navigationType ?: NavigationType ;
28
30
onSuccessNavigateToConfig : {
29
31
navigateInput : NavigateInput ;
30
- pathToDeviceParam : string ;
32
+ pathToDeviceParam : PathToDeviceParam ;
31
33
} ;
32
34
} ;
33
35
@@ -40,9 +42,11 @@ export type BleDevicePairingFlowProps = StackScreenProps<
40
42
* Screen handling the BLE flow with a scanning step and a pairing step
41
43
* @param navigation react-navigation navigation object
42
44
* @param route react-navigation route object. The route params are:
43
- * - filterByDeviceModelId: a device model id to filter on
45
+ * - filterByDeviceModelId: (optional, default to none) a device model id to filter on
44
46
* - areKnownDevicesDisplayed: boolean, display the already known device if true,
45
47
* filter out them if false (default to true)
48
+ * - navigationType: (optional, default to "navigate") when navigating after a successful pairing,
49
+ * choose between a "replace" or a "navigate"
46
50
* - onSuccessNavigateToConfig: object containing navigation config parameters when successful pairing:
47
51
* - navigateInput: navigation object given as input to navigation.navigate. 2 mandatory props:
48
52
* - name: navigator name or screen name if no need to specify a navigator
@@ -74,6 +78,7 @@ export const BleDevicePairingFlow = ({
74
78
filterByDeviceModelId,
75
79
areKnownDevicesDisplayed = true ,
76
80
onSuccessAddToKnownDevices = false ,
81
+ navigationType = "navigate" ,
77
82
onSuccessNavigateToConfig : { navigateInput, pathToDeviceParam } ,
78
83
} = route . params ;
79
84
const [ deviceToPair , setDeviceToPair ] = useState < Device | null > ( null ) ;
@@ -106,16 +111,26 @@ export const BleDevicePairingFlow = ({
106
111
setFromPath ( navigateInput , pathToDeviceParam , device ) ;
107
112
} else {
108
113
console . error (
109
- `BLE pairing flow: device path param ${ pathToDeviceParam } not existing on navigation input` ,
114
+ `BLE pairing flow: device path param ${ String (
115
+ pathToDeviceParam ,
116
+ ) } not existing on navigation input`,
110
117
) ;
111
118
}
112
119
113
- navigation . navigate ( navigateInput ) ;
120
+ // Before navigating, to never come back a the successful pairing but to the scanning part
121
+ setDeviceToPair ( null ) ;
122
+
123
+ if ( navigationType === "replace" ) {
124
+ navigation . replace ( navigateInput . name , { ...navigateInput . params } ) ;
125
+ } else {
126
+ navigation . navigate ( navigateInput ) ;
127
+ }
114
128
} ,
115
129
[
116
130
dispatchRedux ,
117
131
navigateInput ,
118
132
navigation ,
133
+ navigationType ,
119
134
onSuccessAddToKnownDevices ,
120
135
pathToDeviceParam ,
121
136
] ,
0 commit comments