From 14f293e545a0bf6a74eec7152f8fe879a0dd1ce3 Mon Sep 17 00:00:00 2001 From: Bill Thornton Date: Mon, 19 Apr 2021 11:09:25 -0400 Subject: [PATCH] Use compare-versions for all version checks --- stores/SettingStore.js | 5 +++-- utils/Device.js | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/stores/SettingStore.js b/stores/SettingStore.js index 56c70a0..d5dddf5 100644 --- a/stores/SettingStore.js +++ b/stores/SettingStore.js @@ -3,6 +3,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +import compareVersions from 'compare-versions'; import { action, computed, decorate, observable } from 'mobx'; import { Platform } from 'react-native'; @@ -25,7 +26,7 @@ export default class SettingStore { /** * Is screen lock active when media is playing */ - isScreenLockEnabled = Platform.OS === 'ios' ? (parseInt(Platform.Version, 10) < 14) : true + isScreenLockEnabled = Platform.OS === 'ios' ? !!Platform.Version && compareVersions.compare(Platform.Version, '14', '<') : true /** * Are tab labels enabled @@ -65,7 +66,7 @@ export default class SettingStore { reset() { this.activeServer = 0; this.isRotationLockEnabled = Platform.OS === 'ios' && !Platform.isPad; - this.isScreenLockEnabled = Platform.OS === 'ios' ? (parseInt(Platform.Version, 10) < 14) : true; + this.isScreenLockEnabled = Platform.OS === 'ios' ? !!Platform.Version && compareVersions.compare(Platform.Version, '14', '<') : true; this.isTabLabelsEnabled = true; this.themeId = 'dark'; this.systemThemeId = null; diff --git a/utils/Device.js b/utils/Device.js index ff194ed..6916711 100644 --- a/utils/Device.js +++ b/utils/Device.js @@ -3,6 +3,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +import compareVersions from 'compare-versions'; import Constants from 'expo-constants'; import * as Device from 'expo-device'; import { Platform } from 'react-native'; @@ -33,9 +34,9 @@ export function getSafeDeviceName() { export function getDeviceProfile({ enableFmp4 = false } = {}) { if (Platform.OS === 'ios') { - if (parseInt(Platform.Version, 10) < 11) { + if (compareVersions.compare(Platform.Version, '11', '<')) { return iOS10Profile; - } else if (parseInt(Platform.Version, 10) < 13) { + } else if (compareVersions.compare(Platform.Version, '13', '<')) { return iOS12Profile; } else if (enableFmp4) { return iOSFmp4Profile; @@ -53,6 +54,6 @@ export function isCompact({ height = 500 } = {}) { // Does the platform support system level themes: https://docs.expo.io/versions/latest/sdk/appearance/ export function isSystemThemeSupported() { - return (Platform.OS === 'ios' && parseInt(Platform.Version, 10) > 12) || - (Platform.OS === 'android' && parseInt(Platform.Version, 10) > 9); + return (Platform.OS === 'ios' && compareVersions.compare(Platform.Version, '12', '>')) || + (Platform.OS === 'android' && compareVersions.compare(Platform.Version, '9', '>')); }