Skip to content

Commit

Permalink
Merge pull request #2232 from howeyc/backspace-android
Browse files Browse the repository at this point in the history
fix backspace on android for AOSP-based keyboards
  • Loading branch information
andydotxyz committed May 27, 2021
2 parents 6e9d422 + 6bc5e58 commit dcfaf76
Show file tree
Hide file tree
Showing 6 changed files with 236 additions and 203 deletions.
395 changes: 200 additions & 195 deletions cmd/fyne/internal/mobile/dex.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -7,7 +7,7 @@ require (
github.com/akavel/rsrc v0.8.0 // indirect
github.com/fredbi/uri v0.0.0-20181227131451-3dcfdacbaaf3
github.com/fsnotify/fsnotify v1.4.9
github.com/fyne-io/mobile v0.1.3-0.20210510125822-9a3fcd853577
github.com/fyne-io/mobile v0.1.3-0.20210524083716-78f416561547
github.com/go-gl/gl v0.0.0-20210426225639-a3bfa832c8aa
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210410170116-ea3d685f79fb
github.com/go-ole/go-ole v1.2.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -12,8 +12,8 @@ github.com/fredbi/uri v0.0.0-20181227131451-3dcfdacbaaf3 h1:FDqhDm7pcsLhhWl1QtD8
github.com/fredbi/uri v0.0.0-20181227131451-3dcfdacbaaf3/go.mod h1:CzM2G82Q9BDUvMTGHnXf/6OExw/Dz2ivDj48nVg7Lg8=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fyne-io/mobile v0.1.3-0.20210510125822-9a3fcd853577 h1:xCW6aKh2deFRK6wfCsdTWDg2iSUvj8zYxoHeQt3mvyc=
github.com/fyne-io/mobile v0.1.3-0.20210510125822-9a3fcd853577/go.mod h1:/kOrWrZB6sasLbEy2JIvr4arEzQTXBTZGb3Y96yWbHY=
github.com/fyne-io/mobile v0.1.3-0.20210524083716-78f416561547 h1:q3mR3AT73LxwifSK+gNEQFweMiKLXt3p373X5xbIK+4=
github.com/fyne-io/mobile v0.1.3-0.20210524083716-78f416561547/go.mod h1:/kOrWrZB6sasLbEy2JIvr4arEzQTXBTZGb3Y96yWbHY=
github.com/go-gl/gl v0.0.0-20210426225639-a3bfa832c8aa h1:yiL6tST9ZuWBXiymIdM0j6yeLwMVGXDoybpXqnbJpCk=
github.com/go-gl/gl v0.0.0-20210426225639-a3bfa832c8aa/go.mod h1:wjpnOv6ONl2SuJSxqCPVaPZibGFdSci9HFocT9qtVYM=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210410170116-ea3d685f79fb h1:T6gaWBvRzJjuOrdCtg8fXXjKai2xSDqWTcKFUPuw8Tw=
Expand Down
11 changes: 11 additions & 0 deletions internal/driver/gomobile/driver.go
Expand Up @@ -28,6 +28,7 @@ import (
const (
tapMoveThreshold = 4.0 // how far can we move before it is a drag
tapSecondaryDelay = 300 * time.Millisecond // how long before secondary tap
backspaceDelay = 50 * time.Millisecond // how quickly can a user type backspace in succession
)

// Configuration is the system information about the current device
Expand All @@ -49,6 +50,8 @@ type mobileDriver struct {
animation *animation.Runner
currentSize size.Event

lastBackspace time.Time

theme fyne.ThemeVariant
onConfigChanged func(*Configuration)
painting bool
Expand Down Expand Up @@ -470,6 +473,14 @@ func (d *mobileDriver) typeDownCanvas(canvas *mobileCanvas, r rune, code key.Cod
r = runeToPrintable(r)
keyEvent := &fyne.KeyEvent{Name: keyName}

// If backspace was too quick, we received a real backspace followed by simulated backspace
if keyEvent.Name == fyne.KeyBackspace {
if time.Since(d.lastBackspace) < backspaceDelay {
return
}
d.lastBackspace = time.Now()
}

if canvas.Focused() != nil {
if keyName != "" {
canvas.Focused().TypedKey(keyEvent)
Expand Down
25 changes: 21 additions & 4 deletions vendor/github.com/fyne-io/mobile/app/GoNativeActivity.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Expand Up @@ -12,7 +12,7 @@ github.com/davecgh/go-spew/spew
github.com/fredbi/uri
# github.com/fsnotify/fsnotify v1.4.9
github.com/fsnotify/fsnotify
# github.com/fyne-io/mobile v0.1.3-0.20210510125822-9a3fcd853577
# github.com/fyne-io/mobile v0.1.3-0.20210524083716-78f416561547
github.com/fyne-io/mobile/app
github.com/fyne-io/mobile/app/internal/callfn
github.com/fyne-io/mobile/event/key
Expand Down

0 comments on commit dcfaf76

Please sign in to comment.