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

Fixed some issues regarding focus lost/gained next/previous screen id

This commit is contained in:
Björn Ritzl 2017-11-27 21:48:21 +01:00
parent 62684f9795
commit 036cdb853d
2 changed files with 15 additions and 14 deletions

View File

@ -98,15 +98,15 @@ When a transition is completed it is up to the developer to send a ```transition
end end
## Screen focus gain/loss ## Screen focus gain/loss
Monarch will send focus gain and focus loss messages if a Focus Url was provided when the screen was created. Example: Monarch will send focus gain and focus loss messages if a Focus Url was provided when the screen was created. The focus gained message will contain the id of the previous screen and the focus loss message will contain the id of the next screen. Example:
local monarch = require "monarch.monarch" local monarch = require "monarch.monarch"
function on_message(self, message_id, message, sender) function on_message(self, message_id, message, sender)
if message_id == monarch.FOCUS_GAINED then if message_id == monarch.FOCUS_GAINED then
print("Focus gained") print("Focus gained, previous screen: ", message.id)
elseif message_id == monarch.FOCUS_LOST then elseif message_id == monarch.FOCUS_LOST then
print("Focus lost") print("Focus lost, next screen: ", message.id)
end end
end end
@ -127,7 +127,7 @@ Show a Monarch screen
The options table can contain the following fields: The options table can contain the following fields:
* ```clear``` (boolean) - If the clear flag is set Monarch will search the stack for the screen that is to be shown. If the screen already exists in the stack and the clear flag is set Monarch will remove all screens between the current top and the screen in question. * ```clear``` (boolean) - If the clear flag is set Monarch will search the stack for the screen that is to be shown. If the screen already exists in the stack and the clear flag is set Monarch will remove all screens between the current top and the screen in question.
* ```reload``` (boolean) - If the reload flag is set Monarch will reload the collection proxy if it's already loaded (this can happen if the previous screen was a popup).
### monarch.back([data], [callback]) ### monarch.back([data], [callback])
Go back to a previous Monarch screen Go back to a previous Monarch screen

View File

@ -21,8 +21,9 @@ M.TRANSITION.SHOW_OUT = hash("transition_show_out")
M.TRANSITION.BACK_IN = hash("transition_back_in") M.TRANSITION.BACK_IN = hash("transition_back_in")
M.TRANSITION.BACK_OUT = hash("transition_back_out") M.TRANSITION.BACK_OUT = hash("transition_back_out")
M.FOCUS_GAINED = hash("monarch_focus_gained") M.FOCUS = {}
M.FOCUS_LOST = hash("monarch_focus_lost") M.FOCUS.GAINED = hash("monarch_focus_gained")
M.FOCUS.LOST = hash("monarch_focus_lost")
local function screen_from_proxy(proxy) local function screen_from_proxy(proxy)
@ -83,7 +84,7 @@ local function show_out(screen, next_screen, cb)
screen.loaded = false screen.loaded = false
end end
if screen.focus_url then if screen.focus_url then
msg.post(screen.focus_url, M.FOCUS_LOST, {id = next_screen.id}) msg.post(screen.focus_url, M.FOCUS.LOST, {id = next_screen.id})
end end
screen.co = nil screen.co = nil
if cb then cb() end if cb then cb() end
@ -91,7 +92,7 @@ local function show_out(screen, next_screen, cb)
coroutine.resume(co) coroutine.resume(co)
end end
local function show_in(screen, reload, cb) local function show_in(screen, previous_screen, reload, cb)
local co local co
co = coroutine.create(function() co = coroutine.create(function()
screen.co = co screen.co = co
@ -116,7 +117,7 @@ local function show_in(screen, reload, cb)
coroutine.yield() coroutine.yield()
msg.post(screen.script, ACQUIRE_INPUT_FOCUS) msg.post(screen.script, ACQUIRE_INPUT_FOCUS)
if screen.focus_url then if screen.focus_url then
msg.post(screen.focus_url, M.FOCUS_GAINED, {id = screen.id}) msg.post(screen.focus_url, M.FOCUS.GAINED, {id = previous_screen and previous_screen.id})
end end
screen.co = nil screen.co = nil
if cb then cb() end if cb then cb() end
@ -140,7 +141,7 @@ local function back_in(screen, previous_screen, cb)
end end
msg.post(screen.script, ACQUIRE_INPUT_FOCUS) msg.post(screen.script, ACQUIRE_INPUT_FOCUS)
if screen.focus_url then if screen.focus_url then
msg.post(screen.focus_url, M.FOCUS_GAINED, {id = previous_screen.id}) msg.post(screen.focus_url, M.FOCUS.GAINED, {id = previous_screen.id})
end end
screen.co = nil screen.co = nil
if cb then cb() end if cb then cb() end
@ -148,7 +149,7 @@ local function back_in(screen, previous_screen, cb)
coroutine.resume(co) coroutine.resume(co)
end end
local function back_out(screen, cb) local function back_out(screen, next_screen, cb)
local co local co
co = coroutine.create(function() co = coroutine.create(function()
screen.co = co screen.co = co
@ -161,7 +162,7 @@ local function back_out(screen, cb)
coroutine.yield() coroutine.yield()
screen.loaded = false screen.loaded = false
if screen.focus_url then if screen.focus_url then
msg.post(screen.focus_url, M.FOCUS_LOST, {id = screen.id}) msg.post(screen.focus_url, M.FOCUS.LOST, {id = next_screen and next_screen.id})
end end
screen.co = nil screen.co = nil
if cb then cb() end if cb then cb() end
@ -229,7 +230,7 @@ function M.show(id, options, data, cb)
end end
-- show screen -- show screen
show_in(screen, options and options.reload, cb) show_in(screen, top, options and options.reload, cb)
end end
@ -239,8 +240,8 @@ end
function M.back(data, cb) function M.back(data, cb)
local screen = table.remove(stack) local screen = table.remove(stack)
if screen then if screen then
back_out(screen, cb)
local top = stack[#stack] local top = stack[#stack]
back_out(screen, top, cb)
if top then if top then
if data then if data then
screen.data = data screen.data = data