From 036cdb853d4df40e56bd25ddf46f8c8d780a6cc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ritzl?= Date: Mon, 27 Nov 2017 21:48:21 +0100 Subject: [PATCH] Fixed some issues regarding focus lost/gained next/previous screen id --- README.md | 8 ++++---- monarch/monarch.lua | 21 +++++++++++---------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index c4be919..1dd09e3 100644 --- a/README.md +++ b/README.md @@ -98,15 +98,15 @@ When a transition is completed it is up to the developer to send a ```transition end ## 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" function on_message(self, message_id, message, sender) if message_id == monarch.FOCUS_GAINED then - print("Focus gained") + print("Focus gained, previous screen: ", message.id) elseif message_id == monarch.FOCUS_LOST then - print("Focus lost") + print("Focus lost, next screen: ", message.id) end end @@ -127,7 +127,7 @@ Show a Monarch screen 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. - +* ```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]) Go back to a previous Monarch screen diff --git a/monarch/monarch.lua b/monarch/monarch.lua index 5049fa5..8918fbc 100644 --- a/monarch/monarch.lua +++ b/monarch/monarch.lua @@ -21,8 +21,9 @@ M.TRANSITION.SHOW_OUT = hash("transition_show_out") M.TRANSITION.BACK_IN = hash("transition_back_in") M.TRANSITION.BACK_OUT = hash("transition_back_out") -M.FOCUS_GAINED = hash("monarch_focus_gained") -M.FOCUS_LOST = hash("monarch_focus_lost") +M.FOCUS = {} +M.FOCUS.GAINED = hash("monarch_focus_gained") +M.FOCUS.LOST = hash("monarch_focus_lost") local function screen_from_proxy(proxy) @@ -83,7 +84,7 @@ local function show_out(screen, next_screen, cb) screen.loaded = false end 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 screen.co = nil if cb then cb() end @@ -91,7 +92,7 @@ local function show_out(screen, next_screen, cb) coroutine.resume(co) end -local function show_in(screen, reload, cb) +local function show_in(screen, previous_screen, reload, cb) local co co = coroutine.create(function() screen.co = co @@ -116,7 +117,7 @@ local function show_in(screen, reload, cb) coroutine.yield() msg.post(screen.script, ACQUIRE_INPUT_FOCUS) 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 screen.co = nil if cb then cb() end @@ -140,7 +141,7 @@ local function back_in(screen, previous_screen, cb) end msg.post(screen.script, ACQUIRE_INPUT_FOCUS) 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 screen.co = nil if cb then cb() end @@ -148,7 +149,7 @@ local function back_in(screen, previous_screen, cb) coroutine.resume(co) end -local function back_out(screen, cb) +local function back_out(screen, next_screen, cb) local co co = coroutine.create(function() screen.co = co @@ -161,7 +162,7 @@ local function back_out(screen, cb) coroutine.yield() screen.loaded = false 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 screen.co = nil if cb then cb() end @@ -229,7 +230,7 @@ function M.show(id, options, data, cb) end -- show screen - show_in(screen, options and options.reload, cb) + show_in(screen, top, options and options.reload, cb) end @@ -239,8 +240,8 @@ end function M.back(data, cb) local screen = table.remove(stack) if screen then - back_out(screen, cb) local top = stack[#stack] + back_out(screen, top, cb) if top then if data then screen.data = data