Show cancel button when showing authenticationViewController

Signed-off-by: Marcel Müller <marcel-mueller@gmx.de>
This commit is contained in:
Marcel Müller 2022-11-10 18:09:29 +01:00
Родитель fe55e8d69e
Коммит 06d5475eb3
2 изменённых файлов: 42 добавлений и 12 удалений

Просмотреть файл

@ -49,7 +49,6 @@ NSString * const kNCAuthTokenFlowEndpoint = @"/index.php/login/flo
self = [super init];
if (self) {
self.serverUrl = serverUrl;
self.modalPresentationStyle = ([[NCDatabaseManager sharedInstance] numberOfAccounts] == 0) ? UIModalPresentationFullScreen : UIModalPresentationAutomatic;
}
return self;
@ -60,28 +59,28 @@ NSString * const kNCAuthTokenFlowEndpoint = @"/index.php/login/flo
[super viewDidLoad];
WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
configuration.websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore];
NSString *urlString = [NSString stringWithFormat:@"%@%@", _serverUrl, kNCAuthTokenFlowEndpoint];
if (_user) {
urlString = [NSString stringWithFormat:@"%@?user=%@", urlString, _user];
}
NSURL *url = [NSURL URLWithString:urlString];
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (NSHTTPCookie *cookie in [storage cookies])
{
[storage deleteCookie:cookie];
}
NSSet *websiteDataTypes = [WKWebsiteDataStore allWebsiteDataTypes];
NSDate *dateFrom = [NSDate dateWithTimeIntervalSince1970:0];
[[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes modifiedSince:dateFrom completionHandler:^{
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
[request setValue:@"true" forHTTPHeaderField:@"OCS-APIRequest"];
self->_webView = [[DebounceWebView alloc] initWithFrame:self.view.frame configuration:configuration];
NSString *appDisplayName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];
NSString *deviceName = [[UIDevice currentDevice] name];
@ -89,10 +88,10 @@ NSString * const kNCAuthTokenFlowEndpoint = @"/index.php/login/flo
self->_webView.customUserAgent = [[NSString alloc] initWithCString:[userAgent UTF8String] encoding:NSASCIIStringEncoding];
self->_webView.navigationDelegate = self;
self->_webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self->_webView loadRequest:request];
[self.view addSubview:self->_webView];
self->_activityIndicatorView = [[UIActivityIndicatorView alloc] init];
self->_activityIndicatorView.center = self.view.center;
self->_activityIndicatorView.color = [NCAppBranding brandColor];
@ -101,6 +100,36 @@ NSString * const kNCAuthTokenFlowEndpoint = @"/index.php/login/flo
}];
}
- (void)viewWillAppear:(BOOL)animated
{
UIColor *themeColor = [NCAppBranding themeColor];
[self.view setBackgroundColor:themeColor];
[self.navigationController.navigationBar setTitleTextAttributes:
@{NSForegroundColorAttributeName:[NCAppBranding themeTextColor]}];
self.navigationController.navigationBar.tintColor = [NCAppBranding themeTextColor];
self.navigationController.navigationBar.translucent = YES;
self.navigationController.navigationBar.barTintColor = [NCAppBranding themeColor];
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self action:@selector(cancelButtonPressed)];
cancelButton.accessibilityHint = NSLocalizedString(@"Double tap to dismiss authentication dialog", nil);
self.navigationController.navigationBar.topItem.leftBarButtonItem = cancelButton;
UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
[appearance configureWithOpaqueBackground];
appearance.backgroundColor = themeColor;
appearance.titleTextAttributes = @{NSForegroundColorAttributeName:[NCAppBranding themeTextColor]};
self.navigationItem.standardAppearance = appearance;
self.navigationItem.compactAppearance = appearance;
self.navigationItem.scrollEdgeAppearance = appearance;
}
- (void)cancelButtonPressed
{
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];

Просмотреть файл

@ -200,8 +200,9 @@
if (user) {
_authenticationViewController.user = user;
}
[self presentViewController:_authenticationViewController animated:YES completion:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:_authenticationViewController];
[self presentViewController:navController animated:YES completion:nil];
}
#pragma mark - Alerts