Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

How do I get the size of the native keyboard?
Started by stevebreslin Aug 31 2013 02:06 PM

- - - - -
14 replies to this topic
keyboard textfield native
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

stevebreslin

[GLOBAL: userInfoPane.html]
stevebreslin
  • Observer

  • 21 posts
  • Corona SDK

Can anyone tell me how to get or calculate the height of the native keyboard?

 

When using native.newTextField() on iOS, the native keyboard pops up whenever the user touches inside the text field. Obviously the keyboard hides the lower part of the screen and possibly other input elements so it is usually necessary to scroll the main screen contents upwards by some amount, so the keyboard no longer hides stuff.

 

It would be great to be able to automatically and dynamically determine the height of the keyboard to determine exactly how much the screen contents need to be scrolled by.

 

The iPad keyboard takes up less (relative) screen area compared to the iPhone keyboard, and I'm sure Android has all sorts of variations in keyboard sizes for various screens.

 

Any ideas would be greatly appreciated!



[TOPIC: post.html]
#2

jonjonsson

[GLOBAL: userInfoPane.html]
jonjonsson
  • Corona Geek

  • 1,051 posts
  • Corona SDK

It is not possible at the moment as far as I know. A pretty serious drawback in my opinion. Please vote for it in the feature requests: http://feedback.coronalabs.com/forums/188732-corona-sdk-feature-requests-feedback/suggestions/4267410-get-keyboard-height

 

My solution is to move the input boxes up to what I think is a safe position. My optimal solution would be to move them so they rest upon the keyboard, but that is not possible since we have no idea about the height.



[TOPIC: post.html]
#3

stevebreslin

[GLOBAL: userInfoPane.html]
stevebreslin
  • Observer

  • 21 posts
  • Corona SDK

Thanks. I voted for that.

 

What I plan on doing is making a decision on the keyboard height based on device dimensions. It'll work for iOS devices because there a limited number of screen sizes and I can deduce that the keyboard will be about 1/3 of the screen area on an iPad4 but 40% of the screen are on the iPhone4 (iPad and iPhone have different keyboards layouts). On Android though I'll just have to either make sure the screen contents are raised high enough to be not be covered by the keyboard (and risk raising screen content too much), or just make sure there are no critical input elements at the bottom of the screen. I'm very surprised there is not a proper solution for this. Do Corona developers not use keyboards and text input widgets in their apps??



[TOPIC: post.html]
#4

craig stowers

[GLOBAL: userInfoPane.html]
craig stowers
  • Enthusiast

  • 42 posts
  • Corona SDK

I do lots of testing... unfortunately you really need the hardware to do that. Or maybe the xCode Sim can run a corona app? I never tried that.

 

You can get all the apple device keyboard heights. Minus them (after your scaling mods) from the screen height and you should get an almost pixel perfect calculation of it's rest position. Problem is as it moves you have no real idea. I just made my own animation/tween algorithm to closely match the keyboards as it moves. Problem is I think the keyboard runs in it's own world so to speak and depending on system resources at them time  how 'matched' up they are can vary. Implementing time based tweens rather than Frame based could be a solution to this if you want to get finicky. Easiest option is to make sure your animation always lags slightly behind the keyboard animation so it pops up behind it, as doing so before hand could look a bit funny.

 

Getting the real actual height at a given time would be a great feature for more business style apps and I'm definitely going to vote for it. Even better would be to have more control over the keyboard itself. I notice many native apps have more customized colors / submit buttons on their keyboards.

 

As for Android... well you're on your own there for now. I am surprised they give us keyboard access but very little information... basically none... around what it is doing. Alternative is to spend time making your own robust keyboard... that could also be a bit of a nightmare to build.



[TOPIC: post.html]
#5

jonjonsson

[GLOBAL: userInfoPane.html]
jonjonsson
  • Corona Geek

  • 1,051 posts
  • Corona SDK

Yeah Android is the real headache :) Maybe there is some technical reason for Corona not to have this yet, seems very strange omission.



[TOPIC: post.html]
#6

jstrahan

[GLOBAL: userInfoPane.html]
jstrahan
  • Corona Geek

  • 1,926 posts
  • Corona SDK

haven't tried it but here's a custom keyboard although the code is old so may need to make some changes.

http://developer.coronalabs.com/code/onscreenkeyboard



[TOPIC: post.html]
#7

stevebreslin

[GLOBAL: userInfoPane.html]
stevebreslin
  • Observer

  • 21 posts
  • Corona SDK

Craig42, you say "You can get all the apple device keyboard heights", this is what I want. How do you do this ?

[TOPIC: post.html]
#8

craig stowers

[GLOBAL: userInfoPane.html]
craig stowers
  • Enthusiast

  • 42 posts
  • Corona SDK

Craig42, you say "You can get all the apple device keyboard heights", this is what I want. How do you do this ?

 

Sorry to mislead you. I just meant for the ios devices you can do a bit of research and learn the keyboard height for each device. Your program would have to detect which device they are running then set the variable appropriately.

 

I wish there was some system call to get the keyboard height no matter which device.



[TOPIC: post.html]
#9

stevebreslin

[GLOBAL: userInfoPane.html]
stevebreslin
  • Observer

  • 21 posts
  • Corona SDK

Ah yes, that is what I was planning to do. It will work for the limited number of iOS devices but is not a great solution for Android.



[TOPIC: post.html]
#10

cristianomnsantos

[GLOBAL: userInfoPane.html]
cristianomnsantos
  • Observer

  • 13 posts
  • Corona SDK

Well , I believe that this should help Corona Team to make an universal variable that returns the keyboard height on Android right?



[TOPIC: post.html]
#11

Skatan

[GLOBAL: userInfoPane.html]
Skatan
  • Contributor

  • 547 posts
  • Corona SDK

Would be awesome if this feature could get implemented any time soon, especially now with iOS 8 the keyboards are INCREDIBLY dynamic and it is next to impossible to design something properly when you don't know the actual height of the keyboard that is coming up, covering a huge chunk of your screen. Along with custom keyboards the keyboard height can range between a whole range of different heights nowadays, for example with/without keyboard suggestions, custom downloaded keyboards and so on.

 

Our only solution right now is just to animate the screen up 300px when the keyboard comes up as that covers most keyboard heights, but when the keyboard is nowhere close to 300px in height, but say 216px which is the standard height without suggestions, the app looks like a total mess.

 

Implementing this feature would help A LOT as you could make beautiful app ui's for ALL platforms without worrying too much and it would look equally great on all platforms.

 

 

Voted on it on the feature suggestion here, but the suggestion has been there since 2013 without any response from devs so don't know how much use an additional 3 votes would do.

http://feedback.coronalabs.com/forums/188732-corona-sdk-feature-requests-feedback/suggestions/4267410-get-keyboard-height



[TOPIC: post.html]
#12

Skatan

[GLOBAL: userInfoPane.html]
Skatan
  • Contributor

  • 547 posts
  • Corona SDK

Any plans on supporting this, at least for iOS? It is pretty essential now and we currently have no way of knowing the sizes of iOS 8 keyboards at all, even though they can be extremely dynamic. At least iOS can be supported if Android doesn't allow for this possibility?

[TOPIC: post.html]
#13

corona273

[GLOBAL: userInfoPane.html]
corona273
  • Contributor

  • 482 posts
  • Enterprise

Note earlier today: "iOS: When a keyboard appears, the window will shift upward so that the selected native textfield/textbox sits above the keyboard."

 

https://developer.coronalabs.com/corona-daily-builds/summary



[TOPIC: post.html]
#14

stevebreslin

[GLOBAL: userInfoPane.html]
stevebreslin
  • Observer

  • 21 posts
  • Corona SDK

I haven't tried that yet but it looks like they have addressed the problem. Has anyone tried the latest build (2014.2482)?



[TOPIC: post.html]
#15

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,786 posts
  • Enterprise

There are multiple threads about this topic.  Please go here to continue the conversation:

 

http://forums.coronalabs.com/topic/50905-detect-keyboard-height/

 

Thanks

Rob




[topic_controls]
[/topic_controls]