-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from Naveen-g09/notifee
Notifications Feature
- Loading branch information
Showing
8 changed files
with
276 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
npx expo-doctor | ||
|
||
yarn pre-commit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
import notifee, { AndroidStyle } from "@notifee/react-native"; | ||
|
||
import { | ||
BigTextNotificationProps, | ||
InboxNotificationProps, | ||
MessageNotificationProps, | ||
PictureNotificationProps, | ||
SimpleNotificationProps, | ||
} from "./notificationInterfaces"; | ||
|
||
export async function displaySimpleNotification( | ||
props: SimpleNotificationProps, | ||
) { | ||
const channelId = await notifee.createChannel({ | ||
...props.config, | ||
id: props.id, | ||
name: props.id, | ||
vibration: true, | ||
vibrationPattern: [500, 300], | ||
sound: "notify", | ||
}); | ||
|
||
await notifee.displayNotification({ | ||
title: props.title, | ||
body: props.body, | ||
id: props.id, | ||
...props.notificationConfig, | ||
android: { | ||
channelId, | ||
...props.notificationConfig?.android, | ||
}, | ||
}); | ||
} | ||
|
||
export async function displayPictureNotification( | ||
props: PictureNotificationProps, | ||
) { | ||
const channelId = await notifee.createChannel({ | ||
...props.config, | ||
id: props.id, | ||
name: `Residentron channel`, | ||
vibration: true, | ||
vibrationPattern: [500, 300], | ||
sound: "notify", | ||
}); | ||
|
||
await notifee.displayNotification({ | ||
...props.notificationConfig, | ||
title: props.title, | ||
body: props.body, | ||
id: props.id, | ||
android: { | ||
channelId, | ||
style: { | ||
type: AndroidStyle.BIGPICTURE, | ||
picture: props.picture, | ||
}, | ||
...props.notificationConfig?.android, | ||
}, | ||
}); | ||
} | ||
|
||
export async function displayMessageNotification( | ||
props: MessageNotificationProps, | ||
) { | ||
const channelId = await notifee.createChannel({ | ||
...props.config, | ||
id: props.id, | ||
vibration: true, | ||
vibrationPattern: [500, 300], | ||
name: `Residentron channel`, | ||
sound: "notify", | ||
}); | ||
|
||
await notifee.displayNotification({ | ||
...props.notificationConfig, | ||
title: props.title, | ||
body: props.body, | ||
id: props.id, | ||
android: { | ||
channelId, | ||
style: { | ||
type: AndroidStyle.MESSAGING, | ||
person: props.person, | ||
messages: props.messages, | ||
}, | ||
...props.notificationConfig?.android, | ||
}, | ||
}); | ||
} | ||
|
||
export async function displayInboxNotification(props: InboxNotificationProps) { | ||
const channelId = await notifee.createChannel({ | ||
...props.config, | ||
id: props.id, | ||
name: `Residentron`, | ||
vibration: true, | ||
vibrationPattern: [500, 300], | ||
sound: "notify", | ||
}); | ||
|
||
await notifee.displayNotification({ | ||
...props.notificationConfig, | ||
title: props.title, | ||
body: props.body, | ||
id: props.id, | ||
android: { | ||
channelId, | ||
style: { | ||
type: AndroidStyle.INBOX, | ||
lines: props.messages, | ||
}, | ||
...props.notificationConfig?.android, | ||
}, | ||
}); | ||
} | ||
|
||
export async function displayTextNotification(props: BigTextNotificationProps) { | ||
const channelId = await notifee.createChannel({ | ||
...props.config, | ||
id: props.id, | ||
name: `Residentron channel`, | ||
vibration: true, | ||
vibrationPattern: [500, 300], | ||
sound: "notify", | ||
}); | ||
|
||
await notifee.displayNotification({ | ||
...props.notificationConfig, | ||
title: props.title, | ||
body: props.body, | ||
id: props.id, | ||
android: { | ||
channelId, | ||
style: { | ||
type: AndroidStyle.BIGTEXT, | ||
text: props.text, | ||
}, | ||
...props.notificationConfig?.android, | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { | ||
AndroidChannel, | ||
Notification, | ||
AndroidMessagingStyleMessage, | ||
AndroidPerson, | ||
} from "@notifee/react-native"; | ||
|
||
export interface MessageNotificationProps { | ||
id: string; | ||
config?: Omit<Omit<AndroidChannel, "id">, "channel">; | ||
title: string; | ||
body: string; | ||
notificationConfig?: Omit<Omit<Notification, "title">, "body">; | ||
messages: AndroidMessagingStyleMessage[]; | ||
person: AndroidPerson; | ||
} | ||
export interface PictureNotificationProps { | ||
id: string; | ||
config?: Omit<Omit<AndroidChannel, "id">, "channel">; | ||
title: string; | ||
body: string; | ||
notificationConfig?: Omit<Omit<Notification, "title">, "body">; | ||
picture: string; | ||
} | ||
|
||
export interface InboxNotificationProps { | ||
id: string; | ||
config?: Omit<Omit<AndroidChannel, "id">, "channel">; | ||
title: string; | ||
body: string; | ||
notificationConfig?: Omit<Omit<Notification, "title">, "body">; | ||
messages: string[]; | ||
} | ||
|
||
export interface SimpleNotificationProps { | ||
id: string; | ||
config?: Omit<Omit<AndroidChannel, "id">, "channel">; | ||
title?: string; | ||
body?: string; | ||
notificationConfig?: Omit<Omit<Notification, "title">, "body">; | ||
} | ||
|
||
export interface BigTextNotificationProps { | ||
id: string; | ||
config?: Omit<Omit<AndroidChannel, "id">, "channel">; | ||
title: string; | ||
body: string; | ||
notificationConfig?: Omit<Omit<Notification, "title">, "body">; | ||
text: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import notifee from "@notifee/react-native"; | ||
|
||
export async function onDisplayNotification() { | ||
// Request permissions (required for iOS) | ||
await notifee.requestPermission(); | ||
|
||
// Create a channel (required for Android) | ||
const channelId = await notifee.createChannel({ | ||
id: "default", | ||
name: "Default Channel", | ||
}); | ||
|
||
// Display a notification | ||
await notifee.displayNotification({ | ||
title: "Notification Title", | ||
body: "Main body content of the notification", | ||
android: { | ||
channelId, | ||
// optional, defaults to 'ic_launcher'. | ||
// pressAction is needed if you want the notification to open the app when pressed | ||
pressAction: { | ||
id: "default", | ||
}, | ||
}, | ||
}); | ||
} | ||
|
||
// export async function sendPushNotification(expoPushToken: string) { | ||
// const message = { | ||
// to: expoPushToken, | ||
// sound: "default", | ||
// title: "Original Title", | ||
// body: "And here is the body!", | ||
// data: { data: "goes here" }, | ||
// }; | ||
|
||
// await fetch("https://exp.host/--/api/v2/push/send", { | ||
// method: "POST", | ||
// headers: { | ||
// Accept: "application/json", | ||
// "Accept-encoding": "gzip, deflate", | ||
// "Content-Type": "application/json", | ||
// }, | ||
// body: JSON.stringify(message), | ||
// }); | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters