From 0a55106c629461590168a9e7a43e4eacaba3390d Mon Sep 17 00:00:00 2001 From: Ilya Pakhomov Date: Mon, 15 Jun 2026 21:58:12 +0600 Subject: [PATCH 1/2] fix: allow work push notifications for virtual devices --- .../data-access/push-notifications/service.ts | 115 ++++++++---------- 1 file changed, 51 insertions(+), 64 deletions(-) diff --git a/src/lib/src/data-access/push-notifications/service.ts b/src/lib/src/data-access/push-notifications/service.ts index 7530216..7743406 100644 --- a/src/lib/src/data-access/push-notifications/service.ts +++ b/src/lib/src/data-access/push-notifications/service.ts @@ -1,5 +1,4 @@ import Constants from 'expo-constants'; -import * as Device from 'expo-device'; import { PermissionStatus } from 'expo-modules-core'; import * as Notifications from 'expo-notifications'; import { Alert, Linking, Platform } from 'react-native'; @@ -38,9 +37,6 @@ if (Platform.OS === 'android') { * Service for integrating [Expo push notifications](https://docs.expo.dev/push-notifications/overview/) into apps. * Requires [setup](https://docs.expo.dev/push-notifications/push-notifications-setup/) and [backend implementation](https://docs.expo.dev/push-notifications/sending-notifications/) for sending notifications. * - * > Required dependencies: `@pusher/pusher-websocket-react-native`, `pusher-js`, `expo-notifications`, `expo-router`, - * > `expo-constants`, `expo-device`, `expo-modules-core`. - * * Public methods: * - `obtainPushNotificationsToken` – get an Expo token that can be used to send a push notification to the device using Expo's push notifications service. * - `pushToken` – getter for retrieving the token if it was already obtained. @@ -64,90 +60,81 @@ class PushNotificationsService { public async obtainPushNotificationsToken({ getTokenErrorHandler, }: ObtainPushNotificationsTokenArgs): Promise { - if (Device.isDevice) { - const settings = await Notifications.getPermissionsAsync(); - - const handlePermissionDeniedResponse = (response: Notifications.NotificationPermissionsStatus): void => { - if (getTokenErrorHandler) { - getTokenErrorHandler(response); - } else { - const errorMessage = `Sorry, we need notification permissions to make this work! Please enable notification permissions in your device settings`; - - Alert.alert('', errorMessage, [{ text: 'Close' }, { onPress: Linking.openSettings, text: 'Open settings' }]); - } - }; - - const requestPermissionsIOS = async (settings: Notifications.NotificationPermissionsStatus): Promise => { - const permissionsGrantedStatuses = [ - Notifications.IosAuthorizationStatus.AUTHORIZED, - Notifications.IosAuthorizationStatus.PROVISIONAL, - Notifications.IosAuthorizationStatus.EPHEMERAL, - ]; + const settings = await Notifications.getPermissionsAsync(); - if (settings.ios?.status === Notifications.IosAuthorizationStatus.NOT_DETERMINED) { - const permissions = await Notifications.requestPermissionsAsync(); - const arePermissionsGranted = - !!permissions.ios && permissionsGrantedStatuses.includes(permissions.ios?.status); + const handlePermissionDeniedResponse = (response: Notifications.NotificationPermissionsStatus): void => { + if (getTokenErrorHandler) { + getTokenErrorHandler(response); + } else { + const errorMessage = `Sorry, we need notification permissions to make this work! Please enable notification permissions in your device settings`; - if (!arePermissionsGranted) { - handlePermissionDeniedResponse(permissions); - } + Alert.alert('', errorMessage, [{ text: 'Close' }, { onPress: Linking.openSettings, text: 'Open settings' }]); + } + }; - return; - } + const requestPermissionsIOS = async (settings: Notifications.NotificationPermissionsStatus): Promise => { + const permissionsGrantedStatuses = [ + Notifications.IosAuthorizationStatus.AUTHORIZED, + Notifications.IosAuthorizationStatus.PROVISIONAL, + Notifications.IosAuthorizationStatus.EPHEMERAL, + ]; - const arePermissionsGranted = !!settings.ios && permissionsGrantedStatuses.includes(settings.ios?.status); + if (settings.ios?.status === Notifications.IosAuthorizationStatus.NOT_DETERMINED) { + const permissions = await Notifications.requestPermissionsAsync(); + const arePermissionsGranted = !!permissions.ios && permissionsGrantedStatuses.includes(permissions.ios?.status); if (!arePermissionsGranted) { - handlePermissionDeniedResponse(settings); + handlePermissionDeniedResponse(permissions); } - }; - const requestPermissionsAndroid = async ( - settings: Notifications.NotificationPermissionsStatus, - ): Promise => { - if (settings.status !== PermissionStatus.GRANTED) { - const permissions = await Notifications.requestPermissionsAsync(); - const arePermissionsGranted = permissions.status === PermissionStatus.GRANTED; + return; + } - if (!arePermissionsGranted) { - handlePermissionDeniedResponse(permissions); - } + const arePermissionsGranted = !!settings.ios && permissionsGrantedStatuses.includes(settings.ios?.status); - return; - } + if (!arePermissionsGranted) { + handlePermissionDeniedResponse(settings); + } + }; - const arePermissionsGranted = settings.status === PermissionStatus.GRANTED; + const requestPermissionsAndroid = async (settings: Notifications.NotificationPermissionsStatus): Promise => { + if (settings.status !== PermissionStatus.GRANTED) { + const permissions = await Notifications.requestPermissionsAsync(); + const arePermissionsGranted = permissions.status === PermissionStatus.GRANTED; if (!arePermissionsGranted) { - handlePermissionDeniedResponse(settings); + handlePermissionDeniedResponse(permissions); } - }; - - if (Platform.OS === 'ios') { - await requestPermissionsIOS(settings); - } - if (Platform.OS === 'android') { - await requestPermissionsAndroid(settings); + return; } - const projectId = Constants.expoConfig?.extra?.eas.projectId; + const arePermissionsGranted = settings.status === PermissionStatus.GRANTED; - if (!projectId) { - console.error('EAS projectId is not specified in app.config.ts. Push notifications may not work.'); + if (!arePermissionsGranted) { + handlePermissionDeniedResponse(settings); } + }; - const token = await Notifications.getExpoPushTokenAsync({ projectId }); + if (Platform.OS === 'ios') { + await requestPermissionsIOS(settings); + } - this._pushToken = token.data; + if (Platform.OS === 'android') { + await requestPermissionsAndroid(settings); + } - return token.data; - } else { - console.error('Must use physical device for push notifications'); + const projectId = Constants.expoConfig?.extra?.eas.projectId; - return; + if (!projectId) { + console.error('EAS projectId is not specified in app.config.ts. Push notifications may not work.'); } + + const token = await Notifications.getExpoPushTokenAsync({ projectId }); + + this._pushToken = token.data; + + return token.data; } } From 5c5f069a84283d1c8e8f754ee56c9f11b38803f2 Mon Sep 17 00:00:00 2001 From: Ilya Pakhomov Date: Mon, 15 Jun 2026 21:58:39 +0600 Subject: [PATCH 2/2] refactor: remove redundant expo device peer dependency --- README.md | 2 +- apps/example/package.json | 1 - package-lock.json | 40 --------------------------------------- package.json | 1 - src/lib/package.json | 4 ---- 5 files changed, 1 insertion(+), 47 deletions(-) diff --git a/README.md b/README.md index 1d29115..9d4a5a0 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ import { AppSafeAreaView } from '@ronas-it/react-native-common-modules/safe-area #### 1. Push notifications -> **_NOTE:_** Required dependencies: `expo-notifications`, `expo-router`, `expo-constants`, `expo-device`, `expo-modules-core` +> **_NOTE:_** Required dependencies: `expo-notifications`, `expo-router`, `expo-constants`, `expo-modules-core` ##### `PushNotificationsService` diff --git a/apps/example/package.json b/apps/example/package.json index 6f3e939..4fdf283 100644 --- a/apps/example/package.json +++ b/apps/example/package.json @@ -8,7 +8,6 @@ "@reduxjs/toolkit": "^2.9.0", "expo": "^54.0.0", "expo-constants": "~18.0.9", - "expo-device": "~8.0.9", "expo-image-picker": "~17.0.8", "expo-linking": "~8.0.8", "expo-localization": "~17.0.7", diff --git a/package-lock.json b/package-lock.json index 7ac7bbf..b30f2a6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,6 @@ "@reduxjs/toolkit": "^2.9.0", "expo": "^54.0.0", "expo-constants": "~18.0.9", - "expo-device": "~8.0.9", "expo-image-picker": "~17.0.8", "expo-linking": "~8.0.8", "expo-localization": "~17.0.7", @@ -104,7 +103,6 @@ "@reduxjs/toolkit": "^2.9.0", "expo": "^54.0.0", "expo-constants": "~18.0.9", - "expo-device": "~8.0.9", "expo-image-picker": "~17.0.8", "expo-linking": "~8.0.8", "expo-localization": "~17.0.7", @@ -14380,18 +14378,6 @@ "react-native": "*" } }, - "node_modules/expo-device": { - "version": "8.0.9", - "resolved": "https://registry.npmjs.org/expo-device/-/expo-device-8.0.9.tgz", - "integrity": "sha512-XqRpaljDNAYZGZzMpC+b9KZfzfydtkwx3pJAp6ODDH+O/5wjAw+mLc5wQMGJCx8/aqVmMsAokec7iebxDPFZDA==", - "license": "MIT", - "dependencies": { - "ua-parser-js": "^0.7.33" - }, - "peerDependencies": { - "expo": "*" - } - }, "node_modules/expo-eas-client": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/expo-eas-client/-/expo-eas-client-1.0.7.tgz", @@ -27684,32 +27670,6 @@ "typescript": ">=4.8.4 <6.0.0" } }, - "node_modules/ua-parser-js": { - "version": "0.7.41", - "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.41.tgz", - "integrity": "sha512-O3oYyCMPYgNNHuO7Jjk3uacJWZF8loBgwrfd/5LE/HyZ3lUIOdniQ7DNXJcIgZbwioZxk0fLfI4EVnetdiX5jg==", - "funding": [ - { - "type": "opencollective", - "url": "https://opencollective.com/ua-parser-js" - }, - { - "type": "paypal", - "url": "https://paypal.me/faisalman" - }, - { - "type": "github", - "url": "https://github.com/sponsors/faisalman" - } - ], - "license": "MIT", - "bin": { - "ua-parser-js": "script/cli.js" - }, - "engines": { - "node": "*" - } - }, "node_modules/unbox-primitive": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.1.0.tgz", diff --git a/package.json b/package.json index a3a114b..70e6b97 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,6 @@ "@reduxjs/toolkit": "^2.9.0", "expo": "^54.0.0", "expo-constants": "~18.0.9", - "expo-device": "~8.0.9", "expo-image-picker": "~17.0.8", "expo-linking": "~8.0.8", "expo-localization": "~17.0.7", diff --git a/src/lib/package.json b/src/lib/package.json index 8942578..e8946f4 100644 --- a/src/lib/package.json +++ b/src/lib/package.json @@ -64,7 +64,6 @@ "react-native": "*", "@reduxjs/toolkit": "*", "expo-constants": "*", - "expo-device": "*", "expo-image-picker": "*", "expo-localization": "*", "expo-modules-core": "*", @@ -90,9 +89,6 @@ "expo-constants": { "optional": true }, - "expo-device": { - "optional": true - }, "expo-image-picker": { "optional": true },