[TIMOB-14544] iOS: keyboardFrameChanged before keyboard is shown
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | Low |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2015-02-25T18:01:39.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 4.0.0 |
Components | iOS |
Labels | event, events, ios, keyboard |
Reporter | Tristan Roscoe |
Assignee | Vishal Duggal |
Created | 2013-07-12T21:38:11.000+0000 |
Updated | 2015-03-18T20:53:30.000+0000 |
Description
keyboardFrameChanged event doesn't do much good as it is fired after the keyboard has already been displayed. to create responsive layouts with different keyboard sizes we need to know keyboard size BEFORE the keyboard is displayed.
iphone/Classes/AppModule.m line 386-407 could be changed to something like this
-(void)startup
{
WARN_IF_BACKGROUND_THREAD_OBJ; //NSNotificationCenter is not threadsafe!
NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(willShutdown:) name:kTiWillShutdownNotification object:nil];
[nc addObserver:self selector:@selector(willShutdownContext:) name:kTiContextShutdownNotification object:nil];
#if __IPHONE_OS_VERSION_MIN_ALLOWED >= __IPHONE_5_0
if ([TiUtils isIOS5OrGreater])
{
[nc addObserver:self selector:@selector(keyboardFrameChanged:) name:UIKeyboardWillChangeFrameNotification object:nil];
}
#else
[nc addObserver:self selector:@selector(keyboardFrameChanged:) name:UIKeyboardWillShowNotification object:nil];
[nc addObserver:self selector:@selector(keyboardFrameChanged:) name:UIKeyboardWillHideNotification object:nil];
[nc addObserver:self selector:@selector(timeChanged:) name:UIApplicationSignificantTimeChangeNotification object:nil];
#endif
[super startup];
}
Either that or provide access to both Will and Did.
e.x.
Ti.App.addEventListener('keyboardFrameChanged', function(e){
var val = Ti.Platform.displayCaps.platformHeight - e.keyboardFrame.y;
$.container.animate({bottom:val, duration:300}, function() {
Ti.API.log("handleAnimateEnd");
});
});
Also if you guys wanted to throw in UIKeyboardAnimationDurationUserInfoKey as an event property that would be extremely useful as well to match layout animation speed.
Folks this one is killing us whenever we want do anything nice in response to the keyboard appearing. It's even worse when the keyboard is dismissed - whatever UI we've changed in response to the keyboard is left stranded mid-screen until after the keyboard has animated offscreen. No amount of subsequent animation can hide that ugliness. It makes it look like we haven't put in the time to polish the app. We really do need is the will version of the call (with animationDuration if possible) Any chance this could be bumped up in priority?
Surely this is kind of fundamental isn't it?
Test Case
Pull pending master - https://github.com/appcelerator/titanium_mobile/pull/6659
Verified the fix. The keyboardFrameChanged event is fired just before the keyboard is shown or hidden. Closing. Environment: Appc Studio : 4.0.0.201503161602 Ti SDK : 4.0.0.v20150313181810 CLI : 3.5.0-dev Alloy : 1.5.1 MAC Yosemite : 10.10.2 Iphone 6 - IOS 8.2