Skip to content

fix(macos): keep Dimensions in step with the window - #3142

Open
Bron Davies (brondavies) wants to merge 1 commit into
microsoft:mainfrom
brondavies:fix/device-info-window-dimensions
Open

Bron Davies (brondavies) wants to merge 1 commit into
microsoft:mainfrom
brondavies:fix/device-info-window-dimensions

Conversation

@brondavies

@brondavies Bron Davies (brondavies) commented Oct 23, 2026 •

Copy link
Copy Markdown

Summary:

Fixes #3139. Related: #915, #2296.

On macOS, Dimensions.get('window') and useWindowDimensions() stayed at their first value however the window was resized, and reported the frame rather than the content area. In RCTDeviceInfo:

  • Resizes: it observed the frame of the window that was key when the module was created, which is usually none: RCTReactNativeFactory makes the window key after starting React Native. It now also observes NSWindowDidResizeNotification.
  • Size: it reported frame.size, title bar included. It now reports the content rect, which is what the root view gets.
  • No key window: in the background it fell back to the screen's size, or published nothing. It now falls back to NSApp.mainWindow, then the frontmost visible window that isn't a panel, and publishes a change made while the app is in the background, since a Mac app's window stays on screen then.

This covers #2296's case inside RCTDeviceInfo, without changing what RCTKeyWindow() returns elsewhere.

Test Plan:

RNTester-macOS (Debug, arm64, Xcode 27.1, macOS 26.6.2, 1512 x 982 display), Playground showing useWindowDimensions():

Window frame main This change
Opened in the background (open -g) 1280 x 784 1512 x 982, the screen 1280 x 752
Resized in the background 700 x 600 unchanged 700 x 568

On main, bringing the window to the front then reported 700 x 600 (the frame), and a resize to 900 x 650 while in front left it at 700 x 600. The resizes were made through the Accessibility API.

Dimensions.get("window") and useWindowDimensions() could stay at their first value however the window was resized, and reported the frame rather than the content area:

- the module observes the frame of the window that was key when it was created, which is usually none, so no resize was ever reported. It now observes NSWindowDidResizeNotification.
- the size reported was the frame, title bar included. It is now the content rect, which is what the root view gets.
- with no key window (the app in the background) it fell back to the screen size, or published nothing. It now falls back to the main window, then the frontmost visible non-panel window, and publishes a resize made in the background.
@brondavies
Bron Davies (brondavies) requested a review from a team as a code owner October 23, 2026 15:07
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

macOS: Dimensions and useWindowDimensions don't follow window resizes

1 participant