Page 1 of 1

BackKey: best way to use it

Posted: Thu Sep 17, 2020 10:27 am
by trevix
In my standalone I have several "Return" buttons that navigate to the previous card, while holding a script that, for example, save new settings or else.
For example, in card B there is a button "return" that go to card A after having saved something and set some stuff on card A before showing.

Coming from iOS I didn't realise how Android users count on the physical Backkey of their device.
I am now trying to find the best way to implement this all over my stack.

As I understand the

Code: Select all

on BackKey
...(1) eventually do something, like saving and going to previous card
--do not pass otherwise the standalone exits
end backer
must be put on each card script. Since the code (1) is already on the mouseUp script of the button ("return"),I would like to hold this script in a single place, without duplicating it. I was wondering if the script below (that works) is the best way to do it (without having to put a
send "Mouseup" to btn return of card B
(that doesn't sound the best way since I have already "send" and "cancel" all over the standalone.

Card B script:

Code: Select all

On Backkey
set the FireBackKey of btn "return" of this card to empty
end Backkey
Btn "return" script:

Code: Select all

On Mouseup
put true into gSetting
set the backcolor of rect "X" of card "A" to red
go card "A"
End Mouseup

SetProp FireBackKey
Mouseup
end FireBackKey

Re: BackKey: best way to use it

Posted: Thu Sep 17, 2020 12:14 pm
by trevix
Thinking of it, I may have to rewrite all navigation of my stacks.
This one could be a better solution.
card B script:

Code: Select all

On Backkey --the actual navigation
put true into gSetting
set the backcolor of rect "X" of card "A" to red
go card "A"
end Backkey
The navigation "return" button script of card B:

Code: Select all

On Mouseup
Backkey
end Mouseup
Before I rewrite the all stack, is this the correct solution?

Re: BackKey: best way to use it

Posted: Thu Sep 17, 2020 5:51 pm
by jacque
You're right, the back key is essential for Android users. There's nothing wrong with using "send" which is how I usually do it. If all your back navigation always goes to the same place then you don't need send, but in my apps the Back button is usually specific to the card.

The handler is very simple in that case, and can go in the stack script or a background group script:

Code: Select all

on backkey
  if there is a button "back" of this card
  then send "mouseUp" to button "back" of this card
end backkey
If the Back button always goes to the same place then all you need is:

Code: Select all

on backkey
  go card "A" 
end backkey