mirror of
https://github.com/britzl/monarch.git
synced 2025-06-27 10:27:49 +02:00
Changed from single notification to begin and end notification for every navigation
This commit is contained in:
parent
b13adcfb62
commit
22f0e6cddf
@ -24,8 +24,10 @@ M.FOCUS.GAINED = hash("monarch_focus_gained")
|
|||||||
M.FOCUS.LOST = hash("monarch_focus_lost")
|
M.FOCUS.LOST = hash("monarch_focus_lost")
|
||||||
|
|
||||||
-- listener messages
|
-- listener messages
|
||||||
M.SCREEN_VISIBLE = hash("monarch_screen_visible")
|
M.SCREEN_TRANSITION_IN_STARTED = hash("monarch_screen_transition_in_started")
|
||||||
M.SCREEN_HIDDEN = hash("monarch_screen_hidden")
|
M.SCREEN_TRANSITION_IN_FINISHED = hash("monarch_screen_transition_in_finished")
|
||||||
|
M.SCREEN_TRANSITION_OUT_STARTED = hash("monarch_screen_transition_out_started")
|
||||||
|
M.SCREEN_TRANSITION_OUT_FINISHED = hash("monarch_screen_transition_out_finished")
|
||||||
|
|
||||||
|
|
||||||
-- all registered screens
|
-- all registered screens
|
||||||
@ -248,6 +250,7 @@ local function show_out(screen, next_screen, cb)
|
|||||||
local co
|
local co
|
||||||
co = coroutine.create(function()
|
co = coroutine.create(function()
|
||||||
active_transition_count = active_transition_count + 1
|
active_transition_count = active_transition_count + 1
|
||||||
|
notify_listeners(M.SCREEN_TRANSITION_OUT_STARTED, { screen = screen.id, next_screen = next_screen.id })
|
||||||
screen.co = co
|
screen.co = co
|
||||||
change_context(screen)
|
change_context(screen)
|
||||||
release_input(screen)
|
release_input(screen)
|
||||||
@ -263,7 +266,7 @@ local function show_out(screen, next_screen, cb)
|
|||||||
screen.co = nil
|
screen.co = nil
|
||||||
active_transition_count = active_transition_count - 1
|
active_transition_count = active_transition_count - 1
|
||||||
if cb then cb() end
|
if cb then cb() end
|
||||||
notify_listeners(M.SCREEN_HIDDEN, { screen = screen.id, next_screen = next_screen.id })
|
notify_listeners(M.SCREEN_TRANSITION_OUT_FINISHED, { screen = screen.id, next_screen = next_screen.id })
|
||||||
end)
|
end)
|
||||||
coroutine.resume(co)
|
coroutine.resume(co)
|
||||||
end
|
end
|
||||||
@ -273,6 +276,7 @@ local function show_in(screen, previous_screen, reload, cb)
|
|||||||
local co
|
local co
|
||||||
co = coroutine.create(function()
|
co = coroutine.create(function()
|
||||||
active_transition_count = active_transition_count + 1
|
active_transition_count = active_transition_count + 1
|
||||||
|
notify_listeners(M.SCREEN_TRANSITION_IN_STARTED, { screen = screen.id, previous_screen = previous_screen and previous_screen.id })
|
||||||
screen.co = co
|
screen.co = co
|
||||||
change_context(screen)
|
change_context(screen)
|
||||||
if reload and screen.loaded then
|
if reload and screen.loaded then
|
||||||
@ -299,7 +303,7 @@ local function show_in(screen, previous_screen, reload, cb)
|
|||||||
screen.co = nil
|
screen.co = nil
|
||||||
active_transition_count = active_transition_count - 1
|
active_transition_count = active_transition_count - 1
|
||||||
if cb then cb() end
|
if cb then cb() end
|
||||||
notify_listeners(M.SCREEN_VISIBLE, { screen = screen.id, previous_screen = previous_screen and previous_screen.id })
|
notify_listeners(M.SCREEN_TRANSITION_IN_FINISHED, { screen = screen.id, previous_screen = previous_screen and previous_screen.id })
|
||||||
end)
|
end)
|
||||||
coroutine.resume(co)
|
coroutine.resume(co)
|
||||||
end
|
end
|
||||||
@ -310,6 +314,7 @@ local function back_in(screen, previous_screen, cb)
|
|||||||
local co
|
local co
|
||||||
co = coroutine.create(function()
|
co = coroutine.create(function()
|
||||||
active_transition_count = active_transition_count + 1
|
active_transition_count = active_transition_count + 1
|
||||||
|
notify_listeners(M.SCREEN_TRANSITION_IN_STARTED, { screen = screen.id, previous_screen = previous_screen and previous_screen.id })
|
||||||
screen.co = co
|
screen.co = co
|
||||||
change_context(screen)
|
change_context(screen)
|
||||||
if screen.preloaded then
|
if screen.preloaded then
|
||||||
@ -329,7 +334,7 @@ local function back_in(screen, previous_screen, cb)
|
|||||||
screen.co = nil
|
screen.co = nil
|
||||||
active_transition_count = active_transition_count - 1
|
active_transition_count = active_transition_count - 1
|
||||||
if cb then cb() end
|
if cb then cb() end
|
||||||
notify_listeners(M.SCREEN_VISIBLE, { screen = screen.id, previous_screen = previous_screen.id })
|
notify_listeners(M.SCREEN_TRANSITION_IN_FINISHED, { screen = screen.id, previous_screen = previous_screen and previous_screen.id })
|
||||||
end)
|
end)
|
||||||
coroutine.resume(co)
|
coroutine.resume(co)
|
||||||
end
|
end
|
||||||
@ -339,6 +344,7 @@ local function back_out(screen, next_screen, cb)
|
|||||||
print("back_out()", screen.id)
|
print("back_out()", screen.id)
|
||||||
local co
|
local co
|
||||||
co = coroutine.create(function()
|
co = coroutine.create(function()
|
||||||
|
notify_listeners(M.SCREEN_TRANSITION_OUT_STARTED, { screen = screen.id, next_screen = next_screen.id })
|
||||||
active_transition_count = active_transition_count + 1
|
active_transition_count = active_transition_count + 1
|
||||||
screen.co = co
|
screen.co = co
|
||||||
change_context(screen)
|
change_context(screen)
|
||||||
@ -349,7 +355,7 @@ local function back_out(screen, next_screen, cb)
|
|||||||
screen.co = nil
|
screen.co = nil
|
||||||
active_transition_count = active_transition_count - 1
|
active_transition_count = active_transition_count - 1
|
||||||
if cb then cb() end
|
if cb then cb() end
|
||||||
notify_listeners(M.SCREEN_HIDDEN, { screen = screen.id, next_screen = next_screen and next_screen.id })
|
notify_listeners(M.SCREEN_TRANSITION_OUT_FINISHED, { screen = screen.id, next_screen = next_screen.id })
|
||||||
end)
|
end)
|
||||||
coroutine.resume(co)
|
coroutine.resume(co)
|
||||||
end
|
end
|
||||||
|
@ -241,7 +241,15 @@ return function()
|
|||||||
monarch.add_listener(URL2)
|
monarch.add_listener(URL2)
|
||||||
|
|
||||||
monarch.show(SCREEN1)
|
monarch.show(SCREEN1)
|
||||||
|
assert(mock_msg.messages(URL1)[1].message_id == monarch.SCREEN_TRANSITION_IN_STARTED)
|
||||||
|
assert(mock_msg.messages(URL1)[1].message.screen == SCREEN1)
|
||||||
|
assert(mock_msg.messages(URL2)[1].message_id == monarch.SCREEN_TRANSITION_IN_STARTED)
|
||||||
|
assert(mock_msg.messages(URL2)[1].message.screen == SCREEN1)
|
||||||
assert(wait_until_not_busy())
|
assert(wait_until_not_busy())
|
||||||
|
assert(mock_msg.messages(URL1)[2].message_id == monarch.SCREEN_TRANSITION_IN_FINISHED)
|
||||||
|
assert(mock_msg.messages(URL1)[2].message.screen == SCREEN1)
|
||||||
|
assert(mock_msg.messages(URL2)[2].message_id == monarch.SCREEN_TRANSITION_IN_FINISHED)
|
||||||
|
assert(mock_msg.messages(URL2)[2].message.screen == SCREEN1)
|
||||||
|
|
||||||
monarch.remove_listener(URL2)
|
monarch.remove_listener(URL2)
|
||||||
monarch.show(SCREEN2)
|
monarch.show(SCREEN2)
|
||||||
@ -252,15 +260,16 @@ return function()
|
|||||||
|
|
||||||
local messages_1 = mock_msg.messages(URL1)
|
local messages_1 = mock_msg.messages(URL1)
|
||||||
local messages_2 = mock_msg.messages(URL2)
|
local messages_2 = mock_msg.messages(URL2)
|
||||||
assert(#messages_1 == 5)
|
assert(#mock_msg.messages(URL1) == 10)
|
||||||
assert(#messages_2 == 1)
|
assert(#mock_msg.messages(URL2) == 2)
|
||||||
assert(messages_2[1].message_id == monarch.SCREEN_VISIBLE and messages_1[1].message.screen == SCREEN1)
|
assert(mock_msg.messages(URL1)[3].message_id == monarch.SCREEN_TRANSITION_OUT_STARTED)
|
||||||
|
assert(mock_msg.messages(URL1)[3].message.screen == SCREEN1)
|
||||||
assert(messages_1[1].message_id == monarch.SCREEN_VISIBLE and messages_1[1].message.screen == SCREEN1)
|
assert(mock_msg.messages(URL1)[4].message_id == monarch.SCREEN_TRANSITION_IN_STARTED)
|
||||||
assert(messages_1[2].message_id == monarch.SCREEN_HIDDEN and messages_1[2].message.screen == SCREEN1)
|
assert(mock_msg.messages(URL1)[4].message.screen == SCREEN2)
|
||||||
assert(messages_1[3].message_id == monarch.SCREEN_VISIBLE and messages_1[3].message.screen == SCREEN2)
|
assert(mock_msg.messages(URL1)[5].message_id == monarch.SCREEN_TRANSITION_OUT_FINISHED)
|
||||||
assert(messages_1[4].message_id == monarch.SCREEN_HIDDEN and messages_1[4].message.screen == SCREEN2)
|
assert(mock_msg.messages(URL1)[5].message.screen == SCREEN1)
|
||||||
assert(messages_1[5].message_id == monarch.SCREEN_VISIBLE and messages_1[5].message.screen == SCREEN1)
|
assert(mock_msg.messages(URL1)[6].message_id == monarch.SCREEN_TRANSITION_IN_FINISHED)
|
||||||
|
assert(mock_msg.messages(URL1)[7].message.screen == SCREEN2)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user