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

Viewed 28647

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 where they return differente values?

2 Answers

On Android, window reflects the section of the total screen made available for this app. In most cases, width and height for window will be the same size or smaller than screen.

There are at least 3 cases where screen and window may be different:

  1. If an Android device has the device navigation bar visible, the window height (or width when landscape) will be lower than screen height by the height of the navigator. This is illustrated in this answer by RY Zheng which was linked to in an answer to this question which got deleted.

    Example image of an Android system navigation bar from developer.android.com: enter image description here

  2. If the app is shown in Android's split screen/multi-window mode, with windows for two apps side by side, window width or height will be lower than for screen and will give the width or height allocated for that app's window. This would have been documented by this PR by ThisIsMissEm, but it was closed by Facebook because no-one from Facebook got around to reviewing it.

    Example illustration of Android multi-window mode from developer.android.com:

    enter image description here

  3. If an Android device had "screen zoom" or "display size" setting changed in Accessibility settings while the app was open, the scale, width and height properties for window will update to reflect the zoom but the properties for screen will not. If the app is restarted, the window scale property will match that of the screen.

    If an element with fixed dimensions fails to scale on changing screen zoom without restarting the app, multiplying those dimensions by Dimensions.get('window').scale / Dimensions.get('screen').scale may help.

    Example image of the Display Size accessibility settings UI from androidpolice.com: enter image description here


So, width and height for window are usually the same size, or, sometimes on Android, smaller than screen.

There's only one exception I'm aware of where window may give values larger than screen: if the app was opened with "display size" or "screen zoom" accessibility setting set high, then, this was set lower with the app still open. In this case the height and width will be greater and the scale will be lower by the same ratio. I suspect this may be a bug in React Native rather than an intended behaviour and may change in a future release.

Related