ios: Replace the browser navigation buttons with gestures, disable pinch to zoom, and round a button to make it feel more like a native app.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 18m30s
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 18m30s
This commit is contained in:
39
src/ios.m
39
src/ios.m
@@ -35,20 +35,17 @@ static void _start_initial_load(WKWebView* web_view)
|
||||
{
|
||||
[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.web_view.allowsBackForwardNavigationGestures = true;
|
||||
[self.view addSubview:self.web_view];
|
||||
UIRefreshControl* refresh = [[UIRefreshControl alloc] init];
|
||||
[refresh addTarget:self action:@selector(handleRefresh:) forControlEvents:UIControlEventValueChanged];
|
||||
self.web_view.scrollView.refreshControl = refresh;
|
||||
|
||||
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.web_view attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view
|
||||
attribute:NSLayoutAttributeTop
|
||||
@@ -70,31 +67,21 @@ static void _start_initial_load(WKWebView* web_view)
|
||||
_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
|
||||
- (void)handleRefresh:(id)sender
|
||||
{
|
||||
tf_printf("refresh\n");
|
||||
[self.web_view reload];
|
||||
}
|
||||
|
||||
- (void)webView:(WKWebView*)webView didFinishNavigation:(WKNavigation*)navigation
|
||||
{
|
||||
self.initial_load_complete = true;
|
||||
tf_printf("initial load complete\n");
|
||||
if (!self.initial_load_complete)
|
||||
{
|
||||
tf_printf("initial load complete\n");
|
||||
self.initial_load_complete = true;
|
||||
}
|
||||
self.navigationController.interactivePopGestureRecognizer.enabled = self.web_view.canGoBack;
|
||||
[self.web_view.scrollView.refreshControl endRefreshing];
|
||||
}
|
||||
|
||||
- (void)webView:(WKWebView*)webView didFailProvisionalNavigation:(WKNavigation*)navigation withError:(NSError*)error
|
||||
|
||||
Reference in New Issue
Block a user