Skip to content

Commit

Permalink
Fix issue when a layout changes and there's an ongoing transition
Browse files Browse the repository at this point in the history
  • Loading branch information
britzl committed May 10, 2020
1 parent 504ac92 commit 909ada9
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
3 changes: 2 additions & 1 deletion monarch/transitions/gui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ local function create()
if t.in_progress_count == 0 then
table.insert(t.urls, msg.url())
current_transition = t
current_transition.id = transition_id
if #t.transitions > 0 then
for i=1,#t.transitions do
local transition = t.transitions[i]
Expand Down Expand Up @@ -206,7 +207,7 @@ local function create()
transition.fn(transition.node, transition.node_data, transition.easing, 0, 0)
end
if current_transition.in_progress_count > 0 then
finish_transition(message_id)
finish_transition(current_transition.id)
end
end
elseif message_id == monarch.TRANSITION.SHOW_IN
Expand Down
2 changes: 2 additions & 0 deletions test/test.script
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ local deftest = require "deftest.deftest"

local test_monarch = require "test.test_monarch"
local test_callback_tracker = require "test.test_callback_tracker"
local test_transitions = require "test.test_transitions"


function init(self)
deftest.add(test_monarch)
deftest.add(test_callback_tracker)
deftest.add(test_transitions)
deftest.run({
coverage = { enabled = true },
pattern = "",
Expand Down
46 changes: 46 additions & 0 deletions test/test_transitions.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
local cowait = require "test.cowait"
local mock_msg = require "test.msg"
local mock_gui = require "deftest.mock.gui"
local unload = require "deftest.util.unload"
local monarch = require "monarch.monarch"
local transitions = require "monarch.transitions.gui"
local easing = require "monarch.transitions.easings"

return function()

describe("transitions", function()
before(function()
mock_msg.mock()
mock_gui.mock()
transitions = require "monarch.transitions.gui"
end)

after(function()
mock_msg.unmock()
mock_gui.unmock()
unload.unload("monarch%..*")
end)


it("should replay and immediately finish on layout change", function()
function dummy_transition(node, to, easing, duration, delay, cb)
print("dummy transition")
end

local node = gui.new_box_node(vmath.vector3(), vmath.vector3(100, 100, 0))
local duration = 2
local t = transitions.create(node)
.show_in(dummy_transition, easing.OUT, duration, delay or 0)
.show_out(dummy_transition, easing.IN, duration, delay or 0)
.back_in(dummy_transition, easing.OUT, duration, delay or 0)
.back_out(dummy_transition, easing.IN, duration, delay or 0)

t.handle(monarch.TRANSITION.SHOW_IN)
t.handle(hash("layout_changed"))
local messages = mock_msg.messages(msg.url())
assert(#messages == 1, "Expected one message to have been received")
assert(messages[1].message_id == monarch.TRANSITION.DONE, "Expected a TRANSITION.DONE message")
end)
end)

end

0 comments on commit 909ada9

Please sign in to comment.