Commit c506d938 authored by Richard Moe Gustavsen's avatar Richard Moe Gustavsen Committed by Jani Heikkinen
Browse files

iOS: close menu when keyboard hides


If the menu is closed from the keyboard gesture, and
the focus object doesn't change, the menu will still
be in a visible state, even if the keyboard is hidden.

This patch will ensure that this can not be the case
by listening for keyboardWillHideNotification. Since
we have no guarantee for when the destructor runs, we
apply a pessimistic approach and ensure we stop listen
when the menu gets closed.

Task-number: QTBUG-42523
Change-Id: If734ea32d1823b978c9c1c67ebcc5b6c3c5c338c
Reviewed-by: default avatarTor Arne Vestbø <tor.arne.vestbo@digia.com>
Showing with 18 additions and 0 deletions
...@@ -153,13 +153,29 @@ static NSString *const kSelectorPrefix = @"_qtMenuItem_"; ...@@ -153,13 +153,29 @@ static NSString *const kSelectorPrefix = @"_qtMenuItem_";
[self setDelegate:self]; [self setDelegate:self];
[self setDataSource:self]; [self setDataSource:self];
[self selectRow:m_selectedRow inComponent:0 animated:false]; [self selectRow:m_selectedRow inComponent:0 animated:false];
[self listenForKeyboardWillHideNotification:YES];
} }
return self; return self;
} }
-(void)listenForKeyboardWillHideNotification:(BOOL)listen
{
if (listen) {
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(cancelMenu)
name:@"UIKeyboardWillHideNotification" object:nil];
} else {
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:@"UIKeyboardWillHideNotification" object:nil];
}
}
-(void)dealloc -(void)dealloc
{ {
[self listenForKeyboardWillHideNotification:NO];
self.toolbar = 0; self.toolbar = 0;
[super dealloc]; [super dealloc];
} }
...@@ -193,6 +209,7 @@ static NSString *const kSelectorPrefix = @"_qtMenuItem_"; ...@@ -193,6 +209,7 @@ static NSString *const kSelectorPrefix = @"_qtMenuItem_";
- (void)closeMenu - (void)closeMenu
{ {
[self listenForKeyboardWillHideNotification:NO];
if (!m_visibleMenuItems.isEmpty()) if (!m_visibleMenuItems.isEmpty())
QIOSMenu::currentMenu()->handleItemSelected(m_visibleMenuItems.at(m_selectedRow)); QIOSMenu::currentMenu()->handleItemSelected(m_visibleMenuItems.at(m_selectedRow));
else else
...@@ -201,6 +218,7 @@ static NSString *const kSelectorPrefix = @"_qtMenuItem_"; ...@@ -201,6 +218,7 @@ static NSString *const kSelectorPrefix = @"_qtMenuItem_";
- (void)cancelMenu - (void)cancelMenu
{ {
[self listenForKeyboardWillHideNotification:NO];
QIOSMenu::currentMenu()->dismiss(); QIOSMenu::currentMenu()->dismiss();
} }
......
Supports Markdown
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