Skip to content

Commit dcc8409

Browse files
committed
Merge branch 'moo/MOO-1927-add-js-actions-tests' of github.com:mendix/native-widgets into moo/MOO-1927-add-js-actions-tests
2 parents 09b803f + 948d784 commit dcc8409

29 files changed

+207
-338
lines changed

configs/e2e/mendix-versions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"latest": "11.0.0.73100"
2+
"latest": "10.24.0.73019"
33
}

configs/e2e/native_dependencies.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"react-native-maps": "1.14.0",
33
"react-native-geocoder": "0.5.0",
4-
"react-native-device-info": "13.0.0",
4+
"react-native-device-info": "14.0.4",
55
"react-native-action-button": "2.8.5",
66
"react-native-material-menu": "1.2.0",
7-
"react-native-linear-gradient": "2.5.6",
7+
"react-native-linear-gradient": "2.8.3",
88
"@react-native-community/netinfo": "11.4.1",
99
"react-native-svg": "15.11.1",
1010
"react-native-system-navigation-bar": "2.6.3",

packages/jsActions/mobile-resources-native/package.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,26 @@
2626
"release:marketplace": "node ../../../scripts/release/marketplaceRelease.js"
2727
},
2828
"dependencies": {
29+
"@notifee/react-native": "9.1.8",
2930
"@react-native-camera-roll/camera-roll": "7.4.0",
30-
"@react-native-community/push-notification-ios": "1.10.1",
3131
"@react-native-firebase/messaging": "17.3.0",
32-
"@swan-io/react-native-browser": "^0.4.1",
32+
"@swan-io/react-native-browser": "0.4.1",
3333
"fbjs": "3.0.4",
3434
"mime": "3.0.0",
35+
"react-native-biometrics": "3.0.1",
3536
"react-native-blob-util": "0.21.2",
36-
"react-native-device-info": "13.0.0",
37+
"react-native-device-info": "14.0.4",
3738
"react-native-file-viewer": "2.1.5",
3839
"react-native-image-picker": "7.2.3",
3940
"react-native-localize": "3.2.1",
4041
"react-native-permissions": "4.1.5",
41-
"react-native-push-notification": "8.1.1",
4242
"react-native-schedule-exact-alarm-permission": "^0.1.3",
4343
"react-native-sound": "0.11.0",
44-
"react-native-touch-id": "4.4.1",
4544
"url-parse": "^1.4.7"
4645
},
4746
"devDependencies": {
4847
"@mendix/pluggable-widgets-tools": "^10.0.1",
4948
"@types/querystringify": "^2.0.0",
50-
"@types/react-native-push-notification": "8.1.1",
5149
"@types/url-parse": "^1.4.3",
5250
"eslint": "^7.32.0",
5351
"mendix": "~10.0.9976",

packages/jsActions/mobile-resources-native/src/authentication/BiometricAuthentication.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// - the code between BEGIN USER CODE and END USER CODE
66
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
77
// Other code you write will be lost the next time you deploy the project.
8-
import TouchID from "react-native-touch-id";
8+
import ReactNativeBiometrics from "react-native-biometrics";
99

1010
// BEGIN EXTRA CODE
1111
// END EXTRA CODE
@@ -16,9 +16,12 @@ import TouchID from "react-native-touch-id";
1616
*/
1717
export async function BiometricAuthentication(reason?: string): Promise<boolean> {
1818
// BEGIN USER CODE
19-
// Documentation https://github.com/naoufal/react-native-touch-id
19+
// Documentation https://github.com/smallcase/react-native-simple-biometrics
2020

21-
return TouchID.authenticate(reason)
21+
const rnBiometrics = new ReactNativeBiometrics();
22+
23+
return rnBiometrics
24+
.simplePrompt({ promptMessage: reason ?? "" })
2225
.then(() => true)
2326
.catch(() => false);
2427

packages/jsActions/mobile-resources-native/src/authentication/IsBiometricAuthenticationSupported.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// - the code between BEGIN USER CODE and END USER CODE
66
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
77
// Other code you write will be lost the next time you deploy the project.
8-
import TouchID from "react-native-touch-id";
8+
import ReactNativeBiometrics from "react-native-biometrics";
99

1010
// BEGIN EXTRA CODE
1111
// END EXTRA CODE
@@ -15,10 +15,13 @@ import TouchID from "react-native-touch-id";
1515
*/
1616
export async function IsBiometricAuthenticationSupported(): Promise<boolean> {
1717
// BEGIN USER CODE
18-
// Documentation https://github.com/naoufal/react-native-touch-id
18+
// Documentation https://github.com/smallcase/react-native-simple-biometrics
1919

20-
return TouchID.isSupported()
21-
.then(() => true)
20+
const rnBiometrics = new ReactNativeBiometrics();
21+
22+
return rnBiometrics
23+
.isSensorAvailable()
24+
.then(result => result.available)
2225
.catch(() => false);
2326

2427
// END USER CODE

packages/jsActions/mobile-resources-native/src/notifications/CancelAllScheduledNotifications.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
// - the code between BEGIN USER CODE and END USER CODE
66
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
77
// Other code you write will be lost the next time you deploy the project.
8-
import { NativeModules, Platform } from "react-native";
9-
import PushNotification from "react-native-push-notification";
8+
import { NativeModules } from "react-native";
9+
import notifee from "@notifee/react-native";
1010

1111
// BEGIN EXTRA CODE
1212
// END EXTRA CODE
@@ -17,13 +17,12 @@ import PushNotification from "react-native-push-notification";
1717
*/
1818
export async function CancelAllScheduledNotifications(): Promise<void> {
1919
// BEGIN USER CODE
20-
// Documentation https://github.com/zo0r/react-native-push-notification
21-
const isIOS = Platform.OS === "ios";
22-
if (NativeModules && isIOS && !NativeModules.RNCPushNotificationIOS) {
23-
return Promise.reject(new Error("Notifications module is not available in your app"));
20+
// Documentation https://github.com/invertase/notifee
21+
if (NativeModules && !NativeModules.NotifeeApiModule) {
22+
return Promise.reject(new Error("Notifee native module is not available in your app"));
2423
}
2524

26-
PushNotification.cancelAllLocalNotifications();
25+
notifee.cancelAllNotifications();
2726
return Promise.resolve();
2827

2928
// END USER CODE

packages/jsActions/mobile-resources-native/src/notifications/CancelScheduledNotification.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
// - the code between BEGIN USER CODE and END USER CODE
66
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
77
// Other code you write will be lost the next time you deploy the project.
8-
import { NativeModules, Platform } from "react-native";
9-
import PushNotification from "react-native-push-notification";
8+
import { NativeModules } from "react-native";
9+
import notifee from "@notifee/react-native";
1010

1111
// BEGIN EXTRA CODE
1212
// END EXTRA CODE
@@ -17,17 +17,16 @@ import PushNotification from "react-native-push-notification";
1717
*/
1818
export async function CancelScheduledNotification(notificationId?: string): Promise<void> {
1919
// BEGIN USER CODE
20-
// Documentation https://github.com/zo0r/react-native-push-notification
21-
const isIOS = Platform.OS === "ios";
22-
if (NativeModules && isIOS && !NativeModules.RNCPushNotificationIOS) {
23-
return Promise.reject(new Error("Notifications module is not available in your app"));
20+
// Documentation Documentation https://github.com/invertase/notifee
21+
if (NativeModules && !NativeModules.NotifeeApiModule) {
22+
return Promise.reject(new Error("Notifee native module is not available in your app"));
2423
}
2524

2625
if (!notificationId) {
2726
return Promise.reject(new Error("Input parameter 'Notification id' is required"));
2827
}
2928

30-
PushNotification.cancelLocalNotification(notificationId);
29+
notifee.cancelNotification(notificationId);
3130
return Promise.resolve();
3231

3332
// END USER CODE

packages/jsActions/mobile-resources-native/src/notifications/ClearAllDeliveredNotifications.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
// - the code between BEGIN USER CODE and END USER CODE
66
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
77
// Other code you write will be lost the next time you deploy the project.
8-
import { NativeModules, Platform } from "react-native";
9-
import PushNotification from "react-native-push-notification";
8+
import { NativeModules } from "react-native";
9+
import notifee from "@notifee/react-native";
1010

1111
// BEGIN EXTRA CODE
1212
// END EXTRA CODE
@@ -17,13 +17,12 @@ import PushNotification from "react-native-push-notification";
1717
*/
1818
export async function ClearAllDeliveredNotifications(): Promise<void> {
1919
// BEGIN USER CODE
20-
// Documentation https://github.com/zo0r/react-native-push-notification
21-
const isIOS = Platform.OS === "ios";
22-
if (NativeModules && isIOS && !NativeModules.RNCPushNotificationIOS) {
23-
return Promise.reject(new Error("Notifications module is not available in your app"));
20+
// Documentation Documentation https://github.com/invertase/notifee
21+
if (NativeModules && !NativeModules.NotifeeApiModule) {
22+
return Promise.reject(new Error("Notifee native module is not available in your app"));
2423
}
2524

26-
PushNotification.removeAllDeliveredNotifications();
25+
notifee.cancelAllNotifications();
2726

2827
return Promise.resolve();
2928
// END USER CODE

packages/jsActions/mobile-resources-native/src/notifications/DisplayNotification.ts

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
77
// Other code you write will be lost the next time you deploy the project.
88
import { NativeModules, Platform } from "react-native";
9-
import PushNotification, { PushNotificationObject } from "react-native-push-notification";
9+
import notifee, { AndroidChannel, AndroidImportance, Notification } from "@notifee/react-native";
1010

1111
// BEGIN EXTRA CODE
1212
// END EXTRA CODE
@@ -32,59 +32,54 @@ export async function DisplayNotification(
3232
actionGuid?: string
3333
): Promise<void> {
3434
// BEGIN USER CODE
35-
// Documentation https://github.com/zo0r/react-native-push-notification
36-
37-
const isIOS = Platform.OS === "ios";
38-
if (NativeModules && isIOS && !NativeModules.RNCPushNotificationIOS) {
39-
return Promise.reject(new Error("Notifications module is not available in your app"));
35+
if (!body) {
36+
throw new Error("Input parameter 'Body' is required");
4037
}
4138

42-
if (!body) {
43-
return Promise.reject(new Error("Input parameter 'Body' is required"));
39+
// Documentation Documentation https://github.com/invertase/notifee
40+
if (NativeModules && !NativeModules.NotifeeApiModule) {
41+
return Promise.reject(new Error("Notifee native module is not available in your app"));
4442
}
4543

46-
const notification = { message: body } as PushNotificationObject;
44+
const channelId = playSound ? "mendix-local-notifications-withsound" : "mendix-local-notifications";
45+
await createNotificationChannelIfNeeded(channelId);
4746

48-
if (!isIOS) {
49-
const channelId = "mendix-local-notifications";
50-
const channelExists = await new Promise(resolve =>
51-
PushNotification.channelExists(channelId, (exists: boolean) => resolve(exists))
52-
);
53-
if (!channelExists) {
54-
const channel = await new Promise(resolve =>
55-
PushNotification.createChannel(
56-
{
57-
channelId,
58-
channelName: "Local notifications"
59-
},
60-
created => resolve(created)
61-
)
62-
);
63-
if (!channel) {
64-
return Promise.reject(new Error("Could not create the local notifications channel"));
65-
}
66-
}
67-
notification.channelId = channelId;
68-
}
47+
const notification: Notification = {
48+
title: title || undefined,
49+
body,
50+
android: { channelId, sound: "default" },
51+
ios: playSound ? { sound: "default" } : {}
52+
};
6953

70-
if (title) {
71-
notification.title = title;
54+
if (subtitle && Platform.OS === "ios") {
55+
notification.subtitle = subtitle;
7256
}
7357

74-
if (subtitle && !isIOS) {
75-
notification.subText = subtitle;
58+
if (actionName || actionGuid) {
59+
notification.data = {
60+
actionName: actionName ?? "",
61+
guid: actionGuid ?? ""
62+
};
7663
}
7764

78-
notification.playSound = !!playSound;
65+
await notifee.displayNotification(notification);
7966

80-
if (actionName || actionGuid) {
81-
notification.userInfo = {
82-
actionName,
83-
guid: actionGuid
67+
async function createNotificationChannelIfNeeded(channelId: string): Promise<void> {
68+
if (Platform.OS === "ios") {
69+
return;
70+
}
71+
const existingChannel = await notifee.getChannel(channelId);
72+
const channel: AndroidChannel = {
73+
id: channelId,
74+
name: "Local Notifications",
75+
importance: AndroidImportance.HIGH,
76+
...(playSound ? { sound: "default" } : {})
8477
};
78+
if (existingChannel === null) {
79+
await notifee.createChannel(channel);
80+
}
8581
}
8682

87-
PushNotification.localNotification(notification);
8883
return Promise.resolve();
8984
// END USER CODE
9085
}

0 commit comments

Comments
 (0)