|
21 | 21 | #import <React/RCTLinkingManager.h>
|
22 | 22 | #import <React/RCTRootView.h>
|
23 | 23 | #import <React/RCTEventDispatcher.h>
|
| 24 | +#import <React/RCTWindow.h> |
24 | 25 |
|
25 | 26 | @interface AppDelegate() <RCTBridgeDelegate, NSSearchFieldDelegate>
|
26 | 27 |
|
27 | 28 | @end
|
28 | 29 |
|
29 | 30 |
|
30 | 31 | @implementation AppDelegate
|
31 |
| - |
32 |
| --(id)init |
33 | 32 | {
|
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; |
64 | 34 | }
|
65 | 35 |
|
66 | 36 | - (void)applicationDidFinishLaunching:(NSNotification * __unused)aNotification
|
67 | 37 | {
|
| 38 | + [self setDefaultURL]; |
68 | 39 |
|
69 | 40 | _bridge = [[RCTBridge alloc] initWithDelegate:self
|
70 | 41 | launchOptions:@{@"argv": [self argv]}];
|
71 | 42 |
|
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; |
75 | 50 |
|
| 51 | + [self setUpToolbar]; |
| 52 | + [self setUpMainMenu]; |
76 | 53 |
|
| 54 | + _window.contentView = [[RCTRootView alloc] initWithBridge:_bridge |
| 55 | + moduleName:@"RNTesterApp" |
| 56 | + initialProperties:nil]; |
77 | 57 |
|
78 |
| - [self.window setContentView:rootView]; |
| 58 | + [_window makeKeyAndOrderFront:nil]; |
79 | 59 | }
|
80 | 60 |
|
81 | 61 | - (void)setDefaultURL
|
@@ -105,6 +85,14 @@ - (void)loadSourceForBridge:(RCTBridge *)bridge
|
105 | 85 | onComplete:loadCallback];
|
106 | 86 | }
|
107 | 87 |
|
| 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 | + |
108 | 96 | - (NSArray *)toolbarAllowedItemIdentifiers:(__unused NSToolbar *)toolbar
|
109 | 97 | {
|
110 | 98 | return @[NSToolbarFlexibleSpaceItemIdentifier, @"searchBar", NSToolbarFlexibleSpaceItemIdentifier, @"resetButton"];
|
|
0 commit comments