Skip to content

Commit 72a54d7

Browse files
authored
add callback for text show/hide (#282)
Those callback are useful when wanting to display the OS virtual keyboard.
1 parent e5c70be commit 72a54d7

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

option.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,27 @@ type KeyboardShortcuts struct {
245245
Paste glfw.Key
246246
SelectAll glfw.Key
247247
}
248+
249+
// VirtualKeyboardShow sets an func called when the flutter framework want to
250+
// show the keyboard.
251+
// This Option is interesting for people wanting to display the on-screen
252+
// keyboard on TextField focus.
253+
// It's up to the flutter developer to implement (or not) this function with
254+
// the OS related call.
255+
func VirtualKeyboardShow(showCallback func()) Option {
256+
return func(c *config) {
257+
// Reference the callback to the platform plugin (singleton) responsible
258+
// for textinput.
259+
defaultTextinputPlugin.virtualKeyboardShow = showCallback
260+
}
261+
}
262+
263+
// VirtualKeyboardHide sets an func called when the flutter framework want to
264+
// hide the keyboard.
265+
func VirtualKeyboardHide(hideCallback func()) Option {
266+
return func(c *config) {
267+
// Reference the callback to the platform plugin (singleton) responsible
268+
// for textinput.
269+
defaultTextinputPlugin.virtualKeyboardHide = hideCallback
270+
}
271+
}

textinput.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ type textinputPlugin struct {
2626
word []rune
2727
selectionBase int
2828
selectionExtent int
29+
30+
virtualKeyboardShow func()
31+
virtualKeyboardHide func()
2932
}
3033

3134
// keyboardShortcutsGLFW handle glfw.ModifierKey from glfwKeyCallback.
@@ -51,9 +54,18 @@ func (p *textinputPlugin) InitPluginGLFW(window *glfw.Window) error {
5154
p.channel.HandleFuncSync("TextInput.setClient", p.handleSetClient)
5255
p.channel.HandleFuncSync("TextInput.clearClient", p.handleClearClient)
5356
p.channel.HandleFuncSync("TextInput.setEditingState", p.handleSetEditingState)
54-
// Ignored: Desktop's don't have a virtual keyboard, so there is no need to show or hide it
55-
p.channel.HandleFuncSync("TextInput.show", func(_ interface{}) (interface{}, error) { return nil, nil })
56-
p.channel.HandleFuncSync("TextInput.hide", func(_ interface{}) (interface{}, error) { return nil, nil })
57+
p.channel.HandleFunc("TextInput.show", func(_ interface{}) (interface{}, error) {
58+
if p.virtualKeyboardShow != nil {
59+
p.virtualKeyboardShow()
60+
}
61+
return nil, nil
62+
})
63+
p.channel.HandleFunc("TextInput.hide", func(_ interface{}) (interface{}, error) {
64+
if p.virtualKeyboardHide != nil {
65+
p.virtualKeyboardHide()
66+
}
67+
return nil, nil
68+
})
5769
return nil
5870
}
5971

0 commit comments

Comments
 (0)