Commit 30aaa618 authored by Yuwei Huang's avatar Yuwei Huang Committed by Commit Bot

[CRD iOS] Make the side menu help button work

This CL:

* Implements a WebViewController that automatically adds a close button
  to the nav bar when it's the first VC in the nav stack, and allow
  overriding the right nav button.
* Adds the Credits button to the help center VC.
* Makes the side menu's help button work.

Bug: 740240
Change-Id: I28436ada3ea1a9e588be0cedfc2e5b874c82d4d9
Reviewed-on: https://chromium-review.googlesource.com/572602Reviewed-by: default avatarScott Nichols <nicholss@chromium.org>
Commit-Queue: Yuwei Huang <yuweih@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487248}
parent 9486c251
...@@ -56,6 +56,8 @@ source_set("common_source_set") { ...@@ -56,6 +56,8 @@ source_set("common_source_set") {
"side_menu_items.mm", "side_menu_items.mm",
"user_status_presenter.h", "user_status_presenter.h",
"user_status_presenter.mm", "user_status_presenter.mm",
"web_view_controller.h",
"web_view_controller.mm",
] ]
deps = [ deps = [
......
...@@ -23,6 +23,9 @@ ...@@ -23,6 +23,9 @@
// controller. // controller.
- (void)navigateToHelpCenter:(UINavigationController*)navigationController; - (void)navigateToHelpCenter:(UINavigationController*)navigationController;
// Presents the help center modally onto the topmost view controller.
- (void)presentHelpCenter;
// This will present the Send Feedback view controller onto the topmost view // This will present the Send Feedback view controller onto the topmost view
// controller. // controller.
// context: a unique identifier for the user's place within the app which can be // context: a unique identifier for the user's place within the app which can be
......
...@@ -8,8 +8,6 @@ ...@@ -8,8 +8,6 @@
#import "remoting/ios/app/app_delegate.h" #import "remoting/ios/app/app_delegate.h"
#import <WebKit/WebKit.h>
#include "base/logging.h" #include "base/logging.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
...@@ -19,6 +17,7 @@ ...@@ -19,6 +17,7 @@
#import "remoting/ios/app/help_and_feedback.h" #import "remoting/ios/app/help_and_feedback.h"
#import "remoting/ios/app/remoting_view_controller.h" #import "remoting/ios/app/remoting_view_controller.h"
#import "remoting/ios/app/user_status_presenter.h" #import "remoting/ios/app/user_status_presenter.h"
#import "remoting/ios/app/web_view_controller.h"
#import "remoting/ios/facade/remoting_oauth_authentication.h" #import "remoting/ios/facade/remoting_oauth_authentication.h"
@interface AppDelegate ()<FirstLaunchViewControllerDelegate> { @interface AppDelegate ()<FirstLaunchViewControllerDelegate> {
...@@ -118,21 +117,32 @@ static NSString* const kFAQsUrl = ...@@ -118,21 +117,32 @@ static NSString* const kFAQsUrl =
#pragma mark - AppDelegate #pragma mark - AppDelegate
- (void)navigateToFAQs:(UINavigationController*)navigationController { - (void)navigateToFAQs:(UINavigationController*)navigationController {
[self navigateToUrl:kFAQsUrl WebViewController* viewController =
title:@"FAQs" [[WebViewController alloc] initWithUrl:kFAQsUrl title:@"FAQs"];
navigationController:navigationController]; [navigationController pushViewController:viewController animated:YES];
} }
- (void)navigateToHelpCenter:(UINavigationController*)navigationController { - (void)navigateToHelpCenter:(UINavigationController*)navigationController {
[self navigateToUrl:kHelpCenterUrl [navigationController pushViewController:[self createHelpViewController]
title:@"Help Center" animated:YES];
navigationController:navigationController]; }
- (void)presentHelpCenter {
UINavigationController* navController = [[UINavigationController alloc]
initWithRootViewController:[self createHelpViewController]];
[AppDelegate.topPresentingVC presentViewController:navController
animated:YES
completion:nil];
} }
- (void)presentFeedbackFlowWithContext:(NSString*)context { - (void)presentFeedbackFlowWithContext:(NSString*)context {
[HelpAndFeedback.instance presentFeedbackFlowWithContext:context]; [HelpAndFeedback.instance presentFeedbackFlowWithContext:context];
} }
- (void)emailSetupInstructions {
NSLog(@"TODO: emailSetupInstructions");
}
#pragma mark - FirstLaunchViewPresenterDelegate #pragma mark - FirstLaunchViewPresenterDelegate
- (void)presentSignInFlow { - (void)presentSignInFlow {
...@@ -142,24 +152,31 @@ static NSString* const kFAQsUrl = ...@@ -142,24 +152,31 @@ static NSString* const kFAQsUrl =
#pragma mark - Private #pragma mark - Private
- (void)navigateToUrl:(NSString*)url - (WebViewController*)createHelpViewController {
title:(NSString*)title WebViewController* viewController =
navigationController:(UINavigationController*)navigationController { [[WebViewController alloc] initWithUrl:kHelpCenterUrl
UIViewController* viewController = [[UIViewController alloc] init]; title:@"Help Center"];
viewController.title = title; viewController.navigationItem.rightBarButtonItem =
[[UIBarButtonItem alloc] initWithTitle:@"Credits"
NSURLRequest* request = style:UIBarButtonItemStylePlain
[NSURLRequest requestWithURL:[NSURL URLWithString:url]]; target:self
WKWebView* webView = action:@selector(onTapCredits:)];
[[WKWebView alloc] initWithFrame:viewController.view.frame return viewController;
configuration:[[WKWebViewConfiguration alloc] init]];
[viewController.view addSubview:webView];
[navigationController pushViewController:viewController animated:YES];
[webView loadRequest:request];
} }
- (void)emailSetupInstructions { - (void)onTapCredits:(id)button {
NSLog(@"TODO: emailSetupInstructions"); NSLog(@"tap credits");
}
+ (UIViewController*)topPresentingVC {
UIViewController* topController =
UIApplication.sharedApplication.keyWindow.rootViewController;
while (topController.presentedViewController) {
topController = topController.presentedViewController;
}
return topController;
} }
@end @end
...@@ -59,7 +59,7 @@ static NSString* const kFeedbackContext = @"SideMenuFeedbackContext"; ...@@ -59,7 +59,7 @@ static NSString* const kFeedbackContext = @"SideMenuFeedbackContext";
[[SideMenuItem alloc] initWithTitle:@"Help" [[SideMenuItem alloc] initWithTitle:@"Help"
icon:RemotingTheme.helpIcon icon:RemotingTheme.helpIcon
action:^{ action:^{
NSLog(@"Tapped help"); [AppDelegate.instance presentHelpCenter];
}], }],
] ]; ] ];
}); });
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef REMOTING_IOS_APP_WEB_VIEW_CONTROLLER_H_
#define REMOTING_IOS_APP_WEB_VIEW_CONTROLLER_H_
#import <UIKit/UIKit.h>
// A simple VC for showing a web view for the given url. It will show a close
// navigation button when it is the first VC in the navigation stack.
@interface WebViewController : UIViewController
- (instancetype)initWithUrl:(NSString*)url title:(NSString*)title;
@end
#endif // REMOTING_IOS_APP_WEB_VIEW_CONTROLLER_H_
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
#import "remoting/ios/app/web_view_controller.h"
#import <WebKit/WebKit.h>
#import "remoting/ios/app/remoting_theme.h"
@interface WebViewController () {
NSString* _urlString;
}
@end
@implementation WebViewController
- (instancetype)initWithUrl:(NSString*)url title:(NSString*)title {
if (self = [super init]) {
_urlString = url;
self.title = title;
}
return self;
}
#pragma mark - UIViewController
- (void)loadView {
WKWebView* webView =
[[WKWebView alloc] initWithFrame:CGRectZero
configuration:[[WKWebViewConfiguration alloc] init]];
NSURLRequest* request =
[NSURLRequest requestWithURL:[NSURL URLWithString:_urlString]];
[webView loadRequest:request];
self.view = webView;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// Show a close button if it is the first view in the navigation stack.
UIViewController* firstViewController =
[self.navigationController.viewControllers firstObject];
if ((firstViewController == self ||
firstViewController == self.parentViewController) &&
!self.navigationItem.leftBarButtonItem &&
!self.navigationItem.leftBarButtonItems.count) {
self.navigationItem.leftBarButtonItem =
[[UIBarButtonItem alloc] initWithImage:RemotingTheme.closeIcon
style:UIBarButtonItemStylePlain
target:self
action:@selector(didTapClose:)];
}
}
#pragma mark - Private
- (void)didTapClose:(id)button {
[self dismissViewControllerAnimated:YES completion:nil];
}
@end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment