From 4973134fb64f9ffd377eb1453d4bbc837e53136c Mon Sep 17 00:00:00 2001 From: hius07 <62179190+hius07@users.noreply.github.com> Date: Sun, 30 May 2021 02:02:07 +0300 Subject: [PATCH] VirtualKeyboard: Allow hiding the keyboard with a hold on the down arrow key (#7751) (And showing it again with a tap on an input field) --- frontend/ui/widget/inputdialog.lua | 1 + frontend/ui/widget/inputtext.lua | 17 ++++++++++++++++- frontend/ui/widget/virtualkeyboard.lua | 13 ++++++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/frontend/ui/widget/inputdialog.lua b/frontend/ui/widget/inputdialog.lua index 759acd736..f5609ffcb 100644 --- a/frontend/ui/widget/inputdialog.lua +++ b/frontend/ui/widget/inputdialog.lua @@ -391,6 +391,7 @@ function InputDialog:init() scroll_callback = self._buttons_scroll_callback, -- nil if no Nav or Scroll buttons scroll = true, scroll_by_pan = self.scroll_by_pan, + has_nav_bar = self.add_nav_bar, cursor_at_end = self.cursor_at_end, readonly = self.readonly, parent = self, diff --git a/frontend/ui/widget/inputtext.lua b/frontend/ui/widget/inputtext.lua index 2483b76ab..d565264cc 100644 --- a/frontend/ui/widget/inputtext.lua +++ b/frontend/ui/widget/inputtext.lua @@ -61,6 +61,7 @@ local InputText = InputContainer:new{ for_measurement_only = nil, -- When the widget is a one-off used to compute text height do_select = false, -- to start text selection selection_start_pos = nil, -- selection start position + is_keyboard_hidden = false, -- to be able to show the keyboard again when it was hidden (by VK itself) } -- only use PhysicalKeyboard if the device does not have touch screen @@ -121,6 +122,11 @@ if Device:isTouchDevice() or Device:hasDPad() then function InputText:onTapTextBox(arg, ges) if self.parent.onSwitchFocus then self.parent:onSwitchFocus(self) + else + if self.is_keyboard_hidden == true then + self:onShowKeyboard() + self.is_keyboard_hidden = false + end end if #self.charlist > 0 then -- Avoid cursor moving within a hint. local textwidget_offset = self.margin + self.bordersize + self.padding @@ -563,12 +569,21 @@ end function InputText:onShowKeyboard(ignore_first_hold_release) Device:startTextInput() - self.keyboard.ignore_first_hold_release = ignore_first_hold_release UIManager:show(self.keyboard) return true end +function InputText:onHideKeyboard() + if not self.has_nav_bar then + UIManager:close(self.keyboard) + Device:stopTextInput() + self.is_keyboard_hidden = true + end + + return self.is_keyboard_hiddenend +end + function InputText:onCloseKeyboard() UIManager:close(self.keyboard) Device:stopTextInput() diff --git a/frontend/ui/widget/virtualkeyboard.lua b/frontend/ui/widget/virtualkeyboard.lua index 98eef7233..5dbd4868d 100644 --- a/frontend/ui/widget/virtualkeyboard.lua +++ b/frontend/ui/widget/virtualkeyboard.lua @@ -111,7 +111,7 @@ function VirtualKey:init() self.keyboard:delToStartOfLine() end --self.skiphold = true - elseif self.label =="←" then + elseif self.label == "←" then self.callback = function() self.keyboard:leftChar() end self.hold_callback = function() self.ignore_key_release = true @@ -127,6 +127,13 @@ function VirtualKey:init() self.callback = function() self.keyboard:upLine() end elseif self.label == "↓" then self.callback = function() self.keyboard:downLine() end + self.hold_callback = function() + self.ignore_key_release = true + if not self.keyboard:onHideKeyboard() then + -- Keyboard was *not* actually hidden: refresh the key to clear the highlight + self:update_keyboard(false, true) + end + end else self.callback = function () self.keyboard:addChar(self.key) end self.hold_callback = function() @@ -762,6 +769,10 @@ function VirtualKeyboard:onClose() return true end +function VirtualKeyboard:onHideKeyboard() + return self.inputbox:onHideKeyboard() +end + function VirtualKeyboard:onPressKey() self:getFocusItem():handleEvent(Event:new("TapSelect")) return true