What's the difference between 'window' and 'screen' in the Dimensions API

前端 未结 2 1376
故里飘歌
故里飘歌 2020-12-15 15:22

On my iOS emulator they both return the same values.

I understand the difference on a normal browser, but what is the difference on React Native? Are there scenarios

2条回答
  •  情歌与酒
    2020-12-15 16:00

    The documentation on Dimensions is quite poor (outstanding issue), so you'll have to dive into the code to understand what is going on. If you look at the source of Dimensions, you'll see this comment on line 47:

    // Screen and window dimensions are different on android
    

    If you trace back the history using blame, you'll find this commit on the relevant section of code pointing to this old issue which itself points to this issue about Dimensions reporting different screen heights.

    I don't know enough about Android itself, but from what I can gather, it appears that Android can report back two different numbers:

    1. width/height with soft menu bar
    2. width/height without soft menu bar (so the actual entire screen)

    A quick test on my Android device printing out these values and I was able to confirm that window's height < screen's height. So in all likelihood, this means:

    • window: reports width/height without the soft menu bar
    • screen: reports entire screen's width/height

    I didn't follow back this product pain about orientation changes on Android, so I don't know how rotating your screen affects this.

提交回复
热议问题