|
826 | 826 |
|
827 | 827 | -- Hide a screen. The screen must either be at the top of the stack or |
828 | 828 | -- visible but not added to the stack (through the no_stack option) |
829 | | --- @param id (string|hash) - Id of the screen to show |
| 829 | +-- @param id (string|hash) - Id of the screen to .hide |
830 | 830 | -- @param cb (function) - Optional callback to invoke when the screen is hidden |
831 | 831 | -- @return true if successfully hiding, false if busy or for some other reason unable to hide the screen |
832 | 832 | function M.hide(id, cb) |
@@ -863,6 +863,42 @@ function M.hide(id, cb) |
863 | 863 | end |
864 | 864 |
|
865 | 865 |
|
| 866 | + |
| 867 | + |
| 868 | +-- Clear stack completely. Any visible screens will be hidden by navigating back out |
| 869 | +-- from them. |
| 870 | +-- @param cb (function) - Optional callback to invoke when the stack has been cleared |
| 871 | +function M.clear(cb) |
| 872 | + log("clear() queuing action") |
| 873 | + |
| 874 | + queue_action(function(action_done, action_error) |
| 875 | + local co |
| 876 | + co = coroutine.create(function() |
| 877 | + |
| 878 | + local callbacks = callback_tracker() |
| 879 | + |
| 880 | + local top = stack[#stack] |
| 881 | + while top and top.visible do |
| 882 | + stack[#stack] = nil |
| 883 | + back_out(top, screen, WAIT_FOR_TRANSITION, callbacks.track()) |
| 884 | + callbacks.yield_until_done() |
| 885 | + top = stack[#stack] |
| 886 | + end |
| 887 | + |
| 888 | + while stack[#stack] do |
| 889 | + table.remove(stack) |
| 890 | + end |
| 891 | + |
| 892 | + callbacks.when_done(function() |
| 893 | + pcallfn(cb) |
| 894 | + pcallfn(action_done) |
| 895 | + end) |
| 896 | + end) |
| 897 | + assert(coroutine.resume(co)) |
| 898 | + end) |
| 899 | +end |
| 900 | + |
| 901 | + |
866 | 902 | -- Go back to the previous screen in the stack. |
867 | 903 | -- @param data (*) - Optional data to set for the previous screen |
868 | 904 | -- @param cb (function) - Optional callback to invoke when the previous screen is visible again |
|
0 commit comments