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

Vertical height is wrong when Safari's bottom bar isn't present #30

Open
iMerica opened this issue Dec 16, 2019 · 15 comments
Open

Vertical height is wrong when Safari's bottom bar isn't present #30

iMerica opened this issue Dec 16, 2019 · 15 comments

Comments

@iMerica
Copy link

iMerica commented Dec 16, 2019

Hi,

Thanks for creating this component! Its working fine when the bottom menu bar is present, but once you scroll it away, the height is not updated to the correct height.

For example:
vh-issue-bug

@yossi-shasho
Copy link

+1

@michael-arvanitidis
Copy link

https://github.com/mvasin/react-div-100vh/blob/master/src/lib/getWindowHeight.js the code checks first for document.documentElement.clientHeight and then for window.innerHeight, both those values are the same when bottom bar is present, but when the bar disappears the values differ. window.innerHeight returns the correct value.

@mvasin would it be an idea to switch the statement in getWindowHeight()? That way iOS atleast will return correct value.

Untitled-1 copy

@colepeters
Copy link

Just encountered this issue as well. FWIW, for me it occurs when rotating the device (either a physical one or one in the simulator) to landscape and then back to portrait. Maybe we need a listener on device rotation to recompute?

@mvasin
Copy link
Owner

mvasin commented Aug 22, 2020

Indeed, using window.innerHeight instead of document.documentElement.clientHeight seems to solve the issue. At also seem to resolve #14.

That's how it used to be from the beginning, and document.documentElement.clientHeight was introduced to address #22. But seems like it's not an ideal solution and we need to resort towards something like https://bugs.webkit.org/show_bug.cgi?id=170595#c5 (or perhaps #13 (comment)), maybe with some optimisations on top. We may also consider https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver.

@blimpmason
Copy link

@mvasin is there an older release I can downgrade to that solves this Safari issue even if it reintroduces issue described in #22? This is crucial for an app I'm working on currently and I love the simplicity of this component.

@mvasin
Copy link
Owner

mvasin commented Oct 18, 2020

Hi @blimpmason! According to the diff of #22, that should be version 0.3.4.

@pitipatdop
Copy link

What's the issue with window.innerHeight ?
In my project, window.innerHeight seems to return correct height when bottom bar isn't present compare to document.documentElement.clientHeight

@baba43
Copy link

baba43 commented Oct 9, 2021

I think I have this issue as well with iOS 15 and it's bottom bar.

The height itself is correct and my elements are positioned correctly, but when the bottom address bar disappears, there is empty space at the bottom (for instance when the user scrolls down).

@hugo-licon
Copy link

I also started to have the same issue with iOS 15 @baba43, could someone find a fix for this bug?

@mvasin
Copy link
Owner

mvasin commented Nov 7, 2021

Hi all,

I replaced document.documentElement.clientHeight || window.innerHeight with window.innerHeight in #74 and published it as [email protected]. Can you try it out?

@mvasin
Copy link
Owner

mvasin commented Nov 9, 2021

The above update is published under version 0.7.0.

@mvasin mvasin closed this as completed Nov 9, 2021
@patotoma
Copy link

Not quite working for me. On iOS 15 Safari when the browser UI gets minimized, even the window.innerHeight is giving a wrong number. I'm not sure what can be done about it though.

@patotoma
Copy link

patotoma commented Nov 10, 2021

IMG_2709

can see the gap at the bottom of the screen

@mvasin
Copy link
Owner

mvasin commented Nov 10, 2021

Wow, that looks like contemporary art.

@mvasin mvasin reopened this Nov 10, 2021
@alex-cory
Copy link

alex-cory commented Dec 1, 2021

Give this a shot. Seems to be working for me.

const getViewports = () => ({
  viewport: {
    width: Math.max(
      document.documentElement.clientWidth || 0,
      window.innerWidth || 0
    ),
    height: Math.max(
      document.documentElement.clientHeight || 0,
      window.innerHeight || 0
    )
  },
  visualViewport: {
    width: window.visualViewport.width,
    height: window.visualViewport.height
  }
})

const useVisualViewport = () => {
  const [state, setState] = useState(getViewports)
  useEffect(() => {
    const handleResize = () => setState(getViewports)
    window.visualViewport.addEventListener('resize', handleResize)
    return () =>
      window.visualViewport.removeEventListener('resize', handleResize)
  }, [])
  return state
}

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

No branches or pull requests