From 5883599447ad455f3b474c5e7913e6361db800f8 Mon Sep 17 00:00:00 2001 From: zmf <279822581@qq.com> Date: Thu, 21 Mar 2024 22:36:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Ddebug=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E4=B8=8B=E9=97=AA=E7=8E=B0=E9=BB=91=E5=B1=8F=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zmf <279822581@qq.com> --- .../main/ets/component/XComponentStruct.ets | 30 ++++++++++++-- .../main/ets/embedding/ohos/FlutterPage.ets | 39 ++++++++++++++----- 2 files changed, 55 insertions(+), 14 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/component/XComponentStruct.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/component/XComponentStruct.ets index 71c2a68e10..322ffd13a8 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/component/XComponentStruct.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/component/XComponentStruct.ets @@ -13,22 +13,44 @@ * limitations under the License. */ import Any from '../plugin/common/Any'; +import ApplicationInfoLoader from '../embedding/engine/loader/ApplicationInfoLoader'; import { BuilderParams, DVModelParameters } from '../view/DynamicView/dynamicView'; @Component struct XComponentStruct { private context: Any; + private applicationInfo = ApplicationInfoLoader.load(getContext()); dvModelParams: DVModelParameters = new DVModelParameters(); build() { - XComponent({ id: (this.dvModelParams as Record)["xComponentId"], type: XComponentType.SURFACE, libraryname: 'flutter'}) - .onLoad((context) => { - this.context = context; + // todo OS解决默认背景色后可以移除冗余重复代码,仅保留差异的backgroundColor属性条件配置 + if (this.applicationInfo.isDebugMode) { + XComponent({ + id: (this.dvModelParams as Record)["xComponentId"], + type: XComponentType.SURFACE, + libraryname: 'flutter' }) - .onDestroy(() => { + .onLoad((context) => { + this.context = context; + }) + .onDestroy(() => { + }) + .backgroundColor(Color.White) + } else { + XComponent({ + id: (this.dvModelParams as Record)["xComponentId"], + type: XComponentType.SURFACE, + libraryname: 'flutter' }) + .onLoad((context) => { + this.context = context; + }) + .onDestroy(() => { + }) + } } + } @Builder export function BuildXComponentStruct(buildParams: BuilderParams) { diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets index 84081fac92..bf2f16267b 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets @@ -26,6 +26,8 @@ import { } from '../../view/DynamicView/dynamicView'; import { createDVModelFromJson } from '../../view/DynamicView/dynamicViewJson'; import { FlutterView } from '../../view/FlutterView'; +import ApplicationInfoLoader from '../engine/loader/ApplicationInfoLoader'; +import FlutterApplicationInfo from '../engine/loader/FlutterApplicationInfo'; import KeyEventChannel from '../engine/systemchannels/KeyEventChannel'; import FlutterManager from './FlutterManager'; @@ -40,6 +42,7 @@ export struct FlutterPage { @Prop viewId: string = "" @Prop xComponentType: XComponentType = XComponentType.SURFACE private flutterView?: FlutterView | null + private applicationInfo = ApplicationInfoLoader.load(getContext()); aboutToAppear() { this.flutterView = FlutterManager.getInstance().getFlutterView(this.viewId); @@ -48,16 +51,32 @@ export struct FlutterPage { build() { Stack() { - XComponent({ id: this.viewId, type: this.xComponentType, libraryname: 'flutter' }) - .focusable(true) - .onLoad((context) => { - this.flutterView?.onSurfaceCreated() - Log.d(TAG, "XComponent onLoad "); - }) - .onDestroy(() => { - Log.d(TAG, "XComponent onDestroy "); - this.flutterView?.onSurfaceDestroyed() - }) + // todo OS解决默认背景色后可以移除冗余重复代码,仅保留差异的backgroundColor属性条件配置 + if (this.applicationInfo.isDebugMode) { + XComponent({ id: this.viewId, type: this.xComponentType, libraryname: 'flutter' }) + .focusable(true) + .onLoad((context) => { + this.flutterView?.onSurfaceCreated() + Log.d(TAG, "XComponent onLoad "); + }) + .onDestroy(() => { + Log.d(TAG, "XComponent onDestroy "); + this.flutterView?.onSurfaceDestroyed() + }) + .backgroundColor(Color.White) + } else { + XComponent({ id: this.viewId, type: this.xComponentType, libraryname: 'flutter' }) + .focusable(true) + .onLoad((context) => { + this.flutterView?.onSurfaceCreated() + Log.d(TAG, "XComponent onLoad "); + }) + .onDestroy(() => { + Log.d(TAG, "XComponent onDestroy "); + this.flutterView?.onSurfaceDestroyed() + }) + } + ForEach(this.rootDvModel!!, (child:Any) =>{ DynamicView({ model: child as DVModel, -- Gitee