Skip to content

Commit 05744ed

Browse files
committed
use RCTWindow in RNTester/AppDelegate.m
1 parent 6ca1131 commit 05744ed

File tree

1 file changed

+24
-36
lines changed

1 file changed

+24
-36
lines changed

RNTester/RNTester/AppDelegate.m

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,61 +21,41 @@
2121
#import <React/RCTLinkingManager.h>
2222
#import <React/RCTRootView.h>
2323
#import <React/RCTEventDispatcher.h>
24+
#import <React/RCTWindow.h>
2425

2526
@interface AppDelegate() <RCTBridgeDelegate, NSSearchFieldDelegate>
2627

2728
@end
2829

2930

3031
@implementation AppDelegate
31-
32-
-(id)init
3332
{
34-
if(self = [super init]) {
35-
36-
// -- Init Window
37-
NSRect contentSize = NSMakeRect(200, 500, 1000, 500);
38-
39-
self.window = [[NSWindow alloc] initWithContentRect:contentSize
40-
styleMask:NSTitledWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask | NSClosableWindowMask
41-
backing:NSBackingStoreBuffered
42-
defer:NO];
43-
NSWindowController *windowController = [[NSWindowController alloc] initWithWindow:self.window];
44-
45-
[[self window] setTitle:@"RNTester"];
46-
[[self window] setTitleVisibility:NSWindowTitleHidden];
47-
[windowController showWindow:self.window];
48-
49-
[windowController setShouldCascadeWindows:NO];
50-
[windowController setWindowFrameAutosaveName:@"RNTester"];
51-
[self setDefaultURL];
52-
53-
// -- Init Toolbar
54-
NSToolbar *toolbar = [[NSToolbar alloc] initWithIdentifier:@"mainToolbar"];
55-
[toolbar setDelegate:self];
56-
[toolbar setSizeMode:NSToolbarSizeModeRegular];
57-
58-
[self.window setToolbar:toolbar];
59-
60-
// -- Init Menu
61-
[self setUpMainMenu];
62-
}
63-
return self;
33+
NSToolbar *_toolbar;
6434
}
6535

6636
- (void)applicationDidFinishLaunching:(NSNotification * __unused)aNotification
6737
{
38+
[self setDefaultURL];
6839

6940
_bridge = [[RCTBridge alloc] initWithDelegate:self
7041
launchOptions:@{@"argv": [self argv]}];
7142

72-
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:_bridge
73-
moduleName:@"RNTesterApp"
74-
initialProperties:nil];
43+
_window = [[RCTWindow alloc] initWithBridge:_bridge
44+
contentRect:NSMakeRect(200, 500, 1000, 500)
45+
styleMask:(NSTitledWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask | NSClosableWindowMask)
46+
defer:NO];
47+
48+
_window.title = @"RNTester";
49+
_window.titleVisibility = NSWindowTitleHidden;
7550

51+
[self setUpToolbar];
52+
[self setUpMainMenu];
7653

54+
_window.contentView = [[RCTRootView alloc] initWithBridge:_bridge
55+
moduleName:@"RNTesterApp"
56+
initialProperties:nil];
7757

78-
[self.window setContentView:rootView];
58+
[_window makeKeyAndOrderFront:nil];
7959
}
8060

8161
- (void)setDefaultURL
@@ -105,6 +85,14 @@ - (void)loadSourceForBridge:(RCTBridge *)bridge
10585
onComplete:loadCallback];
10686
}
10787

88+
- (void)setUpToolbar
89+
{
90+
NSToolbar *toolbar = [[NSToolbar alloc] initWithIdentifier:@"mainToolbar"];
91+
toolbar.delegate = self;
92+
toolbar.sizeMode = NSToolbarSizeModeRegular;
93+
_window.toolbar = toolbar;
94+
}
95+
10896
- (NSArray *)toolbarAllowedItemIdentifiers:(__unused NSToolbar *)toolbar
10997
{
11098
return @[NSToolbarFlexibleSpaceItemIdentifier, @"searchBar", NSToolbarFlexibleSpaceItemIdentifier, @"resetButton"];

0 commit comments

Comments
 (0)