You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: versioned_docs/version-7.x/custom-android-back-button-handling.md
+225-5Lines changed: 225 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,9 @@ title: Custom Android back button behavior
4
4
sidebar_label: Custom Android back button behavior
5
5
---
6
6
7
+
import Tabs from '@theme/Tabs';
8
+
import TabItem from '@theme/TabItem';
9
+
7
10
By default, when user presses the Android hardware back button, react-navigation will pop a screen or exit the app if there are no screens to pop. This is a sensible default behavior, but there are situations when you might want to implement custom handling.
8
11
9
12
As an example, consider a screen where user is selecting items in a list, and a "selection mode" is active. On a back button press, you would first want the "selection mode" to be deactivated, and the screen should be popped only on the second back button press. The following code snippet demonstrates the situation. We make use of [`BackHandler`](https://reactnative.dev/docs/backhandler.html) which comes with react-native, along with the `useFocusEffect` hook to add our custom `hardwareBackPress` listener.
@@ -12,31 +15,248 @@ Returning `true` from `onBackPress` denotes that we have handled the event, and
12
15
13
16
<sampid="custom-android-back-button"/>
14
17
15
-
```js
18
+
<TabsgroupId="config"queryString="config">
19
+
<TabItemvalue="static"label="Static"default>
20
+
21
+
```js name="Custom android back button" snack version=7
The presented approach will work well for screens that are shown in a `StackNavigator`. Custom back button handling in other situations may not be supported at the moment (eg. A known case when this does not work is when you want to handle back button press in an open drawer. PRs for such use cases are welcome!).
41
261
42
262
If instead of overriding system back button, you'd like to prevent going back from the screen, see docs for [preventing going back](preventing-going-back.md).
Copy file name to clipboardExpand all lines: versioned_docs/version-7.x/deep-linking.md
+84-1Lines changed: 84 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,9 @@ title: Deep linking
4
4
sidebar_label: Deep linking
5
5
---
6
6
7
+
import Tabs from '@theme/Tabs';
8
+
import TabItem from '@theme/TabItem';
9
+
7
10
This guide will describe how to configure your app to handle deep links on various platforms. To handle incoming links, you need to handle 2 scenarios:
8
11
9
12
1. If the app wasn't previously open, the deep link needs to set the initial state
@@ -35,6 +38,28 @@ npx expo install expo-linking
35
38
36
39
Then, let's configure React Navigation to use the `scheme` for parsing incoming deep links:
37
40
41
+
<TabsgroupId="config"queryString="config">
42
+
<TabItemvalue="static"label="Static"default>
43
+
44
+
```js
45
+
import*asLinkingfrom'expo-linking';
46
+
47
+
constprefix=Linking.createURL('/');
48
+
49
+
/* content */
50
+
51
+
functionApp() {
52
+
constlinking= {
53
+
prefixes: [prefix],
54
+
};
55
+
56
+
return<Navigation linking={linking} />;
57
+
}
58
+
```
59
+
60
+
</TabItem>
61
+
<TabItemvalue="dynamic"label="Dynamic"default>
62
+
38
63
```js
39
64
import*asLinkingfrom'expo-linking';
40
65
@@ -53,6 +78,9 @@ function App() {
53
78
}
54
79
```
55
80
81
+
</TabItem>
82
+
</Tabs>
83
+
56
84
The reason that is necessary to use `Linking.createURL` is that the scheme will differ depending on whether you're in the client app or in a standalone app.
57
85
58
86
The scheme specified in `app.json` only applies to standalone apps. In the Expo client app you can deep link using `exp://ADDRESS:PORT/--/` where `ADDRESS` is often `127.0.0.1` and `PORT` is often `19000` - the URL is printed when you run `expo start`. The `Linking.createURL` function abstracts it out so that you don't need to specify them manually.
@@ -267,7 +295,59 @@ React Native's `Linking` isn't the only way to handle deep linking. You might al
267
295
268
296
To achieve this, you'd need to override how React Navigation subscribes to incoming links. To do so, you can provide your own [`getInitialURL`](navigation-container.md#linkinggetinitialurl) and [`subscribe`](navigation-container.md#linkingsubscribe) functions:
269
297
270
-
```js
298
+
<TabsgroupId="config"queryString="config">
299
+
<TabItemvalue="static"label="Static"default>
300
+
301
+
```js name="Third-party integrations"
302
+
constlinking= {
303
+
prefixes: ['myapp://', 'https://myapp.com'],
304
+
305
+
// Custom function to get the URL which was used to open the app
306
+
asyncgetInitialURL() {
307
+
// First, you would need to get the initial URL from your third-party integration
308
+
// The exact usage depend on the third-party SDK you use
309
+
// For example, to get the initial URL for Firebase Dynamic Links:
Similar to the above example, you can integrate any API that provides a way to get the initial URL and to subscribe to new incoming URLs using the `getInitialURL` and `subscribe` options.
0 commit comments