Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(480)

Unified Diff: remoting/ios/app/host_view_controller.mm

Issue 2869303003: Adding hooks to add the keyboard on screen and be able to dismiss it. (Closed)
Patch Set: Adding kKeyboardAnimationTime. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/ios/BUILD.gn ('k') | remoting/ios/client_gestures.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/ios/app/host_view_controller.mm
diff --git a/remoting/ios/app/host_view_controller.mm b/remoting/ios/app/host_view_controller.mm
index 30b19c417349ef07c04fe3de32afb30e462b3490..4cdfb8866aa1d892f5f0d2b8ecc82701844d8191 100644
--- a/remoting/ios/app/host_view_controller.mm
+++ b/remoting/ios/app/host_view_controller.mm
@@ -14,17 +14,20 @@
#import "ios/third_party/material_components_ios/src/components/Buttons/src/MaterialButtons.h"
#import "remoting/ios/client_gestures.h"
+#import "remoting/ios/client_keyboard.h"
#import "remoting/ios/session/remoting_client.h"
#include "remoting/client/gesture_interpreter.h"
static const CGFloat kFabInset = 15.f;
+static const CGFloat kKeyboardAnimationTime = 0.3;
@interface HostViewController () {
RemotingClient* _client;
MDCFloatingButton* _floatingButton;
-
ClientGestures* _clientGestures;
+ ClientKeyboard* _clientKeyboard;
+ CGSize _keyboardSize;
}
@end
@@ -34,6 +37,7 @@ static const CGFloat kFabInset = 15.f;
self = [super init];
if (self) {
_client = client;
+ _keyboardSize = CGSizeZero;
}
return self;
}
@@ -85,12 +89,24 @@ static const CGFloat kFabInset = 15.f;
_clientGestures =
[[ClientGestures alloc] initWithView:self.view client:_client];
+ [[NSNotificationCenter defaultCenter]
+ addObserver:self
+ selector:@selector(keyboardWillShow:)
+ name:UIKeyboardWillShowNotification
+ object:nil];
+
+ [[NSNotificationCenter defaultCenter]
+ addObserver:self
+ selector:@selector(keyboardWillHide:)
+ name:UIKeyboardWillHideNotification
+ object:nil];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
_clientGestures = nil;
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)viewDidLayoutSubviews {
@@ -105,14 +121,95 @@ static const CGFloat kFabInset = 15.f;
btnSize.width, btnSize.height);
}
+#pragma mark - Keyboard
+
+- (BOOL)isKeyboardActive {
+ if (_clientKeyboard) {
+ return [_clientKeyboard isFirstResponder];
+ }
+ return NO;
+}
+
+- (void)showKeyboard {
+ if (!_clientKeyboard) {
+ _clientKeyboard = [[ClientKeyboard alloc] init];
+ [self.view addSubview:_clientKeyboard];
+ // TODO(nicholss): need to pass some keyboard injection interface here.
+ }
+ [_clientKeyboard becomeFirstResponder];
+}
+
+- (void)hideKeyboard {
+ [_clientKeyboard resignFirstResponder];
+}
+
+#pragma mark - Keyboard Notifications
+
+- (void)keyboardWillShow:(NSNotification*)notification {
+ CGSize keyboardSize =
+ [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey]
Yuwei 2017/05/13 01:58:57 You should use UIKeyboardFrameEndUserInfoKey inste
+ CGRectValue]
+ .size;
+ if (_keyboardSize.height != keyboardSize.height) {
+ CGFloat deltaHeight = keyboardSize.height - _keyboardSize.height;
+ [UIView animateWithDuration:0.3
Yuwei 2017/05/13 01:58:57 This should use kKeyboardAnimationTime
nicholss 2017/05/15 15:34:13 Done.
+ animations:^{
+ CGRect f = self.view.frame;
+ f.size.height += deltaHeight;
Yuwei 2017/05/13 01:58:57 Should be -=
nicholss 2017/05/15 15:34:13 Delta can be negative. So I think the math works o
Yuwei 2017/05/15 18:20:53 I think the problem here is this is the delta of t
+ self.view.frame = f;
+ }];
+ _keyboardSize = keyboardSize;
+ }
+}
+
+- (void)keyboardWillHide:(NSNotification*)notification {
+ [UIView animateWithDuration:kKeyboardAnimationTime
+ animations:^{
+ CGRect f = self.view.frame;
+ f.size.height += _keyboardSize.height;
+ self.view.frame = f;
+ }];
+ _keyboardSize = CGSizeZero;
+}
+
#pragma mark - Private
- (void)didTap:(id)sender {
- // TODO(nicholss): The FAB is being used to close the window at the moment
- // just as a demo as the integration continues. This will not be the case
- // in the final app.
- [_client disconnectFromHost];
- [self dismissViewControllerAnimated:YES completion:nil];
+ // TODO(nicholss): The FAB is being used to launch an alert window with
+ // more options. This is not ideal but it gets us an easy way to make a
+ // modal window option selector. Replace this with a real menu later.
+
+ UIAlertController* alert =
+ [UIAlertController alertControllerWithTitle:@"Remote Settings"
+ message:nil
+ preferredStyle:UIAlertControllerStyleAlert];
+
+ if ([self isKeyboardActive]) {
+ void (^hideKeyboardHandler)(UIAlertAction*) = ^(UIAlertAction*) {
+ NSLog(@"Will hide keyboard.");
+ [self hideKeyboard];
+ };
+ [alert addAction:[UIAlertAction actionWithTitle:@"Hide Keyboard"
+ style:UIAlertActionStyleDefault
+ handler:hideKeyboardHandler]];
+ } else {
+ void (^showKeyboardHandler)(UIAlertAction*) = ^(UIAlertAction*) {
+ NSLog(@"Will show keyboard.");
+ [self showKeyboard];
+ };
+ [alert addAction:[UIAlertAction actionWithTitle:@"Show Keyboard"
+ style:UIAlertActionStyleDefault
+ handler:showKeyboardHandler]];
+ }
+ void (^disconnectHandler)(UIAlertAction*) = ^(UIAlertAction*) {
+ [_client disconnectFromHost];
+ [self dismissViewControllerAnimated:YES completion:nil];
+ };
+ [alert addAction:[UIAlertAction actionWithTitle:@"Disconnect"
+ style:UIAlertActionStyleCancel
+ handler:disconnectHandler]];
+
+ [self presentViewController:alert animated:YES completion:nil];
}
@end
« no previous file with comments | « remoting/ios/BUILD.gn ('k') | remoting/ios/client_gestures.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698