Skip to content

Commit

Permalink
feat: Added DeviceTypeDesktop to getDeviceType() (#1137)
Browse files Browse the repository at this point in the history
* Added DeviceTypeDesktop (true for windows, catalyst target builds, and macos builds
* Using Platform.OS to detect windows version and return Desktop

Co-authored-by: vinzenz <vinzenz@nsynk.de>
  • Loading branch information
exotexot and vinzenz committed Jan 2, 2021
1 parent 28554e2 commit c9ae5f7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
6 changes: 4 additions & 2 deletions ios/RNDeviceInfo/RNDeviceInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ typedef NS_ENUM(NSInteger, DeviceType) {
DeviceTypeHandset,
DeviceTypeTablet,
DeviceTypeTv,
DeviceTypeDesktop,
DeviceTypeUnknown
};

#define DeviceTypeValues [NSArray arrayWithObjects: @"Handset", @"Tablet", @"Tv", @"unknown", nil]
#define DeviceTypeValues [NSArray arrayWithObjects: @"Handset", @"Tablet", @"Tv", @"Desktop", @"unknown", nil]

#if !(TARGET_OS_TV)
@import CoreTelephony;
Expand Down Expand Up @@ -110,8 +111,9 @@ - (DeviceType) getDeviceType
{
switch ([[UIDevice currentDevice] userInterfaceIdiom]) {
case UIUserInterfaceIdiomPhone: return DeviceTypeHandset;
case UIUserInterfaceIdiomPad: return DeviceTypeTablet;
case UIUserInterfaceIdiomPad: return TARGET_OS_MACCATALYST ? DeviceTypeDesktop : DeviceTypeTablet;
case UIUserInterfaceIdiomTV: return DeviceTypeTv;
case UIUserInterfaceIdiomMac: return DeviceTypeDesktop;
default: return DeviceTypeUnknown;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/index.js.flow
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow

export type DeviceType = 'Handset' | 'Tablet' | 'Tv' | 'unknown';
export type DeviceType = 'Handset' | 'Tablet' | 'Tv' | 'Desktop' | 'unknown';

export type BatteryState = 'unknown' | 'unplugged' | 'charging' | 'full';

Expand Down
16 changes: 12 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,21 +558,29 @@ export const [isAirplaneMode, isAirplaneModeSync] = getSupportedPlatformInfoFunc
defaultValue: false,
});

export const getDeviceType = () =>
getSupportedPlatformInfoSync({
export const getDeviceType = () => {

if (Platform.OS === "windows") return "Desktop"

return getSupportedPlatformInfoSync({
memoKey: 'deviceType',
supportedPlatforms: ['android', 'ios'],
defaultValue: 'unknown',
getter: () => RNDeviceInfo.deviceType,
});
}

export const getDeviceTypeSync = () =>
getSupportedPlatformInfoSync({
export const getDeviceTypeSync = () => {

if (Platform.OS === "windows") return "Desktop"

return getSupportedPlatformInfoSync({
memoKey: 'deviceType',
supportedPlatforms: ['android', 'ios'],
defaultValue: 'unknown',
getter: () => RNDeviceInfo.deviceType,
});
}

export const [supportedAbis, supportedAbisSync] = getSupportedPlatformInfoFunctions({
memoKey: '_supportedAbis',
Expand Down
2 changes: 1 addition & 1 deletion src/internal/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type DeviceType = 'Handset' | 'Tablet' | 'Tv' | 'unknown';
export type DeviceType = 'Handset' | 'Tablet' | 'Tv' | 'Desktop' | 'unknown';

export type BatteryState = 'unknown' | 'unplugged' | 'charging' | 'full';

Expand Down

0 comments on commit c9ae5f7

Please sign in to comment.