Skip to content

Commit 11bc765

Browse files
authored
Merge pull request #58 from duskload/RDD-55-56-57-Address-Issues
#55 #56 #57 address issues
2 parents 888c94d + 2ed07f3 commit 11bc765

File tree

6 files changed

+116
-23
lines changed

6 files changed

+116
-23
lines changed

index.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ declare module "react-device-detect" {
5151
export import getUA = ReactDeviceDetect.getUA;
5252
export import deviceType = ReactDeviceDetect.deviceType;
5353
export import deviceDetect = ReactDeviceDetect.deviceDetect;
54+
export import isIOS13 = ReactDeviceDetect.isIOS13;
55+
export import isIPad13 = ReactDeviceDetect.isIPad13;
56+
export import isIPhone13 = ReactDeviceDetect.isIPhone13;
57+
export import isIPod13 = ReactDeviceDetect.isIPod13;
5458
export import withOrientationChange = ReactDeviceDetect.withOrientationChange;
5559
}
5660

@@ -169,4 +173,12 @@ declare namespace ReactDeviceDetect {
169173
export const getUA: string;
170174

171175
export const deviceType: string;
176+
177+
export const isIOS13: boolean;
178+
179+
export const isIPad13: boolean;
180+
181+
export const isIPhone13: boolean;
182+
183+
export const isIPod13: boolean;
172184
}

main.js

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ var engine = UA.getEngine();
1717
var os = UA.getOS();
1818
var ua = UA.getUA();
1919
var setDefaults = function setDefaults(p) {
20-
var d = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'none';
20+
var d = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "none";
2121
return p ? p : d;
2222
};
23+
var isIOS13Check = function isIOS13Check(type) {
24+
return navigator.platform.includes(type) || navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1 && !window.MSStream;
25+
};
2326

2427
function _typeof(obj) {
2528
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
@@ -72,6 +75,24 @@ function _defineProperty(obj, key, value) {
7275
return obj;
7376
}
7477

78+
function _extends() {
79+
_extends = Object.assign || function (target) {
80+
for (var i = 1; i < arguments.length; i++) {
81+
var source = arguments[i];
82+
83+
for (var key in source) {
84+
if (Object.prototype.hasOwnProperty.call(source, key)) {
85+
target[key] = source[key];
86+
}
87+
}
88+
}
89+
90+
return target;
91+
};
92+
93+
return _extends.apply(this, arguments);
94+
}
95+
7596
function ownKeys(object, enumerableOnly) {
7697
var keys = Object.keys(object);
7798

@@ -393,6 +414,22 @@ var isIEType = function isIEType() {
393414
return browser.name === BROWSER_TYPES.INTERNET_EXPLORER || browser.name === BROWSER_TYPES.IE;
394415
};
395416

417+
var getIOS13 = function getIOS13() {
418+
return (/iPad|iPhone|iPod/.test(navigator.platform) || navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1) && !window.MSStream;
419+
};
420+
421+
var getIPad13 = function getIPad13() {
422+
return isIOS13Check("iPad");
423+
};
424+
425+
var getIphone13 = function getIphone13() {
426+
return isIOS13Check("iPhone");
427+
};
428+
429+
var getIPod13 = function getIPod13() {
430+
return isIOS13Check("iPod");
431+
};
432+
396433
var getBrowserFullVersion = function getBrowserFullVersion() {
397434
return setDefaults(browser.version);
398435
};
@@ -434,7 +471,7 @@ var getUseragent = function getUseragent() {
434471
};
435472

436473
var getDeviceType = function getDeviceType() {
437-
return setDefaults(device.type, '');
474+
return setDefaults(device.type, "browser");
438475
};
439476

440477
var isSmartTV = isSmartTVType();
@@ -467,6 +504,10 @@ var getUA = getUseragent();
467504
var isEdge = isEdgeType();
468505
var isYandex = isYandexType();
469506
var deviceType = getDeviceType();
507+
var isIOS13 = getIOS13();
508+
var isIPad13 = getIPad13();
509+
var isIPhone13 = getIphone13();
510+
var isIPod13 = getIPod13();
470511

471512
var AndroidView = function AndroidView(_ref) {
472513
var renderWithFragment = _ref.renderWithFragment,
@@ -658,10 +699,10 @@ function withOrientationChange(WrappedComponent) {
658699
}, {
659700
key: "render",
660701
value: function render() {
661-
return React__default.createElement(WrappedComponent, {
702+
return React__default.createElement(WrappedComponent, _extends({}, this.props, {
662703
isLandscape: this.state.isLandscape,
663704
isPortrait: this.state.isPortrait
664-
});
705+
}));
665706
}
666707
}]);
667708

@@ -699,6 +740,10 @@ exports.isEdge = isEdge;
699740
exports.isFirefox = isFirefox;
700741
exports.isIE = isIE;
701742
exports.isIOS = isIOS;
743+
exports.isIOS13 = isIOS13;
744+
exports.isIPad13 = isIPad13;
745+
exports.isIPhone13 = isIPhone13;
746+
exports.isIPod13 = isIPod13;
702747
exports.isMobile = isMobile;
703748
exports.isMobileOnly = isMobileOnly;
704749
exports.isMobileSafari = isMobileSafari;

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/helpers/get-ua-data.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,13 @@ export const mockUserAgent = userAgent => {
1414
window.navigator.__defineGetter__("userAgent", () => userAgent);
1515
};
1616

17-
export const setDefaults = (p, d = 'none') => p ? p : d
17+
export const setDefaults = (p, d = "none") => (p ? p : d);
18+
19+
export const isIOS13Check = type => {
20+
return (
21+
navigator.platform.includes(type) ||
22+
(navigator.platform === "MacIntel" &&
23+
navigator.maxTouchPoints > 1 &&
24+
!window.MSStream)
25+
);
26+
};

src/components/helpers/selectors.js

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { os, device, browser, ua, engine, setDefaults } from "./get-ua-data";
1+
import {
2+
os,
3+
device,
4+
browser,
5+
ua,
6+
engine,
7+
setDefaults,
8+
isIOS13Check
9+
} from "./get-ua-data";
210
import { BROWSER_TYPES, DEVICE_TYPES, OS_TYPES } from "./types";
311

412
const isMobileType = () => device.type === DEVICE_TYPES.MOBILE;
@@ -27,11 +35,25 @@ const isChromiumType = () => browser.name === BROWSER_TYPES.CHROMIUM;
2735
const isEdgeType = () => browser.name === BROWSER_TYPES.EDGE;
2836
const isYandexType = () => browser.name === BROWSER_TYPES.YANDEX;
2937
const isSafariType = () =>
30-
browser.name === BROWSER_TYPES.SAFARI || browser.name === BROWSER_TYPES.MOBILE_SAFARI;
38+
browser.name === BROWSER_TYPES.SAFARI ||
39+
browser.name === BROWSER_TYPES.MOBILE_SAFARI;
3140
const isMobileSafariType = () => browser.name === BROWSER_TYPES.MOBILE_SAFARI;
3241
const isOperaType = () => browser.name === BROWSER_TYPES.OPERA;
3342
const isIEType = () =>
34-
browser.name === BROWSER_TYPES.INTERNET_EXPLORER || browser.name === BROWSER_TYPES.IE;
43+
browser.name === BROWSER_TYPES.INTERNET_EXPLORER ||
44+
browser.name === BROWSER_TYPES.IE;
45+
46+
const getIOS13 = () => {
47+
return (
48+
(/iPad|iPhone|iPod/.test(navigator.platform) ||
49+
(navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1)) &&
50+
!window.MSStream
51+
);
52+
};
53+
54+
const getIPad13 = () => isIOS13Check("iPad");
55+
const getIphone13 = () => isIOS13Check("iPhone");
56+
const getIPod13 = () => isIOS13Check("iPod");
3557

3658
const getBrowserFullVersion = () => setDefaults(browser.version);
3759
const getBrowserVersion = () => setDefaults(browser.major);
@@ -43,7 +65,7 @@ const getMobileModel = () => setDefaults(device.model);
4365
const getEngineName = () => setDefaults(engine.name);
4466
const getEngineVersion = () => setDefaults(engine.version);
4567
const getUseragent = () => setDefaults(ua);
46-
const getDeviceType = () => setDefaults(device.type, '')
68+
const getDeviceType = () => setDefaults(device.type, "browser");
4769

4870
export const isSmartTV = isSmartTVType();
4971
export const isConsole = isConsoleType();
@@ -75,3 +97,7 @@ export const getUA = getUseragent();
7597
export const isEdge = isEdgeType();
7698
export const isYandex = isYandexType();
7799
export const deviceType = getDeviceType();
100+
export const isIOS13 = getIOS13()
101+
export const isIPad13 = getIPad13()
102+
export const isIPhone13 = getIphone13()
103+
export const isIPod13 = getIPod13()

src/components/helpers/withOrientationChange.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,36 @@ function withOrientationChange(WrappedComponent) {
88

99
this.isEventListenerAdded = false;
1010

11-
this.handleOrientationChange = this.handleOrientationChange.bind(this)
12-
this.onOrientationChange = this.onOrientationChange.bind(this)
13-
this.onPageLoad = this.onPageLoad.bind(this)
11+
this.handleOrientationChange = this.handleOrientationChange.bind(this);
12+
this.onOrientationChange = this.onOrientationChange.bind(this);
13+
this.onPageLoad = this.onPageLoad.bind(this);
1414

1515
this.state = {
1616
isLandscape: false,
1717
isPortrait: false
18-
}
18+
};
1919
}
2020

2121
handleOrientationChange() {
2222
if (!this.isEventListenerAdded) {
23-
this.isEventListenerAdded = true
23+
this.isEventListenerAdded = true;
2424
}
2525

2626
let orientation = window.innerWidth > window.innerHeight ? 90 : 0;
2727

2828
this.setState({
29-
isPortrait: orientation === 0,
30-
isLandscape: orientation === 90
31-
})
32-
};
29+
isPortrait: orientation === 0,
30+
isLandscape: orientation === 90
31+
});
32+
}
3333

3434
onOrientationChange() {
3535
this.handleOrientationChange();
36-
};
36+
}
3737

3838
onPageLoad() {
3939
this.handleOrientationChange();
40-
};
40+
}
4141

4242
componentDidMount() {
4343
if (typeof window !== undefined && isMobile) {
@@ -53,12 +53,13 @@ function withOrientationChange(WrappedComponent) {
5353
}
5454

5555
componentWillUnmount() {
56-
window.removeEventListener("resize", this.onOrientationChange, false)
56+
window.removeEventListener("resize", this.onOrientationChange, false);
5757
}
5858

5959
render() {
6060
return (
6161
<WrappedComponent
62+
{...this.props}
6263
isLandscape={this.state.isLandscape}
6364
isPortrait={this.state.isPortrait}
6465
/>
@@ -67,4 +68,4 @@ function withOrientationChange(WrappedComponent) {
6768
};
6869
}
6970

70-
export { withOrientationChange }
71+
export { withOrientationChange };

0 commit comments

Comments
 (0)