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.

Thiago Vinhas (tvinhas) added a commit to tvinhas/react-native-macos that referenced this pull request Oct 28, 2026
Upstream v0.88.1 (30 commits, replayed onto the local v0.88.0 without the
agent files). Conflicts: fork identities and the vlists '*' peer kept;
Hermes 260318099.0.5; RCTStatusBarAppearance, the modal's status bar
capture and RCTRootViewController are iOS-only (macOS has no status bar,
visionOS lacks setNeedsStatusBarAppearanceUpdate); the SwiftUI filter
container sets safeAreaRegions through RCTPlatformHostingController;
SwiftPM autolinking keeps the per-platform UIKit/AppKit linker settings;
RNTester Podfile.lock regenerated with pod install.

Also from microsoft/react-native-macos (open PRs, macOS-only): secure
TextInput focus crash (microsoft#3141), TextInput color for bullets and plain text
(microsoft#3144), TextInput text stays put when resized while focused (microsoft#3150),
ScrollView scrolls over a multiline TextInput (microsoft#3146), inverted lists on
the new architecture (microsoft#3148), press over a TextInput (microsoft#3143), Dimensions
follow window resizes (microsoft#3142, plus removing its observer on invalidate),
RCTView shadow color retained (microsoft#3129), UIImage encoders extern "C"
(microsoft#3140), layout direction constants (microsoft#3131), and codegen skipping
unlinked third-party components (microsoft#3128, upstream react#59067).

.yarnrc.yml preapproves hermes-compiler@260318099.0.5 past the 7-day age
gate.
Jay Meistrich (jmeistrich) added a commit to LegendApp/legend-spark that referenced this pull request Nov 16, 2026
React Native macOS 0.83.0 reported the whole display as `Dimensions.get("window")` and never followed
resizes: `RCTDeviceInfo` read the key window, which doesn't exist yet when the module starts, observed
only that window's frame, reported the frame rather than the content, and published only while the app
was active. Spark now patches it the way open upstream PR microsoft/react-native-macos#3142 does
(observe every window's resize, report the content rect, fall back to the main window and then the
frontmost visible window, publish in the background), until a release ships that fix.

Beyond #3142, the patch skips panels (an open panel is key while it shows), falls back to any window
before the screen (Spark's test driver keeps windows hidden, and the module starts before a window is
shown), reports that window's display as `screen`, and republishes when a window moves to another
display, changes backing scale, becomes main or comes on screen.

Adds a Kitchen Sink Window dimensions screen and driver flow.

**Test plan**

✅ window-dimensions.test.ts: applies to clean 0.83.0 source, idempotent, rejects changed source, keeps cache hardlinks.
✅ Kitchen Sink macOS Debug build; window-dimensions flow: 920×668 for a 920×700 frame (display 1920×1080), and the screen's own resize arrived as a change event. Before the fallback to hidden windows it reported 1920×1080.
⬜ Moving between two displays: one display only; the screen-change notification is wired but not exercised.

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