Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add an example of handling navigation on background mode #1166

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions docs-react-native/react-native/docs/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,33 @@ method should be registered as early on in your project as possible (e.g. the `i

```js
// index.js
import { AppRegistry } from 'react-native';
import { AppRegistry, Linking } from 'react-native';
import notifee, { EventType } from '@notifee/react-native';
import App from './App';

notifee.onBackgroundEvent(async ({ type, detail }) => {
const { notification, pressAction } = detail;

const actionId = pressAction.id
// Check if the user pressed the "Mark as read" action
if (type === EventType.ACTION_PRESS && pressAction.id === 'mark-as-read') {
// Update external API
await fetch(`https://my-api.com/chat/${notification.data.chatId}/read`, {
method: 'POST',
});
if (type === EventType.ACTION_PRESS) {
if (actionId === 'mark-as-read') {
// Update external API
await fetch(`https://my-api.com/chat/${notification.data.chatId}/read`, {
method: 'POST',
});

// Remove the notification
await notifee.cancelNotification(notification.id);
}

// Remove the notification
await notifee.cancelNotification(notification.id);
// you might want to open application and navigate to a specific screen
// deeplink will does this for you
const notificationId = notification?.data?.notificationId
let url = 'myapp://'
if (notificationId) {
url += `notifications/${notificationId}`
}
await Linking.openURL(url);
}
});

Expand Down
Loading