Skip to content

Commit 2cff219

Browse files
committed
tweak demo example
1 parent 84fb50b commit 2cff219

2 files changed

Lines changed: 44 additions & 33 deletions

File tree

examples/RNOneSignalTS/OSDemo.tsx

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
import { useFocusEffect } from '@react-navigation/native';
22
import React, { useCallback, useEffect, useState } from 'react';
33
import {
4-
Alert,
54
ScrollView,
65
StyleSheet,
76
Text,
87
TextInput,
98
TouchableOpacity,
109
View,
1110
} from 'react-native';
12-
import { LogLevel, OneSignal } from 'react-native-onesignal';
11+
import {
12+
LogLevel,
13+
NotificationClickEvent,
14+
NotificationWillDisplayEvent,
15+
OneSignal,
16+
} from 'react-native-onesignal';
1317
import { SafeAreaView } from 'react-native-safe-area-context';
1418
import OSButtons from './OSButtons';
1519
import OSConsole from './OSConsole';
@@ -37,44 +41,51 @@ const OSDemo: React.FC = () => {
3741
}, []);
3842

3943
const onForegroundWillDisplay = useCallback(
40-
(event: unknown) => {
41-
OSLog('OneSignal: notification will show in foreground:', event);
42-
const notif = (
43-
event as { getNotification: () => { title: string } }
44-
).getNotification();
44+
(event: NotificationWillDisplayEvent) => {
45+
const notif = event.getNotification();
46+
OSLog('OneSignal: notification will show in foreground:', notif.title);
47+
console.log('Will display notification event:', notif);
4548

46-
const cancelButton = {
47-
text: 'Cancel',
48-
onPress: () => {
49-
(event as { preventDefault: () => void }).preventDefault();
50-
},
51-
style: 'cancel' as const,
52-
};
49+
event.preventDefault();
5350

54-
const completeButton = {
55-
text: 'Display',
56-
onPress: () => {
57-
(event as { getNotification: () => { display: () => void } })
58-
.getNotification()
59-
.display();
60-
},
61-
};
51+
setTimeout(() => {
52+
notif.display();
53+
}, 5000);
6254

63-
Alert.alert(
64-
'Display notification?',
65-
notif.title,
66-
[cancelButton, completeButton],
67-
{
68-
cancelable: true,
69-
},
70-
);
55+
// const cancelButton = {
56+
// text: 'Cancel',
57+
// onPress: () => {
58+
// (event as { preventDefault: () => void }).preventDefault();
59+
// },
60+
// style: 'cancel' as const,
61+
// };
62+
63+
// const completeButton = {
64+
// text: 'Display',
65+
// onPress: () => {
66+
// (event as { getNotification: () => { display: () => void } })
67+
// .getNotification()
68+
// .display();
69+
// },
70+
// };
71+
72+
// Alert.alert(
73+
// 'Display notification?',
74+
// notif.title,
75+
// [cancelButton, completeButton],
76+
// {
77+
// cancelable: true,
78+
// },
79+
// );
7180
},
7281
[OSLog],
7382
);
7483

7584
const onNotificationClick = useCallback(
76-
(event: unknown) => {
77-
OSLog('OneSignal: notification clicked:', event);
85+
(event: NotificationClickEvent) => {
86+
const notif = event.notification;
87+
OSLog('OneSignal: notification clicked:', notif.title);
88+
console.log('Notification clicked event:', notif);
7889
},
7990
[OSLog],
8091
);

examples/RNOneSignalTS/setup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ bun pm pack
99
mv react-native-onesignal-*.tgz react-native-onesignal.tgz
1010

1111
# Use fresh install of the package
12-
cd $ORIGINAL_DIR
12+
cd "$ORIGINAL_DIR"
1313
bun pm cache rm
1414
bun i

0 commit comments

Comments
 (0)