Merge pull request #6445 from fufesou/fix/mobile_soft_keyboard_focus

fix, mobile soft keyboard focus
This commit is contained in:
RustDesk 2023-11-17 23:09:55 +08:00 committed by GitHub
commit 35eaa94228
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 8 deletions

View File

@ -205,6 +205,12 @@ const kRemoteAudioDualWay = 'dual-way';
const kIgnoreDpi = true; const kIgnoreDpi = true;
// ================================ mobile ================================
// Magic numbers, maybe need to avoid it or use a better way to get them.
const kMobileDelaySoftKeyboard = Duration(milliseconds: 30);
const kMobileDelaySoftKeyboardFocus = Duration(milliseconds: 30);
/// Android constants /// Android constants
const kActionApplicationDetailsSettings = const kActionApplicationDetailsSettings =
"android.settings.APPLICATION_DETAILS_SETTINGS"; "android.settings.APPLICATION_DETAILS_SETTINGS";

View File

@ -115,6 +115,13 @@ class _RemotePageState extends State<RemotePage> {
gFFI.ffiModel.pi.version.isNotEmpty) { gFFI.ffiModel.pi.version.isNotEmpty) {
gFFI.invokeMethod("enable_soft_keyboard", false); gFFI.invokeMethod("enable_soft_keyboard", false);
} }
} else {
_timer?.cancel();
_timer = Timer(kMobileDelaySoftKeyboardFocus, () {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
overlays: SystemUiOverlay.values);
_mobileFocusNode.requestFocus();
});
} }
// update for Scaffold // update for Scaffold
setState(() {}); setState(() {});
@ -204,12 +211,12 @@ class _RemotePageState extends State<RemotePage> {
_value = initText; _value = initText;
setState(() => _showEdit = false); setState(() => _showEdit = false);
_timer?.cancel(); _timer?.cancel();
_timer = Timer(Duration(milliseconds: 30), () { _timer = Timer(kMobileDelaySoftKeyboard, () {
// show now, and sleep a while to requestFocus to // show now, and sleep a while to requestFocus to
// make sure edit ready, so that keyboard wont show/hide/show/hide happen // make sure edit ready, so that keyboard wont show/hide/show/hide happen
setState(() => _showEdit = true); setState(() => _showEdit = true);
_timer?.cancel(); _timer?.cancel();
_timer = Timer(Duration(milliseconds: 30), () { _timer = Timer(kMobileDelaySoftKeyboardFocus, () {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
overlays: SystemUiOverlay.values); overlays: SystemUiOverlay.values);
_mobileFocusNode.requestFocus(); _mobileFocusNode.requestFocus();
@ -448,11 +455,7 @@ class _RemotePageState extends State<RemotePage> {
height: 0, height: 0,
child: !_showEdit child: !_showEdit
? Container() ? Container()
// A container wrapper is needed here on some android devices for flutter 3.13.9, otherwise the focusNode will not work. : TextFormField(
// But for flutter 3.10.*, the container wrapper is not needed.
// It maybe the flutter compatibility issue.
: Container(
child: TextFormField(
textInputAction: TextInputAction.newline, textInputAction: TextInputAction.newline,
autocorrect: false, autocorrect: false,
enableSuggestions: false, enableSuggestions: false,
@ -463,7 +466,7 @@ class _RemotePageState extends State<RemotePage> {
// trick way to make backspace work always // trick way to make backspace work always
keyboardType: TextInputType.multiline, keyboardType: TextInputType.multiline,
onChanged: handleSoftKeyboardInput, onChanged: handleSoftKeyboardInput,
)), ),
), ),
]; ];
if (showCursorPaint) { if (showCursorPaint) {