Skip to content

Commit

Permalink
Fixed OSX Example
Browse files Browse the repository at this point in the history
  • Loading branch information
lokimeyburg committed Dec 8, 2014
1 parent c74cf3d commit bd73d7c
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions Example Apps/ExampleApp-OSX/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ @implementation AppDelegate {
WKWebView *_WKWebView;
WebViewJavascriptBridge* _bridge;
WKWebViewJavascriptBridge* _WKBridge;
NSView* _WKWebViewWrapper;
}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
Expand Down Expand Up @@ -58,6 +59,13 @@ - (void)_configureWebview {
[callbackButton setAction:@selector(_callHandler)];
[_webView addSubview:callbackButton];

NSButton *webViewToggleButton = [[NSButton alloc] initWithFrame:NSMakeRect(235, 0, 180, 40)];
[webViewToggleButton setTitle:@"Switch to WKWebView"];
[webViewToggleButton setBezelStyle:NSRoundedBezelStyle];
[webViewToggleButton setTarget:self];
[webViewToggleButton setAction:@selector(_toggleExample)];
[_webView addSubview:webViewToggleButton];


// Load Page
NSString* htmlPath = [[NSBundle mainBundle] pathForResource:@"ExampleApp" ofType:@"html"];
Expand All @@ -67,12 +75,6 @@ - (void)_configureWebview {


- (void)_configureWKWebview {

// Load Page
NSString* htmlPath = [[NSBundle mainBundle] pathForResource:@"ExampleApp" ofType:@"html"];
NSString* html = [NSString stringWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error:nil];
[_WKWebView loadHTMLString:html baseURL:nil];

// Create Bridge
_WKBridge = [WKWebViewJavascriptBridge bridgeForWebView:_WKWebView handler:^(id data, WVJBResponseCallback responseCallback) {
NSLog(@"ObjC received message from JS: %@", data);
Expand Down Expand Up @@ -104,6 +106,23 @@ - (void)_configureWKWebview {
[callbackButton setTarget:self];
[callbackButton setAction:@selector(_WKCallHandler)];
[_WKWebView addSubview:callbackButton];

NSButton *webViewToggleButton = [[NSButton alloc] initWithFrame:NSMakeRect(235, 0, 180, 40)];
[webViewToggleButton setTitle:@"Switch to WebView"];
[webViewToggleButton setBezelStyle:NSRoundedBezelStyle];
[webViewToggleButton setTarget:self];
[webViewToggleButton setAction:@selector(_toggleExample)];
[_WKWebView addSubview:webViewToggleButton];

// Load Page
NSString* htmlPath = [[NSBundle mainBundle] pathForResource:@"ExampleApp" ofType:@"html"];
NSString* html = [NSString stringWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error:nil];
[_WKWebView loadHTMLString:html baseURL:nil];
}

-(void)_toggleExample {
_WKWebView.hidden = !_WKWebView.isHidden;
_webView.hidden = !_webView.isHidden;
}

- (void)_sendMessage {
Expand Down Expand Up @@ -137,29 +156,14 @@ - (void)_createViews {
// WebView
_webView = [[WebView alloc] initWithFrame:contentView.frame];
[_webView setAutoresizingMask:(NSViewHeightSizable | NSViewWidthSizable)];
_webView.hidden = YES;

// WKWebView
_WKWebView = [[WKWebView alloc] initWithFrame:contentView.frame];
[_WKWebView setAutoresizingMask:(NSViewHeightSizable | NSViewWidthSizable)];

// Tabs
NSTabView *tabView = [[NSTabView alloc]
initWithFrame:contentView.frame];
[contentView addSubview:tabView];

NSTabViewItem *tab1 = [[NSTabViewItem alloc]
initWithIdentifier:@"tab1"];
[tab1 setLabel:@"WebView"];
[tabView addTabViewItem:tab1];

NSTabViewItem *tab2 = [[NSTabViewItem alloc]
initWithIdentifier:@"tab2"];
[tab2 setLabel:@"WKWebView"];
[tabView addTabViewItem:tab2];

// Initialize each tab
[tab1 setView:_webView];
[tab2 setView:_WKWebView];
[contentView addSubview:_WKWebView];
[contentView addSubview:_webView];
}


Expand Down

0 comments on commit bd73d7c

Please sign in to comment.