Skip to content

Commit 5bdc3e4

Browse files
committed
Added option table to back()
1 parent 85123c8 commit 5bdc3e4

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

README_API.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,18 @@ Clear the stack of screens completely. Any visible screen will be hidden by navi
4040
* `callback` (function) - Optional function to call when the stack has been cleared.
4141

4242

43-
## monarch.back([data], [callback])
43+
## monarch.back([options], [data], [callback])
4444
Go back to a previous Monarch screen. This operation will be added to the queue if Monarch is busy.
4545

4646
**PARAMETERS**
47+
* `options` (table) - Options when showing the new screen (see below).
4748
* `data` (table) - Optional data to associate with the screen you are going back to. Retrieve using `monarch.data()`.
4849
* `callback` (function) - Optional function to call when the previous screen is visible.
4950

51+
The options table can contain the following fields:
52+
53+
* `sequential` (boolean) - If the `sequential` flag is set Monarch will start loading the screen only after the previous screen finished transitioning out.
54+
5055

5156
## monarch.preload(screen_id, [options], [callback])
5257
Preload a Monarch screen. This will load but not enable the screen. This is useful for content heavy screens that you wish to be able to show without having to wait for it load. This operation will be added to the queue if Monarch is busy.

monarch/monarch.lua

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -965,21 +965,38 @@ end
965965

966966

967967
-- Go back to the previous screen in the stack.
968+
-- @param options (table) - Table with options when backing out from the screen (can be nil).
969+
-- Valid values:
970+
-- * sequential - Set to true to wait for the current screen to hide itself out before starting the
971+
-- back in transition even when transitioning to a different scene ID.
972+
968973
-- @param data (*) - Optional data to set for the previous screen
969974
-- @param cb (function) - Optional callback to invoke when the previous screen is visible again
970-
function M.back(data, cb)
975+
function M.back(options, data, cb)
971976
log("back() queuing action")
977+
-- backwards compatibility with old version M.back(data, cb)
978+
-- case when back(data, cb)
979+
if type(data) == "function" then
980+
cb = data
981+
data = options
982+
options = nil
983+
-- case when back(data, nil)
984+
elseif options ~= nil and data == nil and cb == nil then
985+
data = options
986+
options = nil
987+
end
972988

973989
queue_action(function(action_done)
974990
local callbacks = callback_tracker()
975-
local back_cb = callbacks.track()
976991
local screen = table.remove(stack)
977992
if screen then
978993
log("back()", screen.id)
979994
local top = stack[#stack]
980995
-- if we go back to the same screen we need to first hide it
981996
-- and wait until it is hidden before we show it again
982-
if top and screen.id == top.id then
997+
local same_screen = top and top.id == screen.id
998+
if same_screen or (options and options.sequential) then
999+
local back_cb = callbacks.track()
9831000
back_out(screen, top, WAIT_FOR_TRANSITION, function()
9841001
if data then
9851002
top.data = data

0 commit comments

Comments
 (0)