Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update macOS init template to enable New Architecture #1854

Merged

Conversation

shwanton
Copy link

Please select one of the following

  • I am removing an existing difference between facebook/react-native and microsoft/react-native-macos 馃憤
  • I am cherry-picking a change from Facebook's react-native into microsoft/react-native-macos 馃憤
  • I am making a fix / change for the macOS implementation of react-native
  • I am making a change required for Microsoft usage of react-native

Summary

**The default template was never upgraded to 0.71 and was not loading the new arch when RCT_NEW_ARCH_ENABLED=1 flag was passed to pod install

This PR picks #1853 to main

Changelog

[MACOS] [FIXED] - Update macOS init template to enable New Architecture

Test Plan

See test plan in #1853

@shwanton shwanton marked this pull request as ready for review June 16, 2023 20:33
@shwanton shwanton requested a review from a team as a code owner June 16, 2023 20:33
@Saadnajmi Saadnajmi merged commit a5f44ca into microsoft:main Jun 16, 2023
15 of 16 checks passed
@xysun
Copy link

xysun commented Jul 15, 2023

This PR sets the macos app size under RCT to be a fixed 1024x768 (code), is there anyway I can override this number?

I tried update self.window in applicationDidFinishLaunching but all it did was open a new window with no view, the original view stays the same size.

NSScreen *screen = [NSScreen mainScreen];
  NSRect screenFrame = [screen visibleFrame];
  NSWindow *window = [[NSWindow alloc] initWithContentRect:screenFrame
                                                  styleMask:NSWindowStyleMaskTitled
                                                    backing:NSBackingStoreBuffered
                                                      defer:NO];

  [window makeKeyAndOrderFront:nil];
  self.window = window;

@Saadnajmi @shwanton thank you.

@Saadnajmi
Copy link
Collaborator

This PR sets the macos app size under RCT to be a fixed 1024x768 (code), is there anyway I can override this number?

I tried update self.window in applicationDidFinishLaunching but all it did was open a new window with no view, the original view stays the same size.

NSScreen *screen = [NSScreen mainScreen];
  NSRect screenFrame = [screen visibleFrame];
  NSWindow *window = [[NSWindow alloc] initWithContentRect:screenFrame
                                                  styleMask:NSWindowStyleMaskTitled
                                                    backing:NSBackingStoreBuffered
                                                      defer:NO];

  [window makeKeyAndOrderFront:nil];
  self.window = window;

@Saadnajmi @shwanton thank you.

To be clear, the window is not resizable? And you can't programmatically access the window/ set the frame afterwards?

@xysun
Copy link

xysun commented Jul 15, 2023

The window is resizable. However I want to set the window size to screen size upon launch, I tried to set the frame in appdelegate:

NSScreen *screen = [NSScreen mainScreen];
  NSRect screenFrame = [screen visibleFrame];
  self.window.contentViewController.view.frame = screenFrame;
  [self.window setFrame:screenFrame display:YES];

This builds but doesn't change the launch window size though; I also tested using a 800x600 rect to make sure it's not a problem with mainScreen and that didn't work either.

@Saadnajmi
Copy link
Collaborator

Saadnajmi commented Jul 15, 2023

@xysun Isee, ideally the user can specify their frame in their app, rather than our hardcoded default. To that end, I think the intention is RCTAppDelegate's createRootViewController method is the entry point for that. If the code was refactored so that instead of us hardcoding the constant, it came from the view controller (that you can override) would that work? Feel free to also submit a PR if that does!

Also, in case you want more control over your window and app delegate in general, this might be useful: https://github.com/microsoft/rnx-kit/blob/main/packages/react-native-host/README.md

@dev-johnny-gh
Copy link

@xysun
it took me 4 hours to resolve this issue, what a damn.

you can't pass any configs to RTCAppDelegate, you can search the RP code for "NSMakeRect(0,0,1024,768)", and you will see it's hardcoded.

you can't use applicationDidFinishLaunching to set up the window size, too. because the window is created on the superclass. at that moment, windows on sharedApplication are empty.

in the end, you have to do it on applicationDidBecomeActive hook.

- (void)applicationDidBecomeActive:(NSNotification *)notification {
  NSArray  *windows = [[UIApplication sharedApplication] windows];
  
  for (NSWindow  *window in windows) {
    if (window.isKeyWindow) {
      
      NSRect frame;
      
      frame.size.height = 680;
      frame.size.width = 400;
      
      [window setFrame:frame display:YES];
      [window center];

      break;
    }
  }
}

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.

None yet

4 participants