Skip to content

Commit db7e61a

Browse files
committed
adjust android compatibility
1 parent 84fb50b commit db7e61a

4 files changed

Lines changed: 53 additions & 37 deletions

File tree

android/build.gradle

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
apply plugin: 'com.android.library'
2+
apply plugin: 'org.jetbrains.kotlin.android'
23

34
def safeExtGet(prop, fallback) {
45
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
56
}
67

78
android {
9+
namespace "com.onesignal.rnonesignalandroid"
810
compileSdkVersion safeExtGet('compileSdkVersion', 28)
911
buildToolsVersion safeExtGet('buildToolsVersion', '28.0.3')
1012

@@ -18,8 +20,12 @@ android {
1820
}
1921

2022
compileOptions {
21-
sourceCompatibility JavaVersion.VERSION_1_8
22-
targetCompatibility JavaVersion.VERSION_1_8
23+
sourceCompatibility JavaVersion.VERSION_17
24+
targetCompatibility JavaVersion.VERSION_17
25+
}
26+
27+
kotlinOptions {
28+
jvmTarget = '17'
2329
}
2430
}
2531

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.onesignal.rnonesignalandroid">
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
32
</manifest>

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)