ios: Add rough back/forward/refresh buttons. #111
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				Build Tilde Friends / Build-All (push) Successful in 30m26s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	Build Tilde Friends / Build-All (push) Successful in 30m26s
				
			This commit is contained in:
		
							
								
								
									
										42
									
								
								src/ios.m
									
									
									
									
									
								
							
							
						
						
									
										42
									
								
								src/ios.m
									
									
									
									
									
								
							| @@ -4,12 +4,14 @@ | ||||
| #import <WebKit/WKWebView.h> | ||||
| #import <WebKit/WKWebViewConfiguration.h> | ||||
|  | ||||
| #include "log.h" | ||||
|  | ||||
| #include <libgen.h> | ||||
| #include <string.h> | ||||
|  | ||||
| void tf_run_thread_start(const char* zip_path); | ||||
|  | ||||
| @interface ViewController : UIViewController <WKUIDelegate, WKNavigationDelegate> | ||||
| @interface ViewController : UINavigationController <WKUIDelegate, WKNavigationDelegate> | ||||
| @property (strong, nonatomic) WKWebView* web_view; | ||||
| @property bool initial_load_complete; | ||||
| @end | ||||
| @@ -19,19 +21,55 @@ static void _start_initial_load(WKWebView* web_view) | ||||
| 	[web_view loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:12345/login/auto"]]]; | ||||
| } | ||||
|  | ||||
| @implementation ViewController : UIViewController | ||||
| @implementation ViewController : UINavigationController | ||||
| - (void)viewDidLoad | ||||
| { | ||||
| 	[super viewDidLoad]; | ||||
|  | ||||
| 	[self setToolbarHidden:false animated:false]; | ||||
| 	self.toolbar.items = @[ | ||||
| 		[[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(goBack)], | ||||
| 		[[UIBarButtonItem alloc] initWithTitle:@"Forward" style:UIBarButtonItemStylePlain target:self action:@selector(goForward)], | ||||
| 		[[UIBarButtonItem alloc] initWithTitle:@"Refresh" style:UIBarButtonItemStylePlain target:self action:@selector(reload)] | ||||
| 	]; | ||||
|  | ||||
| 	WKWebViewConfiguration* configuration = [[WKWebViewConfiguration alloc] init]; | ||||
| 	self.web_view = [[WKWebView alloc] initWithFrame:self.view.frame configuration:configuration]; | ||||
| 	self.web_view.UIDelegate = self; | ||||
| 	self.web_view.navigationDelegate = self; | ||||
| 	self.web_view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; | ||||
| 	self.web_view.translatesAutoresizingMaskIntoConstraints = false; | ||||
| 	[self.view addSubview:self.web_view]; | ||||
|  | ||||
| 	[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.web_view attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1.0 constant:0]]; | ||||
| 	[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.web_view attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-75]]; | ||||
| 	[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.web_view attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0]]; | ||||
| 	[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.web_view attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight multiplier:1.0 constant:0]]; | ||||
|  | ||||
| 	_start_initial_load(self.web_view); | ||||
| } | ||||
|  | ||||
| - (void)goBack | ||||
| { | ||||
| 	if (self.web_view.canGoBack) | ||||
| 	{ | ||||
| 		[self.web_view goBack]; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| - (void)goForward | ||||
| { | ||||
| 	if (self.web_view.canGoForward) | ||||
| 	{ | ||||
| 		[self.web_view goForward]; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| - (void)reload | ||||
| { | ||||
| 	[self.web_view reload]; | ||||
| } | ||||
|  | ||||
| - (void)webView:(WKWebView*)webView didFinishNavigation:(WKNavigation*)navigation | ||||
| { | ||||
| 	self.initial_load_complete = true; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user