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

userAgent.match(/iphone|ipod|ipad/i) for iPad Pro fails #10

Open
baptistebriel opened this issue Mar 20, 2021 · 0 comments · May be fixed by #11
Open

userAgent.match(/iphone|ipod|ipad/i) for iPad Pro fails #10

baptistebriel opened this issue Mar 20, 2021 · 0 comments · May be fixed by #11

Comments

@baptistebriel
Copy link

Hey there, super useful module!

I've noticed that iPad Pro devices are considered Macintosh since they are running on iPadOS. I've been using this module and it worked fine, but still had the issue on iPad. I've fixed it by detecting iPads this way:

function isIpad () {
  const ua = window.navigator.userAgent
  if (ua.includes('iPad')) {
    return true
  }
  if (ua.includes('Macintosh')) {
    try {
      document.createEvent('TouchEvent')
      return true
    } catch (e) {}
  }
  return false
}

...and just updated the code within ios-inner-height where it would skip and return window.innerHeight if the userAgent does not matches /iphone|ipod|ipad/i:

// Non-iOS browsers return window.innerHeight per usual.
// No caching here since browsers can be resized, and setting
// up resize-triggered cache invalidation is not in scope.
/* istanbul ignore if  */
if (!navigator.userAgent.match(/iphone|ipod|ipad/i) && !isIpad()) {
  /**
   * Avoids conditional logic in the implementation
   * @return {number} - window's innerHeight measurement in pixels
   */
  return function () {
    return window.innerHeight
  }
}

I am not sure if I should have created a PR as I'm not sure you want to include that isIpad() function in this module, but it might help if someone is having the same issue as I did... You might have a better solution/fix for including iPadOS for this module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant