From 7a760edfe679356912e5cbf94c8915c3689c72b5 Mon Sep 17 00:00:00 2001 From: zjxi Date: Thu, 26 Sep 2024 21:09:21 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8Dflutterview=E4=B8=AD?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E5=AE=9E=E6=97=B6=E6=9B=B4=E6=96=B0=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E6=98=BE=E7=A4=BA=E5=A4=A7=E5=B0=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zjxi --- .../flutter/src/main/ets/view/FlutterView.ets | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterView.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterView.ets index 59038f9f33..54e84044d0 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterView.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterView.ets @@ -15,12 +15,11 @@ import FlutterEngine from '../embedding/engine/FlutterEngine'; import Log from '../util/Log'; import { DVModel, DVModelChildren, DVModelEvents, DVModelParameters } from './DynamicView/dynamicView'; -import display from '@ohos.display'; +import {display} from '@kit.ArkUI' import FlutterManager from '../embedding/ohos/FlutterManager'; import window from '@ohos.window'; import KeyboardManager from '../embedding/ohos/KeyboardManager'; import MouseCursorPlugin from '../plugin/mouse/MouseCursorPlugin'; -import Any from '../plugin/common/Any'; import Settings from '../embedding/ohos/Settings'; import ArrayList from '@ohos.util.ArrayList'; import { EmbeddingNodeController } from '../embedding/ohos/EmbeddingNodeController'; @@ -155,6 +154,19 @@ export class FlutterView { this.navigationAvoidArea = this.mainWindow?.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR); this.gestureAvoidArea = this.mainWindow?.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM_GESTURE); this.keyboardAvoidArea = this.mainWindow?.getWindowAvoidArea(window.AvoidAreaType.TYPE_KEYBOARD); + + //监听系统设置显示大小改变 + try { + display.on("change", ()=>{ + this.displayInfo = display.getDefaultDisplaySync(); + this.viewportMetrics.devicePixelRatio = this.displayInfo?.densityPixels; + this.viewportMetrics.physicalTouchSlop = 1.0 * this.displayInfo?.densityPixels; + Log.i(TAG, "Display Info: " + JSON.stringify(this.displayInfo)) + this.updateViewportMetrics() + }); + } catch (e) { + Log.e(TAG, "displayInfo error" + JSON.stringify(e)); + } } private windowSizeChangeCallback = (data: window.Size) => { @@ -391,6 +403,7 @@ export class FlutterView { private updateViewportMetrics() { if (this.isAttachedToFlutterEngine()) { + Log.i(TAG, 'updateViewportMetrics devicePixelRatio:' + this.viewportMetrics.devicePixelRatio) this?.flutterEngine?.getFlutterNapi()?.setViewportMetrics(this.viewportMetrics.devicePixelRatio, this.viewportMetrics.physicalWidth, this.viewportMetrics.physicalHeight, -- Gitee From 251ec5bdd6b737b50a8eccfffe748b039bb86f62 Mon Sep 17 00:00:00 2001 From: zjxi Date: Thu, 26 Sep 2024 21:58:29 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8Dflutterview=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E5=AE=9E=E6=97=B6=E6=9B=B4=E6=96=B0=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E5=A4=A7=E5=B0=8F=EF=BC=8C=E5=A2=9E=E5=8A=A0diplay.off?= =?UTF-8?q?=E6=B3=A8=E9=94=80=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zjxi --- .../flutter/src/main/ets/view/FlutterView.ets | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterView.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterView.ets index 54e84044d0..b93d423286 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterView.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterView.ets @@ -161,7 +161,7 @@ export class FlutterView { this.displayInfo = display.getDefaultDisplaySync(); this.viewportMetrics.devicePixelRatio = this.displayInfo?.densityPixels; this.viewportMetrics.physicalTouchSlop = 1.0 * this.displayInfo?.densityPixels; - Log.i(TAG, "Display Info: " + JSON.stringify(this.displayInfo)) + Log.i(TAG, "Display on: " + JSON.stringify(this.displayInfo)) this.updateViewportMetrics() }); } catch (e) { @@ -248,6 +248,18 @@ export class FlutterView { Log.e(TAG, "mainWindow off error: " + JSON.stringify(e)); } this.mainWindow = null; + + try { + display.off("change", ()=>{ + this.displayInfo = display.getDefaultDisplaySync(); + this.viewportMetrics.devicePixelRatio = this.displayInfo?.densityPixels; + this.viewportMetrics.physicalTouchSlop = 1.0 * this.displayInfo?.densityPixels; + Log.i(TAG, "Display Info: " + JSON.stringify(this.displayInfo)) + this.updateViewportMetrics() + }); + } catch (e) { + Log.e(TAG, "displayInfo off error" + JSON.stringify(e)); + } } attachToFlutterEngine(flutterEngine: FlutterEngine): void { -- Gitee