Skip to content

Commit

Permalink
Merge pull request #2271 from ulion/ios_fix_keyboard_not_show_if_was_…
Browse files Browse the repository at this point in the history
…canceled_before_show

[IOS] Fix native keyboard not show if was canceled before it did show
  • Loading branch information
ulion committed Feb 23, 2013
2 parents f08d841 + 983f006 commit 4b9a54c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
3 changes: 2 additions & 1 deletion xbmc/osx/ios/IOSKeyboardView.h
Expand Up @@ -27,9 +27,10 @@
BOOL _confirmed;
CIOSKeyboard *_iosKeyboard;
bool *_canceled;
BOOL _deactivated;
UITextField *_textField;
UILabel *_heading;
BOOL _keyboardIsShowing;
int _keyboardIsShowing; // 0: not, 1: will show, 2: showing
CGFloat _kbHeight;
}

Expand Down
40 changes: 33 additions & 7 deletions xbmc/osx/ios/IOSKeyboardView.mm
Expand Up @@ -46,10 +46,11 @@ - (id)initWithFrame:(CGRect)frame
if (self)
{
_iosKeyboard = nil;
_keyboardIsShowing = NO;
_keyboardIsShowing = 0;
_kbHeight = 0;
_confirmed = NO;
_canceled = NULL;
_deactivated = NO;

self.text = [NSMutableString stringWithString:@""];

Expand Down Expand Up @@ -88,6 +89,10 @@ - (id)initWithFrame:(CGRect)frame
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDidShow:)
name:UIKeyboardDidShowNotification
object:nil];
}
return self;
}
Expand All @@ -113,7 +118,14 @@ -(void)keyboardWillShow:(NSNotification *) notification{
LOG(@"keyboardWillShow: keyboard frame: %@", NSStringFromCGRect(kbRect));
_kbHeight = kbRect.size.width;
[self setNeedsLayout];
_keyboardIsShowing = YES;
_keyboardIsShowing = 1;
}

-(void)keyboardDidShow:(NSNotification *) notification{
LOG(@"keyboardDidShow: deactivated: %d", _deactivated);
_keyboardIsShowing = 2;
if (_deactivated)
[self doDeactivate:nil];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
Expand All @@ -122,6 +134,14 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
[_textField resignFirstResponder];
}

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
LOG(@"%s: keyboard IsShowing %d", __PRETTY_FUNCTION__, _keyboardIsShowing);
// Do not break the keyboard show up process, else we will lost
// keyboard did hide notifaction.
return _keyboardIsShowing != 1;
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
PRINT_SIGNATURE();
Expand All @@ -139,7 +159,7 @@ - (void)keyboardDidHide:(id)sender
{
PRINT_SIGNATURE();

_keyboardIsShowing = NO;
_keyboardIsShowing = 0;

if (_textField.editing)
{
Expand All @@ -156,6 +176,7 @@ - (void) doActivate:(NSDictionary *)dict
[g_xbmcController activateKeyboard:self];
[_textField becomeFirstResponder];
[self setNeedsLayout];
keyboardFinishedEvent.Reset();
}

- (void)activate
Expand All @@ -171,8 +192,6 @@ - (void)activate
return;
}

keyboardFinishedEvent.Reset();

// emulate a modale dialog here
// we are waiting on the user finishing the keyboard
// and have to process our app while doing that
Expand All @@ -191,7 +210,14 @@ - (void)activate

- (void) doDeactivate:(NSDictionary *)dict
{
PRINT_SIGNATURE();
LOG(@"%s: keyboard IsShowing %d", __PRETTY_FUNCTION__, _keyboardIsShowing);
_deactivated = YES;

// Do not break keyboard show up process, if so there's a bug of ios4 will not
// notify us keyboard hide.
if (_keyboardIsShowing == 1)
return;

// invalidate our callback object
if(_iosKeyboard)
{
Expand All @@ -206,7 +232,7 @@ - (void) doDeactivate:(NSDictionary *)dict
[g_xbmcController deactivateKeyboard:self];

// until keyboard did hide, we let the calling thread break loop
if (!_keyboardIsShowing)
if (0 == _keyboardIsShowing)
{
// no more notification we want to receive.
[[NSNotificationCenter defaultCenter] removeObserver: self];
Expand Down

0 comments on commit 4b9a54c

Please sign in to comment.