Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(platform): properly detect iPads running iPadOS #19258

Merged
merged 3 commits into from
Sep 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 14 additions & 3 deletions core/src/utils/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,25 @@ const detectPlatforms = (win: Window) =>
const isMobileWeb = (win: Window): boolean =>
isMobile(win) && !isHybrid(win);

const isIpad = (win: Window) =>
testUserAgent(win, /iPad/i);
const isIpad = (win: Window) => {
// iOS 12 and below
if (testUserAgent(win, /iPad/i)) {
return true;
}

// iOS 13+
if (testUserAgent(win, /Macintosh/i) && isMobile(win)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wondering if we can use some JS media query?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

return true;
}

return false;
};

const isIphone = (win: Window) =>
testUserAgent(win, /iPhone/i);

const isIOS = (win: Window) =>
testUserAgent(win, /iPad|iPhone|iPod/i);
testUserAgent(win, /iPhone|iPod/i) || isIpad(win);

const isAndroid = (win: Window) =>
testUserAgent(win, /android|sink/i);
Expand Down
15 changes: 13 additions & 2 deletions core/src/utils/test/platform.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ describe('Platform Tests', () => {
expect(isPlatform(win, 'desktop')).toEqual(true);
});

it('should return true for "android" and "tablet" on an android tablet', () => {
it('should return true for "android" and "tablet" and false for "ios" on an android tablet', () => {
const win = configureBrowser(PlatformConfiguration.AndroidTablet);
expect(isPlatform(win, 'android')).toEqual(true);
expect(isPlatform(win, 'tablet')).toEqual(true);
expect(isPlatform(win, 'ios')).toEqual(false);
});

it('should return true for "cordova" and "hybrid" in a Cordova app', () => {
Expand Down Expand Up @@ -95,10 +96,11 @@ describe('Platform Tests', () => {
expect(isPlatform(win, 'desktop')).toEqual(false);
});

it('should return false for "android" and "tablet" on desktop Safari', () => {
it('should return false for "android", "tablet", and "ipad" on desktop Safari', () => {
const win = configureBrowser(PlatformConfiguration.DesktopSafari);
expect(isPlatform(win, 'android')).toEqual(false);
expect(isPlatform(win, 'tablet')).toEqual(false);
expect(isPlatform(win, 'ipad')).toEqual(false);
});

it('should return false for "android" and "tablet" and false for "desktop" on iPhone', () => {
Expand All @@ -120,5 +122,14 @@ describe('Platform Tests', () => {
expect(isPlatform(win, 'pwa')).toEqual(true);
expect(isPlatform(win, 'cordova')).toEqual(false);
});

it('should return true for "ios", "ipad", and "tablet" and false for "iphone" and "android"', () => {
const win = configureBrowser(PlatformConfiguration.iPadOS);
expect(isPlatform(win, 'ios')).toEqual(true);
expect(isPlatform(win, 'ipad')).toEqual(true);
expect(isPlatform(win, 'tablet')).toEqual(true);
expect(isPlatform(win, 'iphone')).toEqual(false);
expect(isPlatform(win, 'android')).toEqual(false);
});
})
});
8 changes: 8 additions & 0 deletions core/src/utils/test/platform.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,13 @@ export const PlatformConfiguration = {
innerWidth: 360,
innerHeight: 740,
matchMedia: mockMatchMedia(['(any-pointer:coarse)'])
},
iPadOS: {
navigator: {
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Safari/605.1.15'
},
innerWidth: 1024,
innerHeight: 1292,
matchMedia: mockMatchMedia(['(any-pointer:coarse)'])
}
};