Skip to content

Commit d42e3d0

Browse files
committed
userAgent [nfc]: Use RN's Platform API; drop react-native-device-info
Oddly, on Android, react-native-device-info brings in some Firebase dependencies that we don't need: https://github.com/react-native-device-info/react-native-device-info/blob/v8.7.1/android/build.gradle#L54-L64 Also this dependency seems to have needed a bit of complexity to keep around; see the output of git log --grep='react-native-device-info' Remove it, since we can get the same information in the same form from RN's Platform API. To verify that it's all the same: - For the "system name" piece (given previously by r-n-device-info's `getSystemName`): - iOS: - r-n-device-info was using Apple's UIDevice.systemName: https://github.com/react-native-device-info/react-native-device-info/blob/v8.7.1/ios/RNDeviceInfo/RNDeviceInfo.m#L142 - `Platform.constants.systemName` uses the same thing: https://github.com/facebook/react-native/blob/v0.68.5/React/CoreModules/RCTPlatform.mm#L68 - Android: - r-n-device-info was using the string 'Android': https://github.com/react-native-device-info/react-native-device-info/blob/v8.7.1/android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java#L195 - (so, copy that) - For the "system version" piece (given previously by r-n-device-info's `getSystemVersion`: - iOS: - r-n-device-info was using Apple's UIDevice.systemVersion: https://github.com/react-native-device-info/react-native-device-info/blob/v8.7.1/ios/RNDeviceInfo/RNDeviceInfo.m#L147 - `Platform.constants.osVersion` uses the same thing: https://github.com/facebook/react-native/blob/v0.68.5/React/CoreModules/RCTPlatform.mm#L67 - Android: - r-n-device-info was using Android's Build.VERSION.RELEASE: https://github.com/react-native-device-info/react-native-device-info/blob/v8.7.1/android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java#L196 - `Platform.constants.Release` uses the same thing: https://github.com/facebook/react-native/blob/v0.68.5/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/AndroidInfoModule.java#L69
1 parent cab2167 commit d42e3d0

File tree

6 files changed

+39
-20
lines changed

6 files changed

+39
-20
lines changed

ios/Podfile.lock

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,6 @@ PODS:
406406
- React
407407
- RNCPushNotificationIOS (1.10.1):
408408
- React-Core
409-
- RNDeviceInfo (8.7.1):
410-
- React-Core
411409
- RNGestureHandler (2.9.0):
412410
- React-Core
413411
- RNReanimated (2.2.4):
@@ -537,7 +535,6 @@ DEPENDENCIES:
537535
- "RNCClipboard (from `../node_modules/@react-native-clipboard/clipboard`)"
538536
- "RNCMaskedView (from `../node_modules/@react-native-community/masked-view`)"
539537
- "RNCPushNotificationIOS (from `../node_modules/@react-native-community/push-notification-ios`)"
540-
- RNDeviceInfo (from `../node_modules/react-native-device-info`)
541538
- RNGestureHandler (from `../node_modules/react-native-gesture-handler`)
542539
- RNReanimated (from `../node_modules/react-native-reanimated`)
543540
- RNScreens (from `../node_modules/react-native-screens`)
@@ -678,8 +675,6 @@ EXTERNAL SOURCES:
678675
:path: "../node_modules/@react-native-community/masked-view"
679676
RNCPushNotificationIOS:
680677
:path: "../node_modules/@react-native-community/push-notification-ios"
681-
RNDeviceInfo:
682-
:path: "../node_modules/react-native-device-info"
683678
RNGestureHandler:
684679
:path: "../node_modules/react-native-gesture-handler"
685680
RNReanimated:
@@ -763,7 +758,6 @@ SPEC CHECKSUMS:
763758
RNCClipboard: 3f0451a8100393908bea5c5c5b16f96d45f30bfc
764759
RNCMaskedView: 0e1bc4bfa8365eba5fbbb71e07fbdc0555249489
765760
RNCPushNotificationIOS: 87b8d16d3ede4532745e05b03c42cff33a36cc45
766-
RNDeviceInfo: aad3c663b25752a52bf8fce93f2354001dd185aa
767761
RNGestureHandler: 071d7a9ad81e8b83fe7663b303d132406a7d8f39
768762
RNReanimated: e7d8afaf8fed4b3bf1a46e06adb2e04a2b248f1c
769763
RNScreens: 218801c16a2782546d30bd2026bb625c0302d70f

jest/jestSetup.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,6 @@ jest.mock('react-native-simple-toast', () => ({
139139
showWithGravity: jest.fn(),
140140
}));
141141

142-
jest.mock('react-native-device-info', () => ({
143-
getSystemName: jest.fn().mockReturnValue('ios'),
144-
getSystemVersion: jest.fn().mockReturnValue('13.3.1'),
145-
}));
146-
147142
// Set up our `logging` module with mocks, which tests can use as desired.
148143
//
149144
// This global version just passes the calls right through to the real

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
"react": "17.0.2",
5959
"react-intl": "5.24.6",
6060
"react-native": "0.68.5",
61-
"react-native-device-info": "^8.1.7",
6261
"react-native-document-picker": "^8.1.3",
6362
"react-native-gesture-handler": "^2.8.0",
6463
"react-native-image-picker": "4.10.3",

src/reactNativeUtils.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,20 @@ export function androidSdkVersion(): number {
8484
// 10 it won't be 10, it'll be 29.
8585
return (Platform.Version: number);
8686
}
87+
88+
/**
89+
* The Android user-visible version string, with no promised structure.
90+
*/
91+
// This is Build.VERSION.RELEASE as of RN v0.68.5:
92+
// https://reactnative.dev/docs/platform#constants
93+
// https://github.com/facebook/react-native/blob/v0.68.5/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/AndroidInfoModule.java#L69
94+
// https://developer.android.com/reference/android/os/Build.VERSION#RELEASE
95+
export function androidRelease(): string {
96+
invariant(Platform.OS === 'android', 'androidRelease called on iOS');
97+
98+
// Flow isn't refining `Platform` to a type that corresponds to values
99+
// we'll see on Android.
100+
//
101+
// (If changing the implementation, adjust comment below jsdoc.)
102+
return (Platform.constants.Release: string);
103+
}

src/utils/userAgent.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
11
/* @flow strict-local */
2-
import DeviceInfo from 'react-native-device-info';
32
import { nativeApplicationVersion } from 'expo-application';
3+
import { Platform } from 'react-native';
44

5-
const { getSystemName, getSystemVersion } = DeviceInfo;
5+
import { androidRelease } from '../reactNativeUtils';
6+
7+
const systemName =
8+
// prettier-ignore
9+
Platform.OS === 'ios'
10+
// Probably "iOS" on all iOS devices we support (was "iPhone OS" long ago):
11+
// https://github.com/facebook/react-native/blob/v0.68.5/React/CoreModules/RCTPlatform.mm#L68
12+
// https://developer.apple.com/documentation/uikit/uidevice/1620054-systemname?language=objc
13+
? Platform.constants.systemName
14+
: 'Android';
15+
16+
const systemVersion =
17+
// prettier-ignore
18+
Platform.OS === 'ios'
19+
// E.g. "16.4" for iOS 16.4:
20+
// https://github.com/facebook/react-native/blob/v0.68.5/React/CoreModules/RCTPlatform.mm#L67
21+
// https://developer.apple.com/documentation/uikit/uidevice/1620043-systemversion?language=objc
22+
? `${Platform.constants.osVersion}`
23+
// (E.g. '13' for Android 13 Tiramisu)
24+
: androidRelease();
625

726
export default `ZulipMobile/${
827
nativeApplicationVersion ?? '?.?.?'
9-
} (${getSystemName()} ${getSystemVersion()})`;
28+
} (${systemName} ${systemVersion})`;

yarn.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10378,11 +10378,6 @@ react-native-codegen@^0.0.18:
1037810378
jscodeshift "^0.13.1"
1037910379
nullthrows "^1.1.1"
1038010380

10381-
react-native-device-info@^8.1.7:
10382-
version "8.7.1"
10383-
resolved "https://registry.yarnpkg.com/react-native-device-info/-/react-native-device-info-8.7.1.tgz#fbb06f87dbbc4423abe713874699fb2e6e99fd15"
10384-
integrity sha512-cVMZztFa2Qn6qpQa601W61CtUwZQ1KXfqCOeltejAWEXmgIWivC692WGSdtGudj4upSi1UgMSaGcvKjfcpdGjg==
10385-
1038610381
react-native-document-picker@^8.1.3:
1038710382
version "8.2.0"
1038810383
resolved "https://registry.yarnpkg.com/react-native-document-picker/-/react-native-document-picker-8.2.0.tgz#d0d2f9ff8667e90e7ff6f9733077043e3f86d1a9"

0 commit comments

Comments
 (0)