From c524cdde248849c0d0456c15c2475443d69eacab Mon Sep 17 00:00:00 2001 From: Dustin Schie Date: Tue, 6 Oct 2020 20:48:30 -0400 Subject: [PATCH 1/7] refactor(src/index.ts): rewriting `getUsedMemory*` rewrites `getUsedMemory` and `getUsedMemorySync` to use `getSupportedPlatformInfoFunctions` re #1085 --- src/index.ts | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/index.ts b/src/index.ts index 4dc5b3c50..94a824ef7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -365,19 +365,12 @@ export const [getDeviceName, getDeviceNameSync] = getSupportedPlatformInfoFuncti defaultValue: 'unknown', }); -export async function getUsedMemory() { - if (Platform.OS === 'android' || Platform.OS === 'ios' || Platform.OS === 'web') { - return RNDeviceInfo.getUsedMemory(); - } - return -1; -} - -export function getUsedMemorySync() { - if (Platform.OS === 'android' || Platform.OS === 'ios' || Platform.OS === 'web') { - return RNDeviceInfo.getUsedMemorySync(); - } - return -1; -} +export const [getUsedMemory, getUsedMemorySync] = getSupportedPlatformInfoFunctions({ + supportedPlatforms: ['android', 'ios', 'web'], + getter: () => RNDeviceInfo.getUsedMemory(), + syncGetter: () => RNDeviceInfo.getUsedMemorySync(), + defaultValue: -1, +}); let userAgent: string; export async function getUserAgent() { From 50cc7cdc21873307810148ca3607eb696a259d8e Mon Sep 17 00:00:00 2001 From: Dustin Schie Date: Tue, 6 Oct 2020 21:09:54 -0400 Subject: [PATCH 2/7] refactor(src/index.ts): rewriting `getBuildId*` rewrites `getBuildId` and `getBuildIdSync` to use `getSupportedPlatformInfoFunctions` re #1085 --- src/index.ts | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/src/index.ts b/src/index.ts index 94a824ef7..505c1d933 100644 --- a/src/index.ts +++ b/src/index.ts @@ -234,28 +234,13 @@ export function getSystemVersion() { return systemVersion; } -let buildId: string; -export async function getBuildId() { - if (!buildId) { - if (Platform.OS === 'android' || Platform.OS === 'ios') { - buildId = await RNDeviceInfo.getBuildId(); - } else { - buildId = 'unknown'; - } - } - return buildId; -} - -export function getBuildIdSync() { - if (!buildId) { - if (Platform.OS === 'android' || Platform.OS === 'ios') { - buildId = RNDeviceInfo.getBuildIdSync(); - } else { - buildId = 'unknown'; - } - } - return buildId; -} +export const [getBuildId, getBuildIdSync] = getSupportedPlatformInfoFunctions({ + memoKey: 'buildId', + supportedPlatforms: ['android', 'ios'], + getter: () => RNDeviceInfo.getBuildId(), + syncGetter: () => RNDeviceInfo.getBuildIdSync(), + defaultValue: 'unknown', +}); let apiLevel: number; export async function getApiLevel() { From 4071c3b9215d0a175011a964980b777925ca3bb5 Mon Sep 17 00:00:00 2001 From: Dustin Schie Date: Tue, 6 Oct 2020 21:19:42 -0400 Subject: [PATCH 3/7] refactor(src/index.ts): rewriting `getApiLevel*` rewrites functions to use ``getSupportedPlatformInfoFunctions` re #1085 --- src/index.ts | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/src/index.ts b/src/index.ts index 505c1d933..591c5e5b6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -242,28 +242,13 @@ export const [getBuildId, getBuildIdSync] = getSupportedPlatformInfoFunctions({ defaultValue: 'unknown', }); -let apiLevel: number; -export async function getApiLevel() { - if (!apiLevel) { - if (Platform.OS === 'android') { - apiLevel = await RNDeviceInfo.getApiLevel(); - } else { - apiLevel = -1; - } - } - return apiLevel; -} - -export function getApiLevelSync() { - if (!apiLevel) { - if (Platform.OS === 'android') { - apiLevel = RNDeviceInfo.getApiLevelSync(); - } else { - apiLevel = -1; - } - } - return apiLevel; -} +export const [getApiLevel, getApiLevelSync] = getSupportedPlatformInfoFunctions({ + memoKey: 'apiLevel', + supportedPlatforms: ['android'], + getter: () => RNDeviceInfo.getApiLevel(), + syncGetter: () => RNDeviceInfo.getApiLevelSync(), + defaultValue: -1, +}); let bundleId: string; export function getBundleId() { From 749ca99192fc52f3616c8a2d287bfaf65e33cb1f Mon Sep 17 00:00:00 2001 From: Dustin Schie Date: Tue, 6 Oct 2020 21:53:59 -0400 Subject: [PATCH 4/7] refactor(src/index.ts): rewriting `getInstallerPackageName*` rewrites functions to use ``getSupportedPlatformInfoFunctions` re #1085 --- src/index.ts | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/src/index.ts b/src/index.ts index 591c5e5b6..1bc039222 100644 --- a/src/index.ts +++ b/src/index.ts @@ -262,30 +262,16 @@ export function getBundleId() { return bundleId; } -let installerPackageName: string; -export async function getInstallerPackageName() { - if (!installerPackageName) { - if (Platform.OS === 'android') { - installerPackageName = await RNDeviceInfo.getInstallerPackageName(); - } else { - installerPackageName = 'unknown'; - } - } - - return installerPackageName; -} - -export function getInstallerPackageNameSync() { - if (!installerPackageName) { - if (Platform.OS === 'android') { - installerPackageName = RNDeviceInfo.getInstallerPackageNameSync(); - } else { - installerPackageName = 'unknown'; - } - } - - return installerPackageName; -} +export const [ + getInstallerPackageName, + getInstallerPackageNameSync, +] = getSupportedPlatformInfoFunctions({ + memoKey: 'installerPackageName', + supportedPlatforms: ['android'], + getter: () => RNDeviceInfo.getInstallerPackageName(), + syncGetter: () => RNDeviceInfo.getInstallerPackageNameSync(), + defaultValue: 'unknown', +}); let appName: string; export function getApplicationName() { From 57195398a073cb5c94da7d92d35297c2489488e9 Mon Sep 17 00:00:00 2001 From: Dustin Schie Date: Tue, 6 Oct 2020 22:12:33 -0400 Subject: [PATCH 5/7] refactor(src/index.ts): rewriting `getFontScale*` rewrites functions to use ``getSupportedPlatformInfoFunctions` re #1085 --- src/index.ts | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/index.ts b/src/index.ts index 1bc039222..e3e0e60d2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -352,19 +352,12 @@ export function getUserAgentSync() { return userAgent; } -export async function getFontScale() { - if (Platform.OS === 'android' || Platform.OS === 'ios') { - return RNDeviceInfo.getFontScale(); - } - return -1; -} - -export function getFontScaleSync() { - if (Platform.OS === 'android' || Platform.OS === 'ios') { - return RNDeviceInfo.getFontScaleSync(); - } - return -1; -} +export const [getFontScale, getFontScaleSync] = getSupportedPlatformInfoFunctions({ + supportedPlatforms: ['android', 'ios'], + getter: () => RNDeviceInfo.getFontScale(), + syncGetter: () => RNDeviceInfo.getFontScaleSync(), + defaultValue: -1, +}); let bootloader: string; export async function getBootloader() { From d47df78042f4ebb927d20b0f7e7015c3d1b1a7b3 Mon Sep 17 00:00:00 2001 From: Dustin Schie Date: Tue, 6 Oct 2020 22:36:45 -0400 Subject: [PATCH 6/7] refactor(src/index.ts): rewriting `isPinOrFingerprintSet*` rewrites functions to use ``getSupportedPlatformInfoFunctions` re #1085 --- src/index.ts | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/index.ts b/src/index.ts index e3e0e60d2..5311e51fc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -701,19 +701,14 @@ export function isTablet() { return tablet; } -export async function isPinOrFingerprintSet() { - if (Platform.OS === 'android' || Platform.OS === 'ios' || Platform.OS === 'windows') { - return RNDeviceInfo.isPinOrFingerprintSet(); - } - return false; -} - -export function isPinOrFingerprintSetSync() { - if (Platform.OS === 'android' || Platform.OS === 'ios' || Platform.OS === 'windows') { - return RNDeviceInfo.isPinOrFingerprintSetSync(); - } - return false; -} +export const [isPinOrFingerprintSet, isPinOrFingerprintSetSync] = getSupportedPlatformInfoFunctions( + { + supportedPlatforms: ['android', 'ios', 'windows'], + getter: () => RNDeviceInfo.isPinOrFingerprintSet(), + syncGetter: () => RNDeviceInfo.isPinOrFingerprintSetSync(), + defaultValue: false, + } +); let notch: boolean; export function hasNotch() { From 7952fb14450c45f2ec51e20b4ca021d714620df4 Mon Sep 17 00:00:00 2001 From: Dustin Schie Date: Tue, 6 Oct 2020 22:52:13 -0400 Subject: [PATCH 7/7] refactor(src/index.ts): rewriting `getCarrier*` rewrites functions to use ``getSupportedPlatformInfoFunctions` re #1085 --- src/index.ts | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/index.ts b/src/index.ts index 5311e51fc..47e24eb65 100644 --- a/src/index.ts +++ b/src/index.ts @@ -808,19 +808,12 @@ export function getPhoneNumberSync() { return 'unknown'; } -export async function getCarrier() { - if (Platform.OS === 'android' || Platform.OS === 'ios') { - return RNDeviceInfo.getCarrier(); - } - return 'unknown'; -} - -export function getCarrierSync() { - if (Platform.OS === 'android' || Platform.OS === 'ios') { - return RNDeviceInfo.getCarrierSync(); - } - return 'unknown'; -} +export const [getCarrier, getCarrierSync] = getSupportedPlatformInfoFunctions({ + supportedPlatforms: ['android', 'ios'], + getter: () => RNDeviceInfo.getCarrier(), + syncGetter: () => RNDeviceInfo.getCarrierSync(), + defaultValue: 'unknown', +}); let totalMemory: number; export async function getTotalMemory() {