Skip to content

Commit

Permalink
Merge pull request rustdesk#6445 from fufesou/fix/mobile_soft_keyboar…
Browse files Browse the repository at this point in the history
…d_focus

fix, mobile soft keyboard focus
  • Loading branch information
rustdesk authored Nov 17, 2023
2 parents 7960b2c + 38182ba commit 35eaa94
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
6 changes: 6 additions & 0 deletions flutter/lib/consts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ const kRemoteAudioDualWay = 'dual-way';

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

0 comments on commit 35eaa94

Please sign in to comment.