Skip to content

Commit d38ba46

Browse files
authored
chore: remember RCTAppDelegate main window position (#2637)
## Summary: Previously, we always centered the window, which got a bit annoying during debugging when I'd like to have it remember the last position as I relaunch it. This is probably a good thing to do in general, so let's do it in `RCTAppDelegate`. ## Test Plan: Removed any saved frame by running `defaults delete Microsoft.RNTester-macOS`: window is centered Resize window and move it and close and relaunch: old position is remembered.
1 parent 9634b2d commit d38ba46

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232

3333
using namespace facebook::react;
3434

35+
#if TARGET_OS_OSX // [macOS
36+
static NSString *sRCTAppDelegateMainWindowFrameAutoSaveName = @"RCTAppDelegateMainWindow";
37+
#endif // macOS]
38+
3539
@implementation RCTAppDelegate
3640

3741
- (instancetype)init
@@ -92,7 +96,10 @@ - (void)loadReactNativeWindow:(NSDictionary *)launchOptions
9296
rootView.frame = frame;
9397
self.window.contentViewController = rootViewController;
9498
[self.window makeKeyAndOrderFront:self];
95-
[self.window center];
99+
if (![self.window setFrameUsingName:sRCTAppDelegateMainWindowFrameAutoSaveName]) {
100+
[self.window center];
101+
}
102+
[self.window setFrameAutosaveName:sRCTAppDelegateMainWindowFrameAutoSaveName];
96103
#endif // macOS]
97104
}
98105

@@ -132,4 +139,4 @@ - (void)setBridgeAdapter:(RCTSurfacePresenterBridgeAdapter *)bridgeAdapter
132139
self.reactNativeFactory.rootViewFactory.bridgeAdapter = bridgeAdapter;
133140
}
134141

135-
@end
142+
@end

0 commit comments

Comments
 (0)