Refact/mobile remove adjust 4 soft keyabord (#9787)

* refact: remove adjust for soft keyboard

Signed-off-by: fufesou <linlong1266@gmail.com>

* mobile, do not set the view style after scale end

Signed-off-by: fufesou <linlong1266@gmail.com>

---------

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou 2024-10-31 10:11:00 +08:00 committed by GitHub
parent 0b8cccd8be
commit 697dd87383
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 29 additions and 33 deletions

View file

@ -37,13 +37,15 @@ class RemotePage extends StatefulWidget {
State<RemotePage> createState() => _RemotePageState(id);
}
class _RemotePageState extends State<RemotePage> {
class _RemotePageState extends State<RemotePage> with WidgetsBindingObserver {
Timer? _timer;
bool _showBar = !isWebDesktop;
bool _showGestureHelp = false;
String _value = '';
Orientation? _currentOrientation;
Timer? _timerDidChangeMetrics;
final _blockableOverlayState = BlockableOverlayState();
final keyboardVisibilityController = KeyboardVisibilityController();
@ -100,10 +102,12 @@ class _RemotePageState extends State<RemotePage> {
if (isAndroid) {
_textController.addListener(textAndroidListener);
}
WidgetsBinding.instance.addObserver(this);
}
@override
Future<void> dispose() async {
WidgetsBinding.instance.removeObserver(this);
// https://github.com/flutter/flutter/issues/64935
super.dispose();
gFFI.dialogManager.hideMobileActionsOverlay(store: false);
@ -115,6 +119,7 @@ class _RemotePageState extends State<RemotePage> {
_physicalFocusNode.dispose();
await gFFI.close();
_timer?.cancel();
_timerDidChangeMetrics?.cancel();
gFFI.dialogManager.dismissAll();
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
overlays: SystemUiOverlay.values);
@ -132,6 +137,14 @@ class _RemotePageState extends State<RemotePage> {
}
}
@override
void didChangeMetrics() {
_timerDidChangeMetrics?.cancel();
_timerDidChangeMetrics = Timer(Duration(milliseconds: 100), () {
gFFI.canvasModel.updateViewStyle(refreshMousePos: false);
});
}
// This listener is used to handle the composing region changes for Android soft keyboard input.
void textAndroidListener() {
if (_lastComposingChangeValid) {
@ -968,11 +981,9 @@ class ImagePaint extends StatelessWidget {
Widget build(BuildContext context) {
final m = Provider.of<ImageModel>(context);
final c = Provider.of<CanvasModel>(context);
final adjust = gFFI.cursorModel.adjustForKeyboard();
var s = c.scale;
return CustomPaint(
painter: ImagePainter(
image: m.image, x: c.x / s, y: (c.y - adjust) / s, scale: s),
painter: ImagePainter(image: m.image, x: c.x / s, y: c.y / s, scale: s),
);
}
}
@ -986,7 +997,6 @@ class CursorPaint extends StatelessWidget {
final m = Provider.of<CursorModel>(context);
final c = Provider.of<CanvasModel>(context);
final ffiModel = Provider.of<FfiModel>(context);
final adjust = gFFI.cursorModel.adjustForKeyboard();
final s = c.scale;
double hotx = m.hotx;
double hoty = m.hoty;
@ -1022,7 +1032,7 @@ class CursorPaint extends StatelessWidget {
painter: ImagePainter(
image: image,
x: (m.x - hotx) * factor + c.x / s2,
y: (m.y - hoty) * factor + (c.y - adjust) / s2,
y: (m.y - hoty) * factor + c.y / s2,
scale: s2),
);
}