location of top of keyboard

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Coffee1633
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 219
Joined: Mon Dec 05, 2011 5:35 pm

location of top of keyboard

Post by Coffee1633 » Sat Sep 28, 2013 6:03 pm

Is it possible to get the location of the top of the keyboard when it pops up?

At the moment I have hard coded a number into the code but I cringe when I see it. I was thinking of changing the bottom of the text field to that of the top of the keyboard so there wouldn't be any hidden text or is there some other way to deal with the situation of preventing the text field from being hidden?

Coffee 16

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Contact:

Re: location of top of keyboard

Post by dave.kilroy » Sat Sep 28, 2013 7:01 pm

Hi Coffee

If you use 'effective screenRect' you'll get the area of the screen minus the on-screen keyboard

What follows is an extract from the dictionary entry for screenRect: "Adding the effective adjective to either form returns the area of the screen the application has to itself. In particular, if the keyboard is activated, it take into account if the keyboard is taking up space on the screen. (Android and iOS only)"
"...this is not the code you are looking for..."

Coffee1633
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 219
Joined: Mon Dec 05, 2011 5:35 pm

Re: location of top of keyboard

Post by Coffee1633 » Sun Sep 29, 2013 1:42 am

thanks for the hint.
It all seems so easy and it was working with the hardcoded numbers, but the effective screenRect in the iOS simulator just doesn't want to cooperate

I put this into the field script that I want to have change size, but no go...

Code: Select all

on openField 
     send "shortenField"
end openField

on closeField
     lengthenField     
end closeField

on shortenField
     --set the rect of me to 0,44,320,248  
     set the rect of fld "noteEditor" to the effective screenRect
     put "short rect:" && the screenRect into fld "noteEditor"
end shortenField

on lengthenField
     --set the rect of me to 0,44,320,410
     set the rect of fld "noteEditor" to the effective screenRect
     put "reg rect:" && the screenRect into fld "noteEditor"
end lengthenField
I will try again later after I sleep on it.
Maybe it only works on a real device, hmmm...

Coffee16

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: location of top of keyboard

Post by Simon » Sun Sep 29, 2013 4:09 am

Wow it's true!
I was playing around with effective blah blah a few weeks ago answering the same question you asked.
I just tested it again and it does what I thought it did.
Now at least on Android I found...
wait for it...
it's neat....

Code: Select all

set the acceleratedRendering of this stack to true
in the openStack makes the focused field move to the top of the screen when the keyboard pops up :shock:
No other coding is needed.

Since I haven't seen this documented I don't know if it's just a fluke so I'm not sure it should be relied upon.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Contact:

Re: location of top of keyboard

Post by dave.kilroy » Sun Sep 29, 2013 2:13 pm

Coffee

When on a mobile device (or simulator) the keyboardActivated message is sent to the current card as it opens, and the keyboardDeactivated message is sent when the keyboard is closing. The code below calls the effective working screenRect just after the keyboard appears and just after it slides out of view.

The keyboard is activated by clicking on a (non-locked) field and is deactivated by clicking outside the field (the 'mouseDown' handler for the card in the code below sets the focus to nothing if the card [as opposed to a field] is clicked on - something like this is needed or the user will not be able to remove focus from the field and get the keyboard to go away.

In your code, in the keyboardActivated handler write something to allow for the new effective working screenRect by using your shortenfield handler, or use moving, scrolling or some other method - and do the reverse (your lengthenfield handler) when the keyboardDeactived message fires. And of course you get away from using 'hard-coded' sizes by making use of the effective working screenRect in each handler

Code: Select all

on keyboardActivated
    answer "keyboard activated" & cr & the effective working screenRect
end keyboardActivated

on keyboardDeactivated
    answer "keyboard deactivated" & cr & the effective working screenRect
end keyboardDeactivated

on mousedown
    focus on nothing
end mousedown
Good luck!

Simon - I haven't tried your magic coding trick yet but am about to do so :)
"...this is not the code you are looking for..."

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Contact:

Re: location of top of keyboard

Post by dave.kilroy » Sun Sep 29, 2013 2:21 pm

Simon

Unfortunately including:

Code: Select all

set the acceleratedRendering of this stack to true
In openStack makes no difference in an iOS simulator when I test it (didn't try Android emulator [life is too short]) :(

Dave
"...this is not the code you are looking for..."

Post Reply