Merge pull request #2076 from koreader/houqp-master

uimanager(fix): handle edge case where second widget in stack is ignored
pull/2079/head
Huang Xin 8 years ago committed by GitHub
commit 3544d0b0ee

@ -395,7 +395,7 @@ function UIManager:sendEvent(event)
-- if the event is not consumed, active widgets (from top to bottom) can
-- access it. NOTE: _window_stack can shrink on close event
local checked_widgets = {top_widget}
for i = #self._window_stack-1, 1, -1 do
for i = #self._window_stack, 1, -1 do
local widget = self._window_stack[i]
if checked_widgets[widget] == nil then
if widget.widget.is_always_active then

@ -232,9 +232,7 @@ describe("UIManager spec", function()
end)
it("should handle stack change when checking for active widgets", function()
-- this senario should only happen when other active widgets
-- are closed by the one widget's handleEvent
-- senario 1: 2nd widget removes the 3rd widget in the stack
local call_signals = {0, 0, 0}
UIManager._window_stack = {
{
@ -269,5 +267,40 @@ describe("UIManager spec", function()
assert.is.same(call_signals[1], 1)
assert.is.same(call_signals[2], 0)
assert.is.same(call_signals[3], 1)
-- senario 2: top widget removes itself
call_signals = {0, 0, 0}
UIManager._window_stack = {
{
widget = {
is_always_active = true,
handleEvent = function()
call_signals[1] = call_signals[1] + 1
end
}
},
{
widget = {
is_always_active = true,
handleEvent = function()
call_signals[2] = call_signals[2] + 1
end
}
},
{
widget = {
is_always_active = true,
handleEvent = function()
call_signals[3] = call_signals[3] + 1
table.remove(UIManager._window_stack, 3)
end
}
},
}
UIManager:sendEvent("foo")
assert.is.same(call_signals[1], 1)
assert.is.same(call_signals[2], 1)
assert.is.same(call_signals[3], 1)
end)
end)

Loading…
Cancel
Save