Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-14544] iOS: keyboardFrameChanged before keyboard is shown

GitHub Issuen/a
TypeNew Feature
PriorityLow
StatusClosed
ResolutionFixed
Resolution Date2015-02-25T18:01:39.000+0000
Affected Version/sn/a
Fix Version/sRelease 4.0.0
ComponentsiOS
Labelsevent, events, ios, keyboard
ReporterTristan Roscoe
AssigneeVishal Duggal
Created2013-07-12T21:38:11.000+0000
Updated2015-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");
    });
});

Comments

  1. Tristan Roscoe 2013-07-12

    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.
  2. Mike Butler 2015-02-24

    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?
  3. ian young 2015-02-24

    Surely this is kind of fundamental isn't it?
  4. Vishal Duggal 2015-02-24

    Test Case
       var win = Ti.UI.createWindow({
           backgroundColor: '#ddd',
           fullscreen:true,
           orientationModes:[1,2,3,4]
       });
        
       var ta = Ti.UI.createTextArea({
           width:Ti.UI.FILL,
           height:100,
           backgroundColor:'yellow',
           top:20
       })
       
       Ti.App.addEventListener('keyboardframechanged',function(e){
           Ti.API.info(JSON.stringify(e));
       })
       
       win.add(ta);
       
       win.open();
       
  5. Vishal Duggal 2015-02-24

    Pull pending master - https://github.com/appcelerator/titanium_mobile/pull/6659
  6. Lokesh Choudhary 2015-03-18

    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

JSON Source