fix: mobile, cursor mode, don't reset canvas (#9843)
Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
		
							parent
							
								
									78088360ca
								
							
						
					
					
						commit
						faf97c770c
					
				@ -542,7 +542,9 @@ class _RemotePageState extends State<RemotePage> with WidgetsBindingObserver {
 | 
				
			|||||||
              right: 10,
 | 
					              right: 10,
 | 
				
			||||||
              child: QualityMonitor(gFFI.qualityMonitorModel),
 | 
					              child: QualityMonitor(gFFI.qualityMonitorModel),
 | 
				
			||||||
            ),
 | 
					            ),
 | 
				
			||||||
            KeyHelpTools(requestShow: (keyboardIsVisible || _showGestureHelp)),
 | 
					            KeyHelpTools(
 | 
				
			||||||
 | 
					                keyboardIsVisible: keyboardIsVisible,
 | 
				
			||||||
 | 
					                showGestureHelp: _showGestureHelp),
 | 
				
			||||||
            SizedBox(
 | 
					            SizedBox(
 | 
				
			||||||
              width: 0,
 | 
					              width: 0,
 | 
				
			||||||
              height: 0,
 | 
					              height: 0,
 | 
				
			||||||
@ -771,10 +773,14 @@ class _RemotePageState extends State<RemotePage> with WidgetsBindingObserver {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class KeyHelpTools extends StatefulWidget {
 | 
					class KeyHelpTools extends StatefulWidget {
 | 
				
			||||||
  /// need to show by external request, etc [keyboardIsVisible] or [changeTouchMode]
 | 
					  final bool keyboardIsVisible;
 | 
				
			||||||
  final bool requestShow;
 | 
					  final bool showGestureHelp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  KeyHelpTools({required this.requestShow});
 | 
					  /// need to show by external request, etc [keyboardIsVisible] or [changeTouchMode]
 | 
				
			||||||
 | 
					  bool get requestShow => keyboardIsVisible || showGestureHelp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  KeyHelpTools(
 | 
				
			||||||
 | 
					      {required this.keyboardIsVisible, required this.showGestureHelp});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @override
 | 
					  @override
 | 
				
			||||||
  State<KeyHelpTools> createState() => _KeyHelpToolsState();
 | 
					  State<KeyHelpTools> createState() => _KeyHelpToolsState();
 | 
				
			||||||
@ -819,7 +825,8 @@ class _KeyHelpToolsState extends State<KeyHelpTools> {
 | 
				
			|||||||
      final size = renderObject.size;
 | 
					      final size = renderObject.size;
 | 
				
			||||||
      Offset pos = renderObject.localToGlobal(Offset.zero);
 | 
					      Offset pos = renderObject.localToGlobal(Offset.zero);
 | 
				
			||||||
      gFFI.cursorModel.keyHelpToolsVisibilityChanged(
 | 
					      gFFI.cursorModel.keyHelpToolsVisibilityChanged(
 | 
				
			||||||
          Rect.fromLTWH(pos.dx, pos.dy, size.width, size.height));
 | 
					          Rect.fromLTWH(pos.dx, pos.dy, size.width, size.height),
 | 
				
			||||||
 | 
					          widget.keyboardIsVisible);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -831,7 +838,8 @@ class _KeyHelpToolsState extends State<KeyHelpTools> {
 | 
				
			|||||||
        inputModel.command;
 | 
					        inputModel.command;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!_pin && !hasModifierOn && !widget.requestShow) {
 | 
					    if (!_pin && !hasModifierOn && !widget.requestShow) {
 | 
				
			||||||
      gFFI.cursorModel.keyHelpToolsVisibilityChanged(null);
 | 
					      gFFI.cursorModel
 | 
				
			||||||
 | 
					          .keyHelpToolsVisibilityChanged(null, widget.keyboardIsVisible);
 | 
				
			||||||
      return Offstage();
 | 
					      return Offstage();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    final size = MediaQuery.of(context).size;
 | 
					    final size = MediaQuery.of(context).size;
 | 
				
			||||||
 | 
				
			|||||||
@ -1515,12 +1515,8 @@ class CanvasModel with ChangeNotifier {
 | 
				
			|||||||
    if (kIgnoreDpi && style == kRemoteViewStyleOriginal) {
 | 
					    if (kIgnoreDpi && style == kRemoteViewStyleOriginal) {
 | 
				
			||||||
      _scale = 1.0 / _devicePixelRatio;
 | 
					      _scale = 1.0 / _devicePixelRatio;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    _x = (size.width - displayWidth * _scale) / 2;
 | 
					    _resetCanvasOffset(displayWidth, displayHeight);
 | 
				
			||||||
    _y = (size.height - displayHeight * _scale) / 2;
 | 
					 | 
				
			||||||
    _imageOverflow.value = _x < 0 || y < 0;
 | 
					    _imageOverflow.value = _x < 0 || y < 0;
 | 
				
			||||||
    if (isMobile && style == kRemoteViewStyleOriginal) {
 | 
					 | 
				
			||||||
      _moveToCenterCursor();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if (notify) {
 | 
					    if (notify) {
 | 
				
			||||||
      notifyListeners();
 | 
					      notifyListeners();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -1530,6 +1526,14 @@ class CanvasModel with ChangeNotifier {
 | 
				
			|||||||
    tryUpdateScrollStyle(Duration.zero, style);
 | 
					    tryUpdateScrollStyle(Duration.zero, style);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _resetCanvasOffset(int displayWidth, int displayHeight) {
 | 
				
			||||||
 | 
					    _x = (size.width - displayWidth * _scale) / 2;
 | 
				
			||||||
 | 
					    _y = (size.height - displayHeight * _scale) / 2;
 | 
				
			||||||
 | 
					    if (isMobile && _lastViewStyle.style == kRemoteViewStyleOriginal) {
 | 
				
			||||||
 | 
					      _moveToCenterCursor();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  tryUpdateScrollStyle(Duration duration, String? style) async {
 | 
					  tryUpdateScrollStyle(Duration duration, String? style) async {
 | 
				
			||||||
    if (_scrollStyle != ScrollStyle.scrollbar) return;
 | 
					    if (_scrollStyle != ScrollStyle.scrollbar) return;
 | 
				
			||||||
    style ??= await bind.sessionGetViewStyle(sessionId: sessionId);
 | 
					    style ??= await bind.sessionGetViewStyle(sessionId: sessionId);
 | 
				
			||||||
@ -1640,8 +1644,7 @@ class CanvasModel with ChangeNotifier {
 | 
				
			|||||||
    if (isWebDesktop) {
 | 
					    if (isWebDesktop) {
 | 
				
			||||||
      updateViewStyle();
 | 
					      updateViewStyle();
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      _x = (size.width - getDisplayWidth() * _scale) / 2;
 | 
					      _resetCanvasOffset(getDisplayWidth(), getDisplayHeight());
 | 
				
			||||||
      _y = (size.height - getDisplayHeight() * _scale) / 2;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    notifyListeners();
 | 
					    notifyListeners();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@ -1677,10 +1680,7 @@ class CanvasModel with ChangeNotifier {
 | 
				
			|||||||
    if (kIgnoreDpi && _lastViewStyle.style == kRemoteViewStyleOriginal) {
 | 
					    if (kIgnoreDpi && _lastViewStyle.style == kRemoteViewStyleOriginal) {
 | 
				
			||||||
      _scale = 1.0 / _devicePixelRatio;
 | 
					      _scale = 1.0 / _devicePixelRatio;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    final displayWidth = getDisplayWidth();
 | 
					    _resetCanvasOffset(getDisplayWidth(), getDisplayHeight());
 | 
				
			||||||
    final displayHeight = getDisplayHeight();
 | 
					 | 
				
			||||||
    _x = (size.width - displayWidth * _scale) / 2;
 | 
					 | 
				
			||||||
    _y = (size.height - displayHeight * _scale) / 2;
 | 
					 | 
				
			||||||
    bind.sessionSetViewStyle(sessionId: sessionId, value: _lastViewStyle.style);
 | 
					    bind.sessionSetViewStyle(sessionId: sessionId, value: _lastViewStyle.style);
 | 
				
			||||||
    notifyListeners();
 | 
					    notifyListeners();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@ -1937,9 +1937,10 @@ class CursorModel with ChangeNotifier {
 | 
				
			|||||||
  // `lastIsBlocked` is only used in common/widgets/remote_input.dart -> _RawTouchGestureDetectorRegionState -> onDoubleTap()
 | 
					  // `lastIsBlocked` is only used in common/widgets/remote_input.dart -> _RawTouchGestureDetectorRegionState -> onDoubleTap()
 | 
				
			||||||
  // Because onDoubleTap() doesn't have the `event` parameter, we can't get the touch event's position.
 | 
					  // Because onDoubleTap() doesn't have the `event` parameter, we can't get the touch event's position.
 | 
				
			||||||
  bool _lastIsBlocked = false;
 | 
					  bool _lastIsBlocked = false;
 | 
				
			||||||
 | 
					  bool _lastKeyboardIsVisible = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  Rect? get keyHelpToolsRect => _keyHelpToolsRect;
 | 
					  Rect? get keyHelpToolsRect => _keyHelpToolsRect;
 | 
				
			||||||
  keyHelpToolsVisibilityChanged(Rect? r) {
 | 
					  keyHelpToolsVisibilityChanged(Rect? r, bool keyboardIsVisible) {
 | 
				
			||||||
    _keyHelpToolsRect = r;
 | 
					    _keyHelpToolsRect = r;
 | 
				
			||||||
    if (r == null) {
 | 
					    if (r == null) {
 | 
				
			||||||
      _lastIsBlocked = false;
 | 
					      _lastIsBlocked = false;
 | 
				
			||||||
@ -1949,11 +1950,10 @@ class CursorModel with ChangeNotifier {
 | 
				
			|||||||
      // `lastIsBlocked` will be set when the cursor is moving or touch somewhere else.
 | 
					      // `lastIsBlocked` will be set when the cursor is moving or touch somewhere else.
 | 
				
			||||||
      _lastIsBlocked = true;
 | 
					      _lastIsBlocked = true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (isMobile) {
 | 
					    if (isMobile && _lastKeyboardIsVisible != keyboardIsVisible) {
 | 
				
			||||||
      if (r != null || _lastIsBlocked) {
 | 
					 | 
				
			||||||
      parent.target?.canvasModel.mobileFocusCanvasCursor();
 | 
					      parent.target?.canvasModel.mobileFocusCanvasCursor();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    }
 | 
					    _lastKeyboardIsVisible = keyboardIsVisible;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  get lastIsBlocked => _lastIsBlocked;
 | 
					  get lastIsBlocked => _lastIsBlocked;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user