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

feat(local-notifications): Test android notification styles #139

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
137 changes: 126 additions & 11 deletions src/components/LocalNotificationTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ export default function LocalNotificationTest({ permissions }: Props) {
console.log('schedule result:', result);
};

const scheduleNowWithLargeIcon = async () => {
const notifications: LocalNotificationSchema[] = [
{
...createNotification(),
smallIcon: 'ic_stat_icon_sample',
iconColor: '#00ff00',
largeIcon: 'large_icon_sample.png',
},
];
const result = await LocalNotifications.schedule({ notifications });

getPendingNotifications();

console.log('schedule result:', result);
};

const scheduleOnce = async () => {
const tenSecondsFromNow = new Date(new Date().getTime() + 10000);
const notifications: LocalNotificationSchema[] = [
Expand Down Expand Up @@ -269,6 +285,90 @@ export default function LocalNotificationTest({ permissions }: Props) {
await getPendingNotifications();
};

const scheduleAndroidBigTextStyle = async () => {
const notifications: LocalNotificationSchema[] = [
{
...{
id: 223,
title: 'Android Big Text Test',
body: 'Testing, 1, 2, 3',
summaryText: 'From Capacitor',
largeBody:
'Lorem ipsum dolor sit amet, consectetur adipiscing elite. Morbi quis magna lobortis, dignissim tortor eu, congue lectus. Vestibulum in purus sagittis est blandit sodales.\n\nAliquam lacinia mi id erat eleifend, nec elementum ipsum fermentum. Duis cursus eget lorem sed posuere. Aliquam congue sed lacus eget suscipit. Curabitur vulputate sem quis sollicitudin sollicitudin. Sed sed semper ligula. \n\nIn arcu urna, pretium vel cursus vel, interdum quis massa.',
sound: 'beep.aiff',
attachments: [{ id: 'face', url: 'res:///assets/ionitron.png' }],
},
},
];

const result = await LocalNotifications.schedule({ notifications });
console.log('schedule result:', result);

await getPendingNotifications();
};

const testAndroidInboxStyle = async () => {
const notifications: LocalNotificationSchema[] = [
{
id: generateId(),
title: '4 New mails from Capacitor',
body: 'You have new messages',
summaryText: '+3 more messages',
largeIcon: 'large_icon_sample.png',
inboxList: [
'New direct message from John',
'New direct message from Jane',
"Don't miss our 50% off sale!",
'Payment Confirmation',
],
},
];

const result = await LocalNotifications.schedule({ notifications });
console.log('schedule result:', result);

await getPendingNotifications();
};

const testAndroidGroupStyle = async () => {
const notifications: LocalNotificationSchema[] = [
{
title: 'Noti1',
body: 'Body1',
id: 1,
schedule: { at: new Date(Date.now() + 1000 * 5) },
actionTypeId: '',
extra: null,
group: '1',
},
{
title: 'Noti2',
body: 'Body2',
id: 2,
schedule: { at: new Date(Date.now() + 1000 * 5) },
actionTypeId: '',
extra: null,
group: '1',
},
{
title: 'NotiGroup',
body: 'NotiGroup',
id: 3,
schedule: { at: new Date(Date.now() + 1000 * 5) },
actionTypeId: '',
extra: null,
group: '1',
groupSummary: true,
summaryText: 'Test Summary',
},
];

const result = await LocalNotifications.schedule({ notifications });
console.log('schedule result:', result);

await getPendingNotifications();
};

useEffect(() => {
if (permissions === 'granted') {
getPendingNotifications();
Expand Down Expand Up @@ -313,12 +413,23 @@ export default function LocalNotificationTest({ permissions }: Props) {
</IonList>
<br />
<section>
<h4>Scheduling Tests</h4>
<hr />
<IonButton expand="block" onClick={scheduleOne}>
Schedule just one
</IonButton>
<IonButton expand="block" onClick={cancelOne}>
Cancel just one
</IonButton>
<IonButton expand="block" onClick={scheduleOnWithSeconds}>
Schedule just one (with seconds)
</IonButton>
<IonButton expand="block" onClick={scheduleOnWithoutSeconds}>
Schedule just one (without seconds)
</IonButton>
<IonButton expand="block" onClick={scheduleNow}>
Schedule now
</IonButton>
<IonButton expand="block" onClick={scheduleNowWithIcon}>
Schedule now (custom icon on Android)
</IonButton>
<IonButton expand="block" onClick={scheduleOnce}>
Schedule in 10s
</IonButton>
Expand All @@ -343,17 +454,21 @@ export default function LocalNotificationTest({ permissions }: Props) {
<IonButton expand="block" onClick={refreshPending}>
Refresh Pending Notifications
</IonButton>
<IonButton expand="block" onClick={scheduleOne}>
Schedule just one
<h4>Android Notification Style Tests</h4>
<IonButton expand="block" onClick={scheduleNowWithIcon}>
Custom Small Icon Test
</IonButton>
<IonButton expand="block" onClick={scheduleOnWithSeconds}>
Schedule just one (with seconds)
<IonButton expand="block" onClick={scheduleNowWithLargeIcon}>
Custom Large Icon Test
</IonButton>
<IonButton expand="block" onClick={scheduleOnWithoutSeconds}>
Schedule just one (without seconds)
<IonButton expand="block" onClick={scheduleAndroidBigTextStyle}>
Android Big Text Style
</IonButton>
<IonButton expand="block" onClick={cancelOne}>
Cancel just one
<IonButton expand="block" onClick={testAndroidInboxStyle}>
Android Inbox Style
</IonButton>
<IonButton expand="block" onClick={testAndroidGroupStyle}>
Android Group Notification
</IonButton>
</section>
</div>
Expand Down