From e24f25d75851080da162486db93e32125c34d9a9 Mon Sep 17 00:00:00 2001 From: Yousif Ahmed Date: Fri, 31 May 2024 16:47:26 +0100 Subject: [PATCH 1/2] fix(plugin-expo-device): do not use expo-secure-store on unsupported platforms --- packages/plugin-expo-device/device.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/plugin-expo-device/device.js b/packages/plugin-expo-device/device.js index 4cfce87c..30260cec 100644 --- a/packages/plugin-expo-device/device.js +++ b/packages/plugin-expo-device/device.js @@ -25,15 +25,18 @@ module.exports = { // get the initial orientation updateOrientation() - const storeOptions = { - requireAuthentication: false, - keychainAccessible: SecureStore.ALWAYS_THIS_DEVICE_ONLY - } + let deviceId + if (Platform.OS === 'android' || Platform.OS === 'ios') { + const storeOptions = { + requireAuthentication: false, + keychainAccessible: SecureStore.ALWAYS_THIS_DEVICE_ONLY + } - let deviceId = SecureStore.getItem(DEVICE_ID_KEY, storeOptions) - if (!deviceId || !cuid.isCuid(deviceId)) { - deviceId = cuid() - SecureStore.setItem(DEVICE_ID_KEY, deviceId, storeOptions) + deviceId = SecureStore.getItem(DEVICE_ID_KEY, storeOptions) + if (!deviceId || !cuid.isCuid(deviceId)) { + deviceId = cuid() + SecureStore.setItem(DEVICE_ID_KEY, deviceId, storeOptions) + } } const device = { From d9b38cddc89a90ff7f8711dcd40025dd9e73b16d Mon Sep 17 00:00:00 2001 From: Yousif Ahmed Date: Mon, 3 Jun 2024 10:28:56 +0100 Subject: [PATCH 2/2] fix: replace Constants.platform usage with Platform API --- packages/plugin-expo-app/app.js | 6 +++--- packages/plugin-expo-app/test/app.test.js | 13 +++++++++++-- packages/plugin-expo-device/device.js | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/plugin-expo-app/app.js b/packages/plugin-expo-app/app.js index 93e79202..43b3f4a6 100644 --- a/packages/plugin-expo-app/app.js +++ b/packages/plugin-expo-app/app.js @@ -1,6 +1,6 @@ const Application = require('expo-application') const Constants = require('expo-constants').default -const { AppState } = require('react-native') +const { AppState, Platform } = require('react-native') const appStart = new Date() @@ -19,9 +19,9 @@ module.exports = { let bundleVersion, versionCode if (Constants.appOwnership !== 'expo') { - if (Constants.platform.ios) { + if (Platform.OS === 'ios') { bundleVersion = Application.nativeBuildVersion - } else if (Constants.platform.android) { + } else if (Platform.OS === 'android') { versionCode = Application.nativeBuildVersion } } diff --git a/packages/plugin-expo-app/test/app.test.js b/packages/plugin-expo-app/test/app.test.js index 993f9757..435bd482 100644 --- a/packages/plugin-expo-app/test/app.test.js +++ b/packages/plugin-expo-app/test/app.test.js @@ -4,7 +4,8 @@ jest.mock('react-native', () => ({ AppState: { addEventListener: jest.fn(), currentState: 'active' - } + }, + Platform: { OS: 'android' } })) describe('plugin: expo app', () => { @@ -66,6 +67,13 @@ describe('plugin: expo app', () => { appOwnership: null } })) + jest.doMock('react-native', () => ({ + AppState: { + addEventListener: jest.fn(), + currentState: 'active' + }, + Platform: { OS: 'ios' } + })) const plugin = require('..') @@ -109,7 +117,8 @@ describe('plugin: expo app', () => { })) jest.doMock('react-native', () => ({ - AppState + AppState, + Platform: { OS: 'ios' } })) const plugin = require('..') diff --git a/packages/plugin-expo-device/device.js b/packages/plugin-expo-device/device.js index 30260cec..ccd2fc3f 100644 --- a/packages/plugin-expo-device/device.js +++ b/packages/plugin-expo-device/device.js @@ -50,7 +50,7 @@ module.exports = { reactNative: rnVersion, expoApp: Constants.expoVersion, expoSdk: Constants.expoConfig?.sdkVersion, - androidApiLevel: Constants.platform.android ? String(Platform.Version) : undefined + androidApiLevel: Platform.OS === 'android' ? String(Platform.Version) : undefined }, totalMemory: Device.totalMemory }