Skip to content

Commit

Permalink
use RCTWindow in RNTester/AppDelegate.m
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Feb 19, 2019
1 parent cf0317a commit 778cd07
Showing 1 changed file with 23 additions and 36 deletions.
59 changes: 23 additions & 36 deletions RNTester/RNTester/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,61 +21,41 @@
#import <React/RCTLinkingManager.h>
#import <React/RCTRootView.h>
#import <React/RCTEventDispatcher.h>
#import <React/RCTWindow.h>

@interface AppDelegate() <RCTBridgeDelegate, NSSearchFieldDelegate>

@end


@implementation AppDelegate

-(id)init
{
if(self = [super init]) {

// -- Init Window
NSRect contentSize = NSMakeRect(200, 500, 1000, 500);

self.window = [[NSWindow alloc] initWithContentRect:contentSize
styleMask:NSTitledWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask | NSClosableWindowMask
backing:NSBackingStoreBuffered
defer:NO];
NSWindowController *windowController = [[NSWindowController alloc] initWithWindow:self.window];

[[self window] setTitle:@"RNTester"];
[[self window] setTitleVisibility:NSWindowTitleHidden];
[windowController showWindow:self.window];

[windowController setShouldCascadeWindows:NO];
[windowController setWindowFrameAutosaveName:@"RNTester"];
[self setDefaultURL];

// -- Init Toolbar
NSToolbar *toolbar = [[NSToolbar alloc] initWithIdentifier:@"mainToolbar"];
[toolbar setDelegate:self];
[toolbar setSizeMode:NSToolbarSizeModeRegular];

[self.window setToolbar:toolbar];

// -- Init Menu
[self setUpMainMenu];
}
return self;
NSToolbar *_toolbar;
}

- (void)applicationDidFinishLaunching:(NSNotification * __unused)aNotification
{
[self setDefaultURL];

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

RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:_bridge
moduleName:@"RNTesterApp"
initialProperties:nil];
_window = [[RCTWindow alloc] initWithBridge:_bridge
contentRect:NSMakeRect(200, 500, 1000, 500)
styleMask:(NSTitledWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask | NSClosableWindowMask)
defer:NO];

_window.title = @"RNTester";
_window.titleVisibility = NSWindowTitleHidden;

[self setUpToolbar];
[self setUpMainMenu];

_window.contentView = [[RCTRootView alloc] initWithBridge:_bridge
moduleName:@"RNTesterApp"
initialProperties:nil];

[self.window setContentView:rootView];
[_window makeKeyAndOrderFront:nil];
}

- (void)setDefaultURL
Expand Down Expand Up @@ -105,6 +85,13 @@ - (void)loadSourceForBridge:(RCTBridge *)bridge
onComplete:loadCallback];
}

- (void)setUpToolbar
{
_toolbar = [[NSToolbar alloc] initWithIdentifier:@"mainToolbar"];
_toolbar.delegate = self;
_toolbar.sizeMode = NSToolbarSizeModeRegular;
}

- (NSArray *)toolbarAllowedItemIdentifiers:(__unused NSToolbar *)toolbar
{
return @[NSToolbarFlexibleSpaceItemIdentifier, @"searchBar", NSToolbarFlexibleSpaceItemIdentifier, @"resetButton"];
Expand Down

0 comments on commit 778cd07

Please sign in to comment.