fix: mobile, soft keyboard (#9860)

Switching the input method, don't affect the canvas.

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou 2024-11-08 15:01:36 +08:00 committed by GitHub
parent a277b022ff
commit d3efcd4223
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 1 deletions

View File

@ -134,6 +134,13 @@ class _RemotePageState extends State<RemotePage> with WidgetsBindingObserver {
@override
void didChangeMetrics() {
// If the soft keyboard is visible and the canvas has been changed(panned or scaled)
// Don't try reset the view style and focus the cursor.
if (gFFI.cursorModel.lastKeyboardIsVisible &&
gFFI.canvasModel.isMobileCanvasChanged) {
return;
}
final newBottom = MediaQueryData.fromView(ui.window).viewInsets.bottom;
_timerDidChangeMetrics?.cancel();
_timerDidChangeMetrics = Timer(Duration(milliseconds: 100), () async {

View File

@ -1424,6 +1424,10 @@ class CanvasModel with ChangeNotifier {
Timer? _timerMobileFocusCanvasCursor;
// `isMobileCanvasChanged` is used to avoid canvas reset when changing the input method
// after showing the soft keyboard.
bool isMobileCanvasChanged = false;
final ScrollController _horizontal = ScrollController();
final ScrollController _vertical = ScrollController();
@ -1639,6 +1643,9 @@ class CanvasModel with ChangeNotifier {
panX(double dx) {
_x += dx;
if (isMobile) {
isMobileCanvasChanged = true;
}
notifyListeners();
}
@ -1653,6 +1660,9 @@ class CanvasModel with ChangeNotifier {
panY(double dy) {
_y += dy;
if (isMobile) {
isMobileCanvasChanged = true;
}
notifyListeners();
}
@ -1672,6 +1682,9 @@ class CanvasModel with ChangeNotifier {
// (focalPoint.dy - _y_1 - adjust) / s1 + displayOriginY = (focalPoint.dy - _y_2 - adjust) / s2 + displayOriginY
// _y_2 = focalPoint.dy - adjust - (focalPoint.dy - _y_1 - adjust) / s1 * s2
_y = focalPoint.dy - adjust - (focalPoint.dy - _y - adjust) / s * _scale;
if (isMobile) {
isMobileCanvasChanged = true;
}
notifyListeners();
}
@ -1941,6 +1954,8 @@ class CursorModel with ChangeNotifier {
bool _lastIsBlocked = false;
bool _lastKeyboardIsVisible = false;
bool get lastKeyboardIsVisible => _lastKeyboardIsVisible;
Rect? get keyHelpToolsRectToAdjustCanvas =>
_lastKeyboardIsVisible ? _keyHelpToolsRect : null;
keyHelpToolsVisibilityChanged(Rect? r, bool keyboardIsVisible) {
@ -1955,6 +1970,7 @@ class CursorModel with ChangeNotifier {
}
if (isMobile && _lastKeyboardIsVisible != keyboardIsVisible) {
parent.target?.canvasModel.mobileFocusCanvasCursor();
parent.target?.canvasModel.isMobileCanvasChanged = false;
}
_lastKeyboardIsVisible = keyboardIsVisible;
}