Skip to content

Commit

Permalink
Merge pull request #91 from duskload/feature/Add-Edge-Chromium
Browse files Browse the repository at this point in the history
Feature/add edge chromium
  • Loading branch information
duskload authored Jun 15, 2020
2 parents e9b170e + ee0ae0d commit 7153b07
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 16 deletions.
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const styles = {
| isSafari | bool | returns true if browser is `Safari` |
| isOpera | bool | returns true if browser is `Opera` |
| isIE | bool | returns true if browser is `Internet Explorer` |
| isEdge | bool | returns true if browser is `Edge` |
| isEdge | bool | returns true if browser is `Edge` or `Edge Chromium` |
| isYandex | bool | returns true if browser is `Yandex` |
| isChromium | bool | returns true if browser is `Chromium` |
| isMobileSafari | bool | returns true if browser is `Mobile Safari` |
Expand All @@ -146,9 +146,12 @@ const styles = {
| isIPhone13 | boolean | returns true/false if device is iPhone and running on iOS13 |
| isIPad13 | boolean | returns true/false if device is iPad and running on iOS13 |
| isIPod13 | boolean | returns true/false if device is iPod and running on iOS13 |
| isElectron | boolean | returns true/false if running on Electron |
| deviceDetect | function | return data object which includes all data about device (e.g version, engine, os etc.) |

| isElectron | boolean | returns true/false if running on `Electron` |
| isEdgeChromium | boolean | returns true/false if browser is `Edge Chromium` |
| isLegacyEdge | boolean | returns true if browser is `Edge` |
| isWindows | boolean | returns true/false if os is `Windows` |
| isMacOs | boolean | returns true/false if os is `Mac OS` |
| deviceDetect | boolean | return data object which includes all data about device (e.g version, engine, os etc.) |
### Views

Available views:
Expand Down Expand Up @@ -196,6 +199,17 @@ App = withOrientationChange(App)
export { App }
```

### Testing

```js
import * as rdd from 'react-device-detect';

rdd.isMobile = true;

// use in tests

```

## License

MIT
12 changes: 12 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ declare module "react-device-detect" {
export import isIPhone13 = ReactDeviceDetect.isIPhone13;
export import isIPod13 = ReactDeviceDetect.isIPod13;
export import isElectron = ReactDeviceDetect.isElectron;
export import isEdgeChromium = ReactDeviceDetect.isEdgeChromium;
export import isLegacyEdge = ReactDeviceDetect.isLegacyEdge;
export import isWindows = ReactDeviceDetect.isWindows;
export import isMacOs = ReactDeviceDetect.isMacOs;
export import withOrientationChange = ReactDeviceDetect.withOrientationChange;
}

Expand Down Expand Up @@ -184,4 +188,12 @@ declare namespace ReactDeviceDetect {
export const isIPod13: boolean;

export const isElectron: boolean;

export const isEdgeChromium: boolean;

export const isLegacyEdge: boolean;

export const isWindows: boolean;

export const isMacOs: boolean;
}
35 changes: 31 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var getNavigatorInstance = function getNavigatorInstance() {
};
var isIOS13Check = function isIOS13Check(type) {
var nav = getNavigatorInstance();
return nav && (nav.platform.indexOf(type) !== -1 || nav.platform === 'MacIntel' && nav.maxTouchPoints > 1 && !window.MSStream);
return nav && nav.platform && (nav.platform.indexOf(type) !== -1 || nav.platform === 'MacIntel' && nav.maxTouchPoints > 1 && !window.MSStream);
};

function _typeof(obj) {
Expand Down Expand Up @@ -203,12 +203,15 @@ var BROWSER_TYPES = {
EDGE: "Edge",
CHROMIUM: "Chromium",
IE: 'IE',
MOBILE_SAFARI: "Mobile Safari"
MOBILE_SAFARI: "Mobile Safari",
EDGE_CHROMIUM: "Edge Chromium"
};
var OS_TYPES = {
IOS: 'iOS',
ANDROID: "Android",
WINDOWS_PHONE: "Windows Phone"
WINDOWS_PHONE: "Windows Phone",
WINDOWS: 'Windows',
MAC_OS: 'Mac OS'
};
var initialData = {
isMobile: false,
Expand Down Expand Up @@ -361,6 +364,14 @@ var isMobileAndTabletType = function isMobileAndTabletType() {
}
};

var isEdgeChromiumType = function isEdgeChromiumType() {
if (os.name === OS_TYPES.WINDOWS && os.version === '10') {
return typeof ua === 'string' && ua.indexOf('Edg/') !== -1;
}

return false;
};

var isSmartTVType = function isSmartTVType() {
return device.type === DEVICE_TYPES.SMART_TV;
};
Expand All @@ -381,6 +392,14 @@ var isAndroidType = function isAndroidType() {
return os.name === OS_TYPES.ANDROID;
};

var isWindowsType = function isWindowsType() {
return os.name === OS_TYPES.WINDOWS;
};

var isMacOsType = function isMacOsType() {
return os.name === OS_TYPES.MAC_OS;
};

var isWinPhoneType = function isWinPhoneType() {
return os.name === OS_TYPES.WINDOWS_PHONE;
};
Expand Down Expand Up @@ -519,14 +538,18 @@ var mobileModel = getMobileModel();
var engineName = getEngineName();
var engineVersion = getEngineVersion();
var getUA = getUseragent();
var isEdge = isEdgeType();
var isEdge = isEdgeType() || isEdgeChromiumType();
var isYandex = isYandexType();
var deviceType = getDeviceType();
var isIOS13 = getIOS13();
var isIPad13 = getIPad13();
var isIPhone13 = getIphone13();
var isIPod13 = getIPod13();
var isElectron = isElectronType();
var isEdgeChromium = isEdgeChromiumType();
var isLegacyEdge = isEdgeType();
var isWindows = isWindowsType();
var isMacOs = isMacOsType();

var AndroidView = function AndroidView(_ref) {
var renderWithFragment = _ref.renderWithFragment,
Expand Down Expand Up @@ -756,6 +779,7 @@ exports.isChrome = isChrome;
exports.isChromium = isChromium;
exports.isConsole = isConsole;
exports.isEdge = isEdge;
exports.isEdgeChromium = isEdgeChromium;
exports.isElectron = isElectron;
exports.isFirefox = isFirefox;
exports.isIE = isIE;
Expand All @@ -764,6 +788,8 @@ exports.isIOS13 = isIOS13;
exports.isIPad13 = isIPad13;
exports.isIPhone13 = isIPhone13;
exports.isIPod13 = isIPod13;
exports.isLegacyEdge = isLegacyEdge;
exports.isMacOs = isMacOs;
exports.isMobile = isMobile;
exports.isMobileOnly = isMobileOnly;
exports.isMobileSafari = isMobileSafari;
Expand All @@ -773,6 +799,7 @@ exports.isSmartTV = isSmartTV;
exports.isTablet = isTablet;
exports.isWearable = isWearable;
exports.isWinPhone = isWinPhone;
exports.isWindows = isWindows;
exports.isYandex = isYandex;
exports.mobileModel = mobileModel;
exports.mobileVendor = mobileVendor;
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-device-detect",
"version": "1.12.1",
"version": "1.13.1",
"description": "Detect device type and render your component according to it",
"main": "main.js",
"typings": "./index.d.ts",
Expand Down
16 changes: 15 additions & 1 deletion src/components/helpers/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,21 @@ const isMobileAndTabletType = () => {
}
};

const isEdgeChromiumType = () => {
if (os.name === OS_TYPES.WINDOWS && os.version === '10') {
return typeof ua === 'string' && ua.indexOf('Edg/') !== -1;
}

return false;
};

const isSmartTVType = () => device.type === DEVICE_TYPES.SMART_TV;
const isBrowserType = () => device.type === DEVICE_TYPES.BROWSER;
const isWearableType = () => device.type === DEVICE_TYPES.WEARABLE;
const isConsoleType = () => device.type === DEVICE_TYPES.CONSOLE;
const isAndroidType = () => os.name === OS_TYPES.ANDROID;
const isWindowsType = () => os.name === OS_TYPES.WINDOWS;
const isMacOsType = () => os.name === OS_TYPES.MAC_OS;
const isWinPhoneType = () => os.name === OS_TYPES.WINDOWS_PHONE;
const isIOSType = () => os.name === OS_TYPES.IOS;
const isChromeType = () => browser.name === BROWSER_TYPES.CHROME;
Expand Down Expand Up @@ -89,11 +99,15 @@ export const mobileModel = getMobileModel();
export const engineName = getEngineName();
export const engineVersion = getEngineVersion();
export const getUA = getUseragent();
export const isEdge = isEdgeType();
export const isEdge = isEdgeType() || isEdgeChromiumType();
export const isYandex = isYandexType();
export const deviceType = getDeviceType();
export const isIOS13 = getIOS13();
export const isIPad13 = getIPad13();
export const isIPhone13 = getIphone13();
export const isIPod13 = getIPod13();
export const isElectron = isElectronType();
export const isEdgeChromium = isEdgeChromiumType();
export const isLegacyEdge = isEdgeType();
export const isWindows = isWindowsType();
export const isMacOs = isMacOsType();
7 changes: 5 additions & 2 deletions src/components/helpers/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ export const BROWSER_TYPES = {
EDGE: "Edge",
CHROMIUM: "Chromium",
IE: 'IE',
MOBILE_SAFARI: "Mobile Safari"
MOBILE_SAFARI: "Mobile Safari",
EDGE_CHROMIUM: "Edge Chromium"
};

export const OS_TYPES = {
IOS: 'iOS',
ANDROID: "Android",
WINDOWS_PHONE: "Windows Phone"
WINDOWS_PHONE: "Windows Phone",
WINDOWS: 'Windows',
MAC_OS: 'Mac OS'
};

const initialData = {
Expand Down

0 comments on commit 7153b07

Please sign in to comment.