blob: c51cd2a4c08cba83a498e0021c960be2df4f4bef [file] [log] [blame]
// Copyright 2018 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.
#import "ios/chrome/browser/ui/autofill/manual_fill/keyboard_observer_helper.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface KeyboardObserverHelper ()
// Boolean to check if the keyboard was actually dismissed.
@property(nonatomic) BOOL keyboardOnScreen;
@end
@implementation KeyboardObserverHelper
- (instancetype)init {
self = [super init];
if (self) {
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(keyboardDidHide:)
name:UIKeyboardDidHideNotification
object:nil];
}
return self;
}
- (void)keyboardWillShow:(NSNotification*)notification {
self.keyboardOnScreen = YES;
}
- (void)keyboardWillHide:(NSNotification*)notification {
self.keyboardOnScreen = NO;
dispatch_async(dispatch_get_main_queue(), ^{
if (self.keyboardOnScreen) {
[self.delegate keyboardDidStayOnScreen];
}
});
}
- (void)keyboardDidHide:(NSNotification*)notification {
dispatch_async(dispatch_get_main_queue(), ^{
if (!self.keyboardOnScreen) {
[self.delegate keyboardDidHide];
}
});
}
@end