Skip to content

Commit

Permalink
Bug fix: keyboard doesn't appear when detecting volume hardware buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
giantsol committed Oct 2, 2019
1 parent 2e98611 commit 3cc3737
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Expand Up @@ -125,7 +125,7 @@ object HardwareButtonsWatcherManager {
keyWatcher = KeyWatcher(application.applicationContext, callback = {
dispatchVolumeButtonEvent(it)
currentActivity?.dispatchKeyEvent(it)
})
}, findFocusCallback = { currentActivity?.window?.decorView?.rootView })
addOverlayWindowView(application, keyWatcher!!)
}
}
Expand Down Expand Up @@ -200,12 +200,19 @@ private class KeyWatcher @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
private val callback: ((event: KeyEvent) -> Unit)? = null
private val callback: ((event: KeyEvent) -> Unit)? = null,
private val findFocusCallback: (() -> View?)? = null
) : View(context, attrs, defStyleAttr) {
override fun dispatchKeyEvent(event: KeyEvent): Boolean {
callback?.invoke(event)
return false
}

// without this, flutter app will not be able to show keyboard
// because KeyWatcher view window takes all the focus..
override fun findFocus(): View? {
return findFocusCallback?.invoke()
}
}

private class HomeButtonWatcher(private val callback: () -> Unit): BroadcastReceiver() {
Expand Down
15 changes: 14 additions & 1 deletion example/lib/main.dart
Expand Up @@ -47,7 +47,20 @@ class _MyAppState extends State<MyApp> {
title: const Text('Plugin example app'),
),
body: Center(
child: Text('Value: $_latestHardwareButtonEvent\n'),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text('Value: $_latestHardwareButtonEvent\n'),
SizedBox(
width: 300,
child: TextField(
decoration: InputDecoration(
hintText: '안드 테스트 용도입니다 ㅠ.ㅠ',
),
),
)
],
),
),
),
);
Expand Down

0 comments on commit 3cc3737

Please sign in to comment.