Skip to content

Commit

Permalink
Resolves #1096, device width for iOS devices
Browse files Browse the repository at this point in the history
When content is rendered inside frames, the wrong size classes were being applied for iOS devices.  Switching to use screen.width as part of the calculation resolves this.

Android devices already behave as expected.
  • Loading branch information
brian-learningpool committed Jun 13, 2016
1 parent 27c814a commit 8ca0861
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/core/js/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ define(function(require) {
$('html').addClass("size-"+Adapt.device.screenSize);
});

Adapt.device.screenWidth = $window.width();
Adapt.device.screenWidth = isAppleDevice()
? screen.width
: window.innerWidth || $window.width();

function checkScreenSize() {

Expand All @@ -34,7 +36,11 @@ define(function(require) {
}

var onWindowResize = _.debounce(function onScreenSizeChanged() {
Adapt.device.screenWidth = window.innerWidth || $window.width();

Adapt.device.screenWidth = isAppleDevice()
? screen.width
: window.innerWidth || $window.width();

var newScreenSize = checkScreenSize();

if (newScreenSize !== Adapt.device.screenSize) {
Expand All @@ -45,7 +51,7 @@ define(function(require) {
Adapt.trigger('device:changed', Adapt.device.screenSize);
}

Adapt.trigger('device:resize', Adapt.device.screenWidth);
Adapt.trigger('device:resize', Adapt.device.screenWidth);

}, 100);

Expand All @@ -58,6 +64,10 @@ define(function(require) {
// Bowser only checks against navigator.userAgent so if the OS is undefined, do a check on the navigator.platform
if (OS == undefined) OS = getPlatform();

function isAppleDevice() {
return /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
}

function getPlatform() {

var platform = navigator.platform;
Expand All @@ -71,7 +81,6 @@ define(function(require) {
}

return "PlatformUnknown";

}

function pixelDensity() {
Expand Down

0 comments on commit 8ca0861

Please sign in to comment.