3
0
mirror of https://github.com/britzl/monarch.git synced 2025-06-27 10:27:49 +02:00

Wait for popups when closing them

This commit is contained in:
Björn Ritzl 2019-01-23 08:08:56 +01:00
parent 79df80df33
commit 38f95e0b5b

View File

@ -568,48 +568,55 @@ function M.show(id, options, data, cb)
log("show()", screen.id) log("show()", screen.id)
-- a screen can ignore the stack by setting the no_stack to true local co
local add_to_stack = not options or not options.no_stack co = coroutine.create(function()
if add_to_stack then -- a screen can ignore the stack by setting the no_stack to true
-- manipulate the current top local add_to_stack = not options or not options.no_stack
-- close popup if needed if add_to_stack then
-- transition out -- manipulate the current top
local top = stack[#stack] -- close popup(s) if needed
if top then -- transition out
-- keep top popup visible if new screen can be shown on top of a popup local top = stack[#stack]
if top.popup and screen.popup_on_popup then if top then
disable(top, screen) -- keep top popup visible if new screen can be shown on top of a popup
else if top.popup and screen.popup_on_popup then
-- close all popups disable(top, screen)
while top.popup do else
stack[#stack] = nil -- close all popups, one by one
show_out(top, screen, callbacks.track()) while top.popup do
top = stack[#stack] stack[#stack] = nil
end show_out(top, screen, function()
-- unload and transition out from top coroutine.resume(co)
-- unless we're showing the same screen as is already visible end)
if top and top.id ~= screen.id then coroutine.yield()
show_out(top, screen, callbacks.track()) top = stack[#stack]
end
-- unload and transition out from top
-- unless we're showing the same screen as is already visible
if top and top.id ~= screen.id then
show_out(top, screen, callbacks.track())
end
end end
end end
end end
end
-- if the screen we want to show is in the stack -- if the screen we want to show is in the stack
-- already and the clear flag is set then we need -- already and the clear flag is set then we need
-- to remove every screen on the stack up until and -- to remove every screen on the stack up until and
-- including the screen itself -- including the screen itself
if options and options.clear then if options and options.clear then
log("show() clearing") log("show() clearing")
while M.in_stack(id) do while M.in_stack(id) do
table.remove(stack) table.remove(stack)
end
end end
end
-- show screen -- show screen
show_in(screen, top, options and options.reload, add_to_stack, callbacks.track()) show_in(screen, top, options and options.reload, add_to_stack, callbacks.track())
if cb then callbacks.when_done(cb) end if cb then callbacks.when_done(cb) end
end)
coroutine.resume(co)
return true return true
end end