mirror of
https://github.com/Insality/druid
synced 2025-06-27 10:27:48 +02:00
35 lines
875 B
Lua
35 lines
875 B
Lua
--- Component to handle back key (android, backspace)
|
|
-- @module druid.back_handler
|
|
|
|
local const = require("druid.const")
|
|
local component = require("druid.component")
|
|
|
|
local M = component.create("back_handler", { const.ON_INPUT })
|
|
|
|
|
|
--- Component init function
|
|
-- @function back_handler:init
|
|
-- @tparam table self Component instance
|
|
-- @tparam callback callback On back button
|
|
-- @tparam[opt] params Callback argument
|
|
function M.init(self, callback, params)
|
|
self.callback = callback
|
|
self.params = params
|
|
end
|
|
|
|
|
|
--- Input handler for component
|
|
-- @function back_handler:on_input
|
|
-- @tparam string action_id on_input action id
|
|
-- @tparam table action on_input action
|
|
function M.on_input(self, action_id, action)
|
|
if action_id == const.ACTION_BACK and action[const.RELEASED] then
|
|
self.callback(self:get_context(), self.params)
|
|
return true
|
|
end
|
|
|
|
return false
|
|
end
|
|
|
|
|
|
return M |