From 26bbd5028f0a2fc217661f5de7880ea461abce57 Mon Sep 17 00:00:00 2001 From: 18719058668 <718092089@qq.com> Date: Fri, 10 May 2024 19:24:43 +0800 Subject: [PATCH 1/8] new platformview create Signed-off-by: 18719058668 <718092089@qq.com> --- .../ets/embedding/engine/FlutterEngine.ets | 2 +- .../ohos/EmbeddingNodeController.ets | 130 +++++++++ .../main/ets/embedding/ohos/FlutterPage.ets | 35 ++- .../main/ets/plugin/platform/PlatformView.ets | 9 +- .../platform/PlatformViewsController.ets | 258 ++++++++---------- .../ets/plugin/platform/RawPointerCoord.ets | 33 +++ .../flutter/src/main/ets/view/FlutterView.ets | 43 +++ 7 files changed, 356 insertions(+), 154 deletions(-) create mode 100644 shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/EmbeddingNodeController.ets create mode 100644 shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/RawPointerCoord.ets diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterEngine.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterEngine.ets index f6950fde1e..ad6757c2fb 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterEngine.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterEngine.ets @@ -102,7 +102,7 @@ export default class FlutterEngine implements EngineLifecycleListener{ platformViewsController = new PlatformViewsController(); } this.platformViewsController = platformViewsController; - this.platformViewsController.attach(context, null, this.dartExecutor); + this.platformViewsController.attach(context, this.renderer, this.dartExecutor); } async init(context: common.Context, dartVmArgs: Array | null, waitForRestorationData: boolean) { diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/EmbeddingNodeController.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/EmbeddingNodeController.ets new file mode 100644 index 0000000000..cd9671d1fb --- /dev/null +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/EmbeddingNodeController.ets @@ -0,0 +1,130 @@ +/* +* Copyright (c) 2024 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +import { BuilderNode, FrameNode, NodeController, NodeRenderType } from '@kit.ArkUI'; +import Any from '../../plugin/common/Any'; +import PlatformView, { Params } from '../../plugin/platform/PlatformView'; +import { DVModel, DVModelChildren, DynamicView } from '../../view/DynamicView/dynamicView'; + + +declare class nodeControllerParams { + surfaceId : string + type : string + renderType : NodeRenderType + embedId : string + width : number + height : number +} + +@Component +struct ButtonComponent { + @Prop params: Params + @State bkColor: Color = Color.Red + + build() { + Column() { + Button("test button") + .border({ width: 2, color: Color.Red}) + .backgroundColor(this.bkColor) + } + .width(this.params.width) + .height(this.params.height) + } +} + +@Builder +function ButtonBuilder(params: Params) { + ButtonComponent({ params: params }) + .backgroundColor(Color.Green) +} + + +export class EmbeddingNodeController extends NodeController { + private rootNode: BuilderNode<[Params]> | undefined | null = null; + private wrappedBuilder: WrappedBuilder<[Params]> | null = null; + private platformView: PlatformView | undefined = undefined; + private embedId_ : string = ""; + private surfaceId_ : string = ""; + private renderType_ :NodeRenderType = NodeRenderType.RENDER_TYPE_DISPLAY; + private width_ : number = 0; + private height_ : number = 0; + private type_ : string = ""; + private isDestroy_ : boolean = false; + + setRenderOption(platformView: PlatformView, surfaceId: string, renderType: NodeRenderType, width: number, height: number) { + if (platformView == undefined) { + console.log("nodeController platformView undefined") + } else { + this.wrappedBuilder = platformView.getView(); + } + + this.platformView = platformView; + this.surfaceId_ = surfaceId; + this.renderType_ = renderType; + this.width_ = width; + this.height_ = height; + } + makeNode(uiContext: UIContext): FrameNode | null{ + this.rootNode = new BuilderNode(uiContext, { surfaceId: this.surfaceId_, type: this.renderType_}); + if (this.wrappedBuilder == null) { + console.log("nodeController makeNode 1") + this.rootNode.build(wrapBuilder(ButtonBuilder), {width : this.width_, height : this.height_}); + } else { + console.log("nodeController makeNode 2") + this.rootNode.build(this.wrappedBuilder, {width : this.width_, height : this.height_, platformView: this.platformView}); + } + return this.rootNode.getFrameNode(); + } + + setBuilderNode(rootNode: BuilderNode | null): void{ + this.rootNode = rootNode; + } + + getBuilderNode(): BuilderNode<[Params]> | undefined | null{ + return this.rootNode; + } + + updateNode(arg: Object): void { + this.rootNode?.update(arg); + } + getEmbedId() : string { + return this.embedId_; + } + + setDestroy(isDestroy : boolean) : void { + this.isDestroy_ = isDestroy; + if (this.isDestroy_) { + this.rootNode = null; + } + } + + postEvent(event: TouchEvent | undefined) : boolean { + if (event != undefined) { + let changedTouchLen = event.changedTouches.length; + for (let i = 0; i< changedTouchLen; i++) { + event.changedTouches[i].displayX = vp2px(event.changedTouches[i].displayX); + event.changedTouches[i].displayY = vp2px(event.changedTouches[i].displayY); + event.changedTouches[i].windowX = vp2px(event.changedTouches[i].windowX); + event.changedTouches[i].windowY = vp2px(event.changedTouches[i].windowY); + event.changedTouches[i].screenX = vp2px(event.changedTouches[i].screenX); + event.changedTouches[i].screenY = vp2px(event.changedTouches[i].screenY); + event.changedTouches[i].x = vp2px(event.changedTouches[i].x); + event.changedTouches[i].y = vp2px(event.changedTouches[i].y); + } + return this.rootNode?.postTouchEvent(event) as boolean + } else { + return false; + } + } +} \ No newline at end of file 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 c14e38b02f..0644802c03 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 @@ -16,7 +16,9 @@ import Any from '../../plugin/common/Any'; import Log from '../../util/Log'; import { DVModel, DVModelChildren, DynamicView } from '../../view/DynamicView/dynamicView'; import { FlutterView } from '../../view/FlutterView'; +import { EmbeddingNodeController } from './EmbeddingNodeController'; import FlutterManager from './FlutterManager'; +import { NodeRenderType } from '@ohos.arkui.node'; const TAG = "FlutterPage"; @@ -34,10 +36,11 @@ export struct FlutterPage { @State showSplashScreen: boolean = true; private flutterView?: FlutterView | null - + private nodeController: EmbeddingNodeController | undefined = undefined aboutToAppear() { this.flutterView = FlutterManager.getInstance().getFlutterView(this.viewId); - this.rootDvModel = this.flutterView!!.getDVModel().children + this.rootDvModel = this.flutterView!!.getDVModel().children; + this.nodeController = this.flutterView!!.getEmbeddingNodeController(); this.flutterView?.addFirstFrameListener(this) } @@ -47,10 +50,32 @@ export struct FlutterPage { onFirstFrame() { this.showSplashScreen = false; + if (this.flutterView != null) { + let surfaceId: string = this.flutterView?.getSurfaceId() + Log.d(TAG, "nodeController onLoad surfaceId:" + surfaceId); + this.nodeController!!.setRenderOption(this.flutterView?.getPlatformView()!, surfaceId, NodeRenderType.RENDER_TYPE_TEXTURE, 300, 500); + Log.d(TAG, "nodeController rebuild"); + this.nodeController!!.rebuild(); + } } build() { Stack() { + NodeContainer(this.nodeController) + .width('100%') + .height('50%') + .onAppear(() => { + console.log("nodeController nodeContainer appear") + sleep(200); + if (this.flutterView != null) { + let surfaceId: string = this.flutterView?.getSurfaceId() + Log.d(TAG, "nodeController onLoad surfaceId:" + surfaceId); + this.nodeController!!.setRenderOption(this.flutterView?.getPlatformView()!, surfaceId, NodeRenderType.RENDER_TYPE_TEXTURE, 300, 500); + Log.d(TAG, "nodeController rebuild"); + this.nodeController!!.rebuild(); + } + }) + XComponent({ id: this.viewId, type: this.xComponentType, libraryname: 'flutter' }) .focusable(true) .focusOnTouch(true) @@ -88,3 +113,9 @@ export struct FlutterPage { }) } } + +function sleep(ms: number): Promise { + return new Promise( + (resolve) => setTimeout(resolve, ms) + ) +} diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformView.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformView.ets index ddf5f59a71..9a86013708 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformView.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformView.ets @@ -15,11 +15,16 @@ import { DVModel, DynamicView } from '../../view/DynamicView/dynamicView' +export declare class Params { + width : number + height : number + platformView : PlatformView +} + /** A handle to an DynamicView to be embedded in the Flutter hierarchy. */ export default abstract class PlatformView { /** Returns the DynamicView to be embedded in the Flutter hierarchy. */ - abstract getView(): DVModel; - + abstract getView(): WrappedBuilder<[Params]>; /** * Called by the {@link io.flutter.embedding.engine.FlutterEngine} that owns this {@code * PlatformView} when the DynamicView responsible for rendering a Flutter UI is diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets index 82c87cd521..0ad10724cc 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets @@ -20,7 +20,7 @@ import PlatformViewsChannel, { PlatformViewResizeRequest, PlatformViewsHandler, PlatformViewTouch, PlatformViewBufferSize } from '../../../ets/embedding/engine/systemchannels/PlatformViewsChannel'; -import PlatformView from './PlatformView'; +import PlatformView, { Params } from './PlatformView'; import { DVModel, DVModelContainer, DVModelParameters, DynamicView } from '../../view/DynamicView/dynamicView'; import display from '@ohos.display'; import { FlutterView } from '../../view/FlutterView'; @@ -42,9 +42,11 @@ import OhosTouchProcessor from '../../embedding/ohos/OhosTouchProcessor' import PlatformViewFactory from './PlatformViewFactory' import { ByteBuffer } from '../../util/ByteBuffer'; import Any from '../common/Any'; +import { RawPointerCoords } from './RawPointerCoord'; +import { ArrayList } from '@kit.ArkTS'; const TAG = "PlatformViewsController" - +let tsp: number = 52086377781000 export default class PlatformViewsController implements PlatformViewsAccessibilityDelegate, PlatformViewsHandler { private registry: PlatformViewRegistryImpl; private context: Context | null = null; @@ -57,6 +59,7 @@ export default class PlatformViewsController implements PlatformViewsAccessibili private usesSoftwareRendering: boolean = false; private platformViews: Map; + private viewIdWithTextureId: Map; private overlayLayerViews: Map; private viewWrappers: Map; private currentFrameUsedOverlayLayerIds: HashSet; @@ -71,6 +74,7 @@ export default class PlatformViewsController implements PlatformViewsAccessibili this.currentFrameUsedPlatformViewIds = new HashSet(); this.viewWrappers = new Map(); this.platformViews = new Map(); + this.viewIdWithTextureId = new Map(); this.platformViewParent = new Map(); } @@ -107,6 +111,11 @@ export default class PlatformViewsController implements PlatformViewsAccessibili return; } this.platformViews.delete(viewId); + let textureId = this.viewIdWithTextureId.get(viewId); + + if (textureId != undefined) { + this.textureRegistry!.unregisterTexture(textureId); + } try { platformView.dispose(); @@ -114,21 +123,7 @@ export default class PlatformViewsController implements PlatformViewsAccessibili Log.e(TAG, "Disposing platform view threw an exception", err); } - let viewWrapper: PlatformViewWrapper | null = this.viewWrappers.get(viewId) || null; - if (viewWrapper != null) { - let children = viewWrapper.getDvModel().children; - if (this.flutterView) { - let index = this.flutterView.getDVModel().children.indexOf(viewWrapper.getDvModel()); - children.splice(0, children.length); - this.flutterView.getDVModel().children.splice(index, 1); - } - this.viewWrappers.delete(viewId); - } - let parentView: FlutterMutatorView | null = this.platformViewParent.get(viewId) || null; - if (parentView != null) { - this.platformViewParent.delete(viewId); - } } setParams: (params: DVModelParameters, key: string, element: Any ) => void = (params: DVModelParameters, key: string, element: Any): void => { @@ -141,40 +136,10 @@ export default class PlatformViewsController implements PlatformViewsAccessibili let physicalHeight: number = this.toPhysicalPixels(request.newLogicalHeight); let viewId: number = request.viewId; Log.i(TAG, `Resize viewId ${viewId}, pw:${physicalWidth}, ph:${physicalHeight},lw:${request.newLogicalWidth}, lh:${request.newLogicalHeight}`); + this.flutterView!.getPlatformViewSize().width = physicalWidth; + this.flutterView!.getPlatformViewSize().height = physicalHeight; + - let platformView: PlatformView | null = this.platformViews.get(viewId) || null; - let viewWrapper: PlatformViewWrapper | null = this.viewWrappers.get(viewId) || null; - if (platformView == null || viewWrapper == null) { - Log.e(TAG, "Resizing unknown platform view with id: " + viewId); - return; - } - - let viewWrapperLayoutParams: DVModelParameters | undefined = viewWrapper.getDvModel()?.getLayoutParams(); - if (physicalWidth && viewWrapperLayoutParams) { - this.setParams(viewWrapperLayoutParams, "width", physicalWidth); - // viewWrapperLayoutParams.width = physicalWidth; - } - - if (physicalHeight && viewWrapperLayoutParams) { - this.setParams(viewWrapperLayoutParams, "height", physicalHeight); - // viewWrapperLayoutParams.height = physicalHeight; - } - - let embeddedView: DVModel = platformView.getView(); - if (embeddedView != null) { - let embeddedViewLayoutParams = embeddedView.getLayoutParams(); - if (physicalWidth) { - this.setParams(embeddedViewLayoutParams, "width", physicalWidth); - // embeddedViewLayoutParams.width = physicalWidth; - } - - if (physicalHeight) { - this.setParams(embeddedViewLayoutParams, "height", physicalHeight); - // embeddedViewLayoutParams.height = physicalHeight; - } - } - - onComplete.run(new PlatformViewBufferSize(request.newLogicalWidth, request.newLogicalHeight)); } offset(viewId: number, top: number, left: number): void { @@ -194,42 +159,91 @@ export default class PlatformViewsController implements PlatformViewsAccessibili } onTouch(touch: PlatformViewTouch): void { - let viewId: number = touch.viewId; - let density: number = display.getDefaultDisplaySync().densityDPI; - - let platformView: PlatformView | null = this.platformViews.get(viewId) ?? null; - if (platformView == null) { - Log.e(TAG, "Sending touch to an unknown platform view with id: " + viewId); - return; - } - let dvModel: DVModel = platformView.getView(); - if (dvModel == null) { - Log.e(TAG, "Sending touch to a null dv model with id: " + viewId); - } - Log.e(TAG, "Sending touch to a dv model with id: " + viewId.toString()); - sendEventByKey(viewId.toString(), 10, ""); + console.log("nodeController onTouch:") + let xx = 0; + let yy = 0; + let rawPointerCoords1: Array = touch.rawPointerCoords as Array ; + let length = rawPointerCoords1.length + rawPointerCoords1.forEach((item: ESObject) => { + let rawPoints: ArrayList = item as ArrayList; + let length2 = rawPoints.length + xx = rawPoints[7]; + yy = rawPoints[8]; + console.log("nodeController onTouch rawPoints.x :" + rawPoints[7]) + console.log("nodeController onTouch rawPoints.y :" + rawPoints[8]) + }) + + + + let touches1: TouchObject = { + type: touch.action, + id: 0, + displayX: xx, + displayY: yy, + windowX: xx, + windowY: yy, + screenX: xx, + screenY: yy, + x: xx, + y: yy, + } + + + let changedTouches1: TouchObject = { + type: touch.action, + id: 0, + displayX: xx, + displayY: yy, + windowX: xx, + windowY: yy, + screenX: xx, + screenY: yy, + x: xx, + y: yy, + } + + + tsp = tsp + 10000; + let touchEvent1: TouchEvent = { + type: touch.action, + source: 2, + sourceTool: 1, + pressure: 1, + timestamp: tsp, + touches: [touches1], + changedTouches: [changedTouches1], + tiltX: 0, + tiltY: 0, + stopPropagation: () => { + }, + getHistoricalPoints: () => { + return []; + }, + target: { + area: { + width: 1, + height: 1, + position: { + x: 1, + y: 1 + }, + globalPosition: { + x: 1, + y: 1 + } + } + }, + } + + console.log("nodeController onTouch type " + touch.action) + console.log("nodeController onTouch timestamp " + tsp) + if (this.flutterView == null) { + console.log("nodeController flutterView == null") + } + this.flutterView?.getEmbeddingNodeController().postEvent(touchEvent1) } setDirection(viewId: number, direction: number): void { - if (!this.validateDirection(direction)) { - throw new Error("Trying to set unknown direction value: " - + direction - + "(view id: " - + viewId - + ")"); - } - - const platformView = this.platformViews.get(viewId); - if (platformView == null) { - Log.e(TAG, "Setting direction to an unknown view with id: " + viewId); - return; - } - const embeddedView = platformView.getView(); - if (embeddedView == null) { - Log.e(TAG, "Setting direction to a null view with id: " + viewId); - return; - } - this.setParams(embeddedView.params, "direction", direction); // embeddedView.params.direction = direction; } @@ -258,15 +272,10 @@ export default class PlatformViewsController implements PlatformViewsAccessibili Log.i(TAG, "Enter createForTextureLayer"); this.ensureValidRequest(request); - let viewId: number = request.viewId; - if (this.viewWrappers.get(request.viewId) != null) { - throw new Error( - "Trying to create an already created platform view, view id: " + viewId); - } - let platformView: PlatformView = this.createPlatformView(request, true); - let dynamicView: DVModel = platformView.getView(); - return this.configureForTextureLayerComposition(platformView, request); + let textureId = this.configureForTextureLayerComposition(platformView, request); + this.viewIdWithTextureId.set(request.viewId, textureId); + return textureId; } private ensureValidRequest(request: PlatformViewCreationRequest): void { @@ -297,13 +306,11 @@ export default class PlatformViewsController implements PlatformViewsAccessibili } let platformView = viewFactory.create(this.context, request.viewId, createParams); - let embeddedView: DVModel = platformView.getView(); + let embeddedView: WrappedBuilder<[Params]> = platformView.getView(); if (embeddedView == null) { throw new Error("PlatformView#getView() returned null, but an dynamic view reference was expected."); } - this.setParams(embeddedView.params, "direction", request.direction); - // embeddedView.params.direction = request.direction; this.platformViews.set(request.viewId, platformView); return platformView; @@ -317,43 +324,18 @@ export default class PlatformViewsController implements PlatformViewsAccessibili private configureForTextureLayerComposition(platformView: PlatformView, request: PlatformViewCreationRequest): number { Log.i(TAG, "Hosting view in view hierarchy for platform view: " + request.viewId); - let viewWrapper: PlatformViewWrapper = new PlatformViewWrapper(); + // let viewWrapper: PlatformViewWrapper = new PlatformViewWrapper(); let textureId: number = 0; - - let physicalTop: number = this.toPhysicalPixels(request.logicalTop); - let physicalLeft: number = this.toPhysicalPixels(request.logicalLeft); - - Log.i(TAG, `View pW:${request.logicalWidth}, pH:${request.logicalHeight}, pT:${physicalTop}, pL:${physicalLeft}`); - - let param: DVModelParameters = new DVModelParameters(); - - this.setParams(param, "marginLeft", physicalLeft); - this.setParams(param, "marginTop", physicalTop); - // param.marginLeft = physicalLeft; - // param.marginTop = physicalTop; - - let model = platformView.getView(); - if (request.logicalWidth != null) { - let physicalWidth: number = this.toPhysicalPixels(request.logicalWidth); - this.setParams(model.params, "width", physicalWidth); - this.setParams(param, "width", physicalWidth); - // model.params.width = physicalWidth; - // param.width = physicalWidth; + if (this.textureRegistry != null) { + textureId = this.textureRegistry!.getTextureId(); + let surfaceId: string = this.textureRegistry!.registerTexture(textureId).getSurfaceId().toString(); + Log.i(TAG, "nodeController getSurfaceId: " + surfaceId); + this.flutterView!.setSurfaceId(surfaceId); } - if (request.logicalHeight != null) { - let physicalHeight: number = this.toPhysicalPixels(request.logicalHeight); - this.setParams(model.params, "height", physicalHeight); - this.setParams(param, "height", physicalHeight); - // model.params.height = physicalHeight; - // param.height = physicalHeight; - } - - viewWrapper.setLayoutParams(param); - viewWrapper.addDvModel(model); - - this.flutterView?.getDVModel().children.push(viewWrapper.getDvModel()!); - this.viewWrappers.set(request.viewId, viewWrapper); + let wrappedBuilder: WrappedBuilder<[Params]> = platformView.getView(); + this.flutterView?.setWrappedBuilder(wrappedBuilder); + this.flutterView?.setPlatformView(platformView); Log.i(TAG, "Create platform view success"); return textureId; @@ -454,28 +436,6 @@ export default class PlatformViewsController implements PlatformViewsAccessibili private initializeRootImageViewIfNeeded(): void { } - initializePlatformViewIfNeeded(viewId: number): void { - let platformView: PlatformView = this.platformViews[viewId]; - if (platformView == null) { - throw new Error("Platform view hasn't been initialized from the platform view channel."); - } - if (this.platformViewParent[viewId] == null) { - return; - } - let dvModel: DVModel = platformView.getView(); - if (dvModel == null) { - throw new Error("PlatformView#getView() returned null, but an ohos dv model reference was expected."); - } - let parentView: FlutterMutatorView = new FlutterMutatorView(); - parentView.setOnDescendantFocusChangeListener(() => { - this.platformViewsChannel?.invokeViewFocused(viewId); - }, () => { - if (this.textInputPlugin != null) { - this.textInputPlugin.clearTextInputClient(); - } - }); - } - public onDisplayOverlaySurface(id: number, x: number, y: number, width: number, height: number): void { } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/RawPointerCoord.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/RawPointerCoord.ets new file mode 100644 index 0000000000..ad28649e47 --- /dev/null +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/RawPointerCoord.ets @@ -0,0 +1,33 @@ +export class RawPointerCoords { + private orientation: number = 0; + private pressure: number = 0; + private size: number = 0; + private toolMajor: number = 0; + private toolMinor: number = 0; + private touchMajor: number = 0; + private touchMinor: number = 0; + private x: number = 0; + private y: number = 0; + + constructor(orientation: number, pressure: number, size: number, toolMajor: number, toolMinor: number, + touchMajor: number, touchMinor: number, x: number, y: number) { + this.orientation = orientation; + this.pressure = pressure; + this.size = size; + this.toolMajor = toolMajor; + this.toolMinor = toolMinor; + this.touchMajor = touchMajor; + this.touchMinor = touchMinor; + this.x = x; + this.y = y; + } + + getX(): number { + return this.x; + } + + getY(): number { + return this.y; + } + +} \ No newline at end of file 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 d092c6c5d3..5fb6ef08fd 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 @@ -23,6 +23,8 @@ 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'; +import PlatformView, { Params } from '../plugin/platform/PlatformView'; const TAG = "FlutterView"; @@ -45,10 +47,16 @@ class ViewportMetrics { physicalTouchSlop = -1; } +export class PlatformViewSize { + width: number = 0; + height: number = 0; +} export class FlutterView { private flutterEngine: FlutterEngine | null = null private id: string = "" private dVModel: DVModel = new DVModel("Stack", new DVModelParameters(), new DVModelEvents(), new DVModelChildren(), null); + private wrapBuilder: WrappedBuilder<[Params]> | undefined = undefined; + private platformView: PlatformView | undefined = undefined; private isSurfaceAvailableForRendering: boolean = false private viewportMetrics = new ViewportMetrics(); private displayInfo?: display.Display; @@ -59,6 +67,9 @@ export class FlutterView { private settings?: Settings; private mFirstFrameListeners: ArrayList; private isFlutterUiDisplayed: boolean = false; + private surfaceId: string = "0"; + private nodeController: EmbeddingNodeController = new EmbeddingNodeController(); + private platformViewSize: PlatformViewSize = new PlatformViewSize(); constructor(viewId: string, context: Context) { this.id = viewId @@ -91,6 +102,38 @@ export class FlutterView { return this.id } + setSurfaceId(surfaceId: string): void { + this.surfaceId = surfaceId; + } + + getSurfaceId(): string { + return this.surfaceId; + } + + getEmbeddingNodeController(): EmbeddingNodeController { + return this.nodeController; + } + + setWrappedBuilder(wrappedBuilder: WrappedBuilder<[Params]>) { + this.wrapBuilder = wrappedBuilder; + } + + getWrappedBuilder(): WrappedBuilder<[Params]> | undefined { + return this.wrapBuilder; + } + + setPlatformView(platformView: PlatformView) { + this.platformView = platformView; + } + + getPlatformView(): PlatformView | undefined { + return this.platformView; + } + + getPlatformViewSize(): PlatformViewSize { + return this.platformViewSize; + } + getDVModel() { return this.dVModel } -- Gitee From d7adc6c127334e868a4c877d7781695a2f21e1aa Mon Sep 17 00:00:00 2001 From: 18719058668 <718092089@qq.com> Date: Mon, 13 May 2024 15:47:55 +0800 Subject: [PATCH 2/8] set nodecontainer size Signed-off-by: 18719058668 <718092089@qq.com> --- .../main/ets/embedding/ohos/FlutterPage.ets | 28 +++++++++++-------- .../platform/PlatformViewsController.ets | 2 ++ 2 files changed, 19 insertions(+), 11 deletions(-) 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 0644802c03..f4e4cff2ae 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 @@ -34,6 +34,8 @@ export struct FlutterPage { @Builder doNothingBuilder() {} @BuilderParam splashScreenView: () => void = this.doNothingBuilder; @State showSplashScreen: boolean = true; + @State nodeContainerWidth: string | number = '100%' + @State nodeContainerHeight: string | number = '100%' private flutterView?: FlutterView | null private nodeController: EmbeddingNodeController | undefined = undefined @@ -53,6 +55,10 @@ export struct FlutterPage { if (this.flutterView != null) { let surfaceId: string = this.flutterView?.getSurfaceId() Log.d(TAG, "nodeController onLoad surfaceId:" + surfaceId); + this.nodeContainerWidth = this.flutterView?.getPlatformViewSize().width; + this.nodeContainerHeight = this.flutterView?.getPlatformViewSize().height; + Log.d(TAG, "nodeController nodeContainerWidth :" + this.nodeContainerWidth); + Log.d(TAG, "nodeController nodeContainerHeight :" + this.nodeContainerHeight); this.nodeController!!.setRenderOption(this.flutterView?.getPlatformView()!, surfaceId, NodeRenderType.RENDER_TYPE_TEXTURE, 300, 500); Log.d(TAG, "nodeController rebuild"); this.nodeController!!.rebuild(); @@ -62,8 +68,8 @@ export struct FlutterPage { build() { Stack() { NodeContainer(this.nodeController) - .width('100%') - .height('50%') + .width(this.nodeContainerWidth) + .height(this.nodeContainerHeight) .onAppear(() => { console.log("nodeController nodeContainer appear") sleep(200); @@ -89,15 +95,15 @@ export struct FlutterPage { }) .backgroundColor(Color.Transparent) - ForEach(this.rootDvModel!!, (child: Any) => { - DynamicView({ - model: child as DVModel, - params: child.params, - events: child.events, - children: child.children, - customBuilder: child.builder - }) - }) + // ForEach(this.rootDvModel!!, (child: Any) => { + // DynamicView({ + // model: child as DVModel, + // params: child.params, + // events: child.events, + // children: child.children, + // customBuilder: child.builder + // }) + // }) if (this.showSplashScreen) { this.splashScreenView(); diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets index 0ad10724cc..86f3f161c6 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets @@ -336,6 +336,8 @@ export default class PlatformViewsController implements PlatformViewsAccessibili let wrappedBuilder: WrappedBuilder<[Params]> = platformView.getView(); this.flutterView?.setWrappedBuilder(wrappedBuilder); this.flutterView?.setPlatformView(platformView); + this.flutterView!.getPlatformViewSize().width = request.logicalWidth; + this.flutterView!.getPlatformViewSize().height = request.logicalHeight; Log.i(TAG, "Create platform view success"); return textureId; -- Gitee From f0c6381e4d5f2833a2cd0431171260669f60d662 Mon Sep 17 00:00:00 2001 From: 18719058668 <718092089@qq.com> Date: Fri, 17 May 2024 20:43:45 +0800 Subject: [PATCH 3/8] add CustomTouchEvent Signed-off-by: 18719058668 <718092089@qq.com> --- .../main/ets/embedding/ohos/FlutterPage.ets | 14 ++- .../ets/plugin/platform/CustomTouchEvent.ets | 80 ++++++++++++++++ .../platform/PlatformViewsController.ets | 94 +++++-------------- 3 files changed, 111 insertions(+), 77 deletions(-) create mode 100644 shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/CustomTouchEvent.ets 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 f4e4cff2ae..8586a39ffa 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 @@ -15,7 +15,7 @@ import Any from '../../plugin/common/Any'; import Log from '../../util/Log'; import { DVModel, DVModelChildren, DynamicView } from '../../view/DynamicView/dynamicView'; -import { FlutterView } from '../../view/FlutterView'; +import { FlutterView, PlatformViewSize } from '../../view/FlutterView'; import { EmbeddingNodeController } from './EmbeddingNodeController'; import FlutterManager from './FlutterManager'; import { NodeRenderType } from '@ohos.arkui.node'; @@ -36,6 +36,7 @@ export struct FlutterPage { @State showSplashScreen: boolean = true; @State nodeContainerWidth: string | number = '100%' @State nodeContainerHeight: string | number = '100%' + @State platformViewSize: PlatformViewSize = new PlatformViewSize(); private flutterView?: FlutterView | null private nodeController: EmbeddingNodeController | undefined = undefined @@ -57,6 +58,7 @@ export struct FlutterPage { Log.d(TAG, "nodeController onLoad surfaceId:" + surfaceId); this.nodeContainerWidth = this.flutterView?.getPlatformViewSize().width; this.nodeContainerHeight = this.flutterView?.getPlatformViewSize().height; + this.platformViewSize = this.flutterView?.getPlatformViewSize(); Log.d(TAG, "nodeController nodeContainerWidth :" + this.nodeContainerWidth); Log.d(TAG, "nodeController nodeContainerHeight :" + this.nodeContainerHeight); this.nodeController!!.setRenderOption(this.flutterView?.getPlatformView()!, surfaceId, NodeRenderType.RENDER_TYPE_TEXTURE, 300, 500); @@ -68,11 +70,13 @@ export struct FlutterPage { build() { Stack() { NodeContainer(this.nodeController) - .width(this.nodeContainerWidth) - .height(this.nodeContainerHeight) - .onAppear(() => { + // .width(this.nodeContainerWidth) + // .height(this.nodeContainerHeight) + .width(this.platformViewSize.width) + .height(this.platformViewSize.height) + .onAppear(async () => { console.log("nodeController nodeContainer appear") - sleep(200); + await sleep(200); if (this.flutterView != null) { let surfaceId: string = this.flutterView?.getSurfaceId() Log.d(TAG, "nodeController onLoad surfaceId:" + surfaceId); diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/CustomTouchEvent.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/CustomTouchEvent.ets new file mode 100644 index 0000000000..bcf3e4bb5a --- /dev/null +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/CustomTouchEvent.ets @@ -0,0 +1,80 @@ +export class CustomTouchEvent implements TouchEvent { + type: TouchType = 0; + touches: CustomTouchObject[]; + changedTouches: CustomTouchObject[]; + stopPropagation: () => void = () => {}; + + timestamp: number; + source: SourceType; + pressure: number; + tiltX: number; + tiltY: number; + sourceTool: SourceTool; + + constructor(type: TouchType, touches: CustomTouchObject[], changedTouches: CustomTouchObject[], timestamp: number, source: SourceType, pressure: number, tiltX: number, tiltY: number, sourceTool: SourceTool) { + this.type = type; + this.touches = touches; + this.changedTouches = changedTouches; + this.timestamp = timestamp; + this.source = source; + this.pressure = pressure; + this.tiltX = tiltX; + this.tiltY = tiltY; + this.sourceTool = sourceTool; + } + + target: EventTarget = new CustomEventTarget(new CustomArea(0, 0, {x: 0, y: 0}, {x: 0, y: 0})); + + getHistoricalPoints(): HistoricalPoint[] { + throw new Error('Method not implemented.'); + } +} + +class CustomEventTarget implements EventTarget { + area: Area = new CustomArea(0, 0, {x: 0, y: 0}, {x: 0, y: 0}); + + constructor(area: Area) { + this.area = area; + } +} + +class CustomArea implements Area { + width: Length = 0; + height: Length = 0; + position: Position = {x: 0, y: 0}; + globalPosition: Position = {x: 0, y: 0}; + + constructor(width: Length, height: Length, position: Position, globalPosition: Position ) { + this.width = width; + this.height = height; + this.position = position; + this.globalPosition = globalPosition; + } +} + + +export class CustomTouchObject implements TouchObject { + type: TouchType; + id: number; + displayX: number; + displayY: number; + windowX: number; + windowY: number; + screenX: number; + screenY: number; + x: number; + y: number; + + constructor(type: TouchType, id: number, displayX: number, displayY: number, windowX: number, windowY: number, screenX: number, screenY: number, x: number, y: number) { + this.type = type; + this.id = id; + this.displayX = displayX; + this.displayY = displayY; + this.windowX = windowX; + this.windowY = windowY; + this.screenX = screenX; + this.screenY = screenY; + this.x = x; + this.y = y; + } +} \ No newline at end of file diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets index 86f3f161c6..2041e19d13 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets @@ -44,6 +44,7 @@ import { ByteBuffer } from '../../util/ByteBuffer'; import Any from '../common/Any'; import { RawPointerCoords } from './RawPointerCoord'; import { ArrayList } from '@kit.ArkTS'; +import { CustomTouchEvent, CustomTouchObject } from './CustomTouchEvent'; const TAG = "PlatformViewsController" let tsp: number = 52086377781000 @@ -136,26 +137,29 @@ export default class PlatformViewsController implements PlatformViewsAccessibili let physicalHeight: number = this.toPhysicalPixels(request.newLogicalHeight); let viewId: number = request.viewId; Log.i(TAG, `Resize viewId ${viewId}, pw:${physicalWidth}, ph:${physicalHeight},lw:${request.newLogicalWidth}, lh:${request.newLogicalHeight}`); - this.flutterView!.getPlatformViewSize().width = physicalWidth; - this.flutterView!.getPlatformViewSize().height = physicalHeight; + this.flutterView!.getPlatformViewSize().width = request.newLogicalWidth; + this.flutterView!.getPlatformViewSize().height = request.newLogicalHeight; } offset(viewId: number, top: number, left: number): void { Log.i(TAG, `Offset is id${viewId}, t:${top}, l:${left}`); - let viewWrapper: PlatformViewWrapper | null = this.viewWrappers.get(viewId) || null; - if (viewWrapper == null) { - Log.e(TAG, "Setting offset for an unknown platform view with id: " + viewId); - return; - } - let physicalTop = this.toPhysicalPixels(top); - let physicalLeft = this.toPhysicalPixels(left); - let params = viewWrapper.getDvModel()!.params; - this.setParams(params!, "marginTop", physicalTop); - this.setParams(params!, "marginLeft", physicalLeft); - viewWrapper.setLayoutParams(params!); + + // let viewWrapper: PlatformViewWrapper | null = this.viewWrappers.get(viewId) || null; + // if (viewWrapper == null) { + // Log.e(TAG, "Setting offset for an unknown platform view with id: " + viewId); + // return; + // } + // + // let physicalTop = this.toPhysicalPixels(top); + // let physicalLeft = this.toPhysicalPixels(left); + // let params = viewWrapper.getDvModel()!.params; + // this.setParams(params!, "marginTop", physicalTop); + // this.setParams(params!, "marginLeft", physicalLeft); + // viewWrapper.setLayoutParams(params!); + } onTouch(touch: PlatformViewTouch): void { @@ -175,72 +179,18 @@ export default class PlatformViewsController implements PlatformViewsAccessibili - let touches1: TouchObject = { - type: touch.action, - id: 0, - displayX: xx, - displayY: yy, - windowX: xx, - windowY: yy, - screenX: xx, - screenY: yy, - x: xx, - y: yy, - } - - - let changedTouches1: TouchObject = { - type: touch.action, - id: 0, - displayX: xx, - displayY: yy, - windowX: xx, - windowY: yy, - screenX: xx, - screenY: yy, - x: xx, - y: yy, - } - - tsp = tsp + 10000; - let touchEvent1: TouchEvent = { - type: touch.action, - source: 2, - sourceTool: 1, - pressure: 1, - timestamp: tsp, - touches: [touches1], - changedTouches: [changedTouches1], - tiltX: 0, - tiltY: 0, - stopPropagation: () => { - }, - getHistoricalPoints: () => { - return []; - }, - target: { - area: { - width: 1, - height: 1, - position: { - x: 1, - y: 1 - }, - globalPosition: { - x: 1, - y: 1 - } - } - }, - } + let touches1: CustomTouchObject = new CustomTouchObject(touch.action, 0, xx, yy, xx, yy, xx, yy, xx, yy); + let changedTouches1: CustomTouchObject = new CustomTouchObject(touch.action, 0, xx, yy, xx, yy, xx, yy, xx, yy); + let customTouchEvent1: CustomTouchEvent = new CustomTouchEvent(touch.action, [touches1], [changedTouches1], tsp, 2, 1, 0, 0, 1); + console.log("nodeController onTouch type " + touch.action) console.log("nodeController onTouch timestamp " + tsp) if (this.flutterView == null) { console.log("nodeController flutterView == null") } - this.flutterView?.getEmbeddingNodeController().postEvent(touchEvent1) + this.flutterView?.getEmbeddingNodeController().postEvent(customTouchEvent1) } setDirection(viewId: number, direction: number): void { -- Gitee From 85e9716cc157993567ebd052e6d8aa6e582db3f6 Mon Sep 17 00:00:00 2001 From: 18719058668 <718092089@qq.com> Date: Mon, 20 May 2024 14:28:17 +0800 Subject: [PATCH 4/8] add direction Signed-off-by: 18719058668 <718092089@qq.com> --- .../systemchannels/PlatformViewsChannel.ets | 16 ++++++--- .../ohos/EmbeddingNodeController.ets | 7 ++-- .../main/ets/embedding/ohos/FlutterPage.ets | 34 ++++++++++--------- .../main/ets/plugin/platform/PlatformView.ets | 1 + .../platform/PlatformViewsController.ets | 13 +++++-- .../flutter/src/main/ets/view/FlutterView.ets | 7 ++-- 6 files changed, 50 insertions(+), 28 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/PlatformViewsChannel.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/PlatformViewsChannel.ets index 66531efde8..01c41d4120 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/PlatformViewsChannel.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/PlatformViewsChannel.ets @@ -65,9 +65,9 @@ export default class PlatformViewsChannel { let direction: Direction = Direction.Ltr; if (createArgs.get("direction") == 0) { - direction = Direction.Ltr; - } else if (createArgs.get("direction") == 1) { direction = Direction.Rtl; + } else if (createArgs.get("direction") == 1) { + direction = Direction.Ltr; } try { @@ -206,7 +206,13 @@ export default class PlatformViewsChannel { setDirection(call: MethodCall, result: MethodResult): void { const setDirectionArgs: Map = call.args; const newDirectionViewId: number = setDirectionArgs.get("id"); - const direction: number = setDirectionArgs.get("direction"); + const directionNumber: number = setDirectionArgs.get("direction"); + let direction: Direction = Direction.Ltr; + if (directionNumber == 0) { + direction = Direction.Rtl; + } else if (directionNumber == 1) { + direction = Direction.Ltr; + } try { this.handler?.setDirection(newDirectionViewId, direction); @@ -307,7 +313,7 @@ export interface PlatformViewsHandler { * The Flutter application would like to change the layout direction of an existing Android * {@code View}, i.e., platform view. */ - setDirection(viewId: number, direction: number): void; + setDirection(viewId: number, direction: Direction): void; /** Clears the focus from the platform view with a give id if it is currently focused. */ clearFocus(viewId: number): void; @@ -355,7 +361,7 @@ export class PlatformViewCreationRequest { /** * The layout direction of the new platform view. */ - public direction: number; + public direction: Direction; public displayMode: RequestedDisplayMode; /** Custom parameters that are unique to the desired platform view. */ diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/EmbeddingNodeController.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/EmbeddingNodeController.ets index cd9671d1fb..7ce67e5a5c 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/EmbeddingNodeController.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/EmbeddingNodeController.ets @@ -59,10 +59,12 @@ export class EmbeddingNodeController extends NodeController { private renderType_ :NodeRenderType = NodeRenderType.RENDER_TYPE_DISPLAY; private width_ : number = 0; private height_ : number = 0; + private direction: Direction = Direction.Auto; private type_ : string = ""; private isDestroy_ : boolean = false; - setRenderOption(platformView: PlatformView, surfaceId: string, renderType: NodeRenderType, width: number, height: number) { + + setRenderOption(platformView: PlatformView, surfaceId: string, renderType: NodeRenderType, width: number, height: number, direction: Direction) { if (platformView == undefined) { console.log("nodeController platformView undefined") } else { @@ -74,6 +76,7 @@ export class EmbeddingNodeController extends NodeController { this.renderType_ = renderType; this.width_ = width; this.height_ = height; + this.direction = direction; } makeNode(uiContext: UIContext): FrameNode | null{ this.rootNode = new BuilderNode(uiContext, { surfaceId: this.surfaceId_, type: this.renderType_}); @@ -82,7 +85,7 @@ export class EmbeddingNodeController extends NodeController { this.rootNode.build(wrapBuilder(ButtonBuilder), {width : this.width_, height : this.height_}); } else { console.log("nodeController makeNode 2") - this.rootNode.build(this.wrappedBuilder, {width : this.width_, height : this.height_, platformView: this.platformView}); + this.rootNode.build(this.wrappedBuilder, {width : this.width_, height : this.height_, direction: this.direction, platformView: this.platformView}); } return this.rootNode.getFrameNode(); } 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 8586a39ffa..093e7bbd16 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 @@ -15,7 +15,7 @@ import Any from '../../plugin/common/Any'; import Log from '../../util/Log'; import { DVModel, DVModelChildren, DynamicView } from '../../view/DynamicView/dynamicView'; -import { FlutterView, PlatformViewSize } from '../../view/FlutterView'; +import { FlutterView, PlatformViewParas } from '../../view/FlutterView'; import { EmbeddingNodeController } from './EmbeddingNodeController'; import FlutterManager from './FlutterManager'; import { NodeRenderType } from '@ohos.arkui.node'; @@ -36,7 +36,7 @@ export struct FlutterPage { @State showSplashScreen: boolean = true; @State nodeContainerWidth: string | number = '100%' @State nodeContainerHeight: string | number = '100%' - @State platformViewSize: PlatformViewSize = new PlatformViewSize(); + @State platformViewSize: PlatformViewParas = new PlatformViewParas(); private flutterView?: FlutterView | null private nodeController: EmbeddingNodeController | undefined = undefined @@ -61,9 +61,9 @@ export struct FlutterPage { this.platformViewSize = this.flutterView?.getPlatformViewSize(); Log.d(TAG, "nodeController nodeContainerWidth :" + this.nodeContainerWidth); Log.d(TAG, "nodeController nodeContainerHeight :" + this.nodeContainerHeight); - this.nodeController!!.setRenderOption(this.flutterView?.getPlatformView()!, surfaceId, NodeRenderType.RENDER_TYPE_TEXTURE, 300, 500); - Log.d(TAG, "nodeController rebuild"); - this.nodeController!!.rebuild(); + // this.nodeController!!.setRenderOption(this.flutterView?.getPlatformView()!, surfaceId, NodeRenderType.RENDER_TYPE_TEXTURE, 300, 500, this.platformViewSize.direction); + // Log.d(TAG, "nodeController rebuild"); + // this.nodeController!!.rebuild(); } } @@ -74,17 +74,19 @@ export struct FlutterPage { // .height(this.nodeContainerHeight) .width(this.platformViewSize.width) .height(this.platformViewSize.height) - .onAppear(async () => { - console.log("nodeController nodeContainer appear") - await sleep(200); - if (this.flutterView != null) { - let surfaceId: string = this.flutterView?.getSurfaceId() - Log.d(TAG, "nodeController onLoad surfaceId:" + surfaceId); - this.nodeController!!.setRenderOption(this.flutterView?.getPlatformView()!, surfaceId, NodeRenderType.RENDER_TYPE_TEXTURE, 300, 500); - Log.d(TAG, "nodeController rebuild"); - this.nodeController!!.rebuild(); - } - }) + // .width(this.storageLinkWidth) + // .height(this.storageLinkHeight) + // .onAppear(async () => { + // console.log("nodeController nodeContainer appear") + // await sleep(200); + // if (this.flutterView != null) { + // let surfaceId: string = this.flutterView?.getSurfaceId() + // Log.d(TAG, "nodeController onLoad surfaceId:" + surfaceId); + // this.nodeController!!.setRenderOption(this.flutterView?.getPlatformView()!, surfaceId, NodeRenderType.RENDER_TYPE_TEXTURE, 300, 500); + // Log.d(TAG, "nodeController rebuild"); + // this.nodeController!!.rebuild(); + // } + // }) XComponent({ id: this.viewId, type: this.xComponentType, libraryname: 'flutter' }) .focusable(true) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformView.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformView.ets index 9a86013708..55ff1c8a9f 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformView.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformView.ets @@ -18,6 +18,7 @@ import { DVModel, DynamicView } from '../../view/DynamicView/dynamicView' export declare class Params { width : number height : number + direction: Direction platformView : PlatformView } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets index 2041e19d13..dffca31eae 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets @@ -45,6 +45,8 @@ import Any from '../common/Any'; import { RawPointerCoords } from './RawPointerCoord'; import { ArrayList } from '@kit.ArkTS'; import { CustomTouchEvent, CustomTouchObject } from './CustomTouchEvent'; +import { NodeRenderType } from '@kit.ArkUI'; + const TAG = "PlatformViewsController" let tsp: number = 52086377781000 @@ -193,7 +195,10 @@ export default class PlatformViewsController implements PlatformViewsAccessibili this.flutterView?.getEmbeddingNodeController().postEvent(customTouchEvent1) } - setDirection(viewId: number, direction: number): void { + setDirection(viewId: number, direction: Direction): void { + this.flutterView!.getPlatformViewSize().direction = direction; + // this.flutterView!.getEmbeddingNodeController().setRenderOption(platformView, surfaceId, NodeRenderType.RENDER_TYPE_TEXTURE, 300, 500, request.direction); + this.flutterView!.getEmbeddingNodeController().rebuild(); // embeddedView.params.direction = direction; } @@ -275,10 +280,11 @@ export default class PlatformViewsController implements PlatformViewsAccessibili Log.i(TAG, "Hosting view in view hierarchy for platform view: " + request.viewId); // let viewWrapper: PlatformViewWrapper = new PlatformViewWrapper(); + let surfaceId: string = '0'; let textureId: number = 0; if (this.textureRegistry != null) { textureId = this.textureRegistry!.getTextureId(); - let surfaceId: string = this.textureRegistry!.registerTexture(textureId).getSurfaceId().toString(); + surfaceId = this.textureRegistry!.registerTexture(textureId).getSurfaceId().toString(); Log.i(TAG, "nodeController getSurfaceId: " + surfaceId); this.flutterView!.setSurfaceId(surfaceId); } @@ -288,6 +294,9 @@ export default class PlatformViewsController implements PlatformViewsAccessibili this.flutterView?.setPlatformView(platformView); this.flutterView!.getPlatformViewSize().width = request.logicalWidth; this.flutterView!.getPlatformViewSize().height = request.logicalHeight; + this.flutterView!.getPlatformViewSize().direction = request.direction; + this.flutterView!.getEmbeddingNodeController().setRenderOption(platformView, surfaceId, NodeRenderType.RENDER_TYPE_TEXTURE, 300, 500, request.direction); + this.flutterView!.getEmbeddingNodeController().rebuild(); Log.i(TAG, "Create platform view success"); return textureId; 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 5fb6ef08fd..97cf84a048 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 @@ -47,9 +47,10 @@ class ViewportMetrics { physicalTouchSlop = -1; } -export class PlatformViewSize { +export class PlatformViewParas { width: number = 0; height: number = 0; + direction: Direction = Direction.Auto; } export class FlutterView { private flutterEngine: FlutterEngine | null = null @@ -69,7 +70,7 @@ export class FlutterView { private isFlutterUiDisplayed: boolean = false; private surfaceId: string = "0"; private nodeController: EmbeddingNodeController = new EmbeddingNodeController(); - private platformViewSize: PlatformViewSize = new PlatformViewSize(); + private platformViewSize: PlatformViewParas = new PlatformViewParas(); constructor(viewId: string, context: Context) { this.id = viewId @@ -130,7 +131,7 @@ export class FlutterView { return this.platformView; } - getPlatformViewSize(): PlatformViewSize { + getPlatformViewSize(): PlatformViewParas { return this.platformViewSize; } -- Gitee From 42d1eeb3cddb3f6d99de5a0b70466fed3d56f264 Mon Sep 17 00:00:00 2001 From: 18719058668 <718092089@qq.com> Date: Mon, 20 May 2024 14:59:20 +0800 Subject: [PATCH 5/8] add direction paras Signed-off-by: 18719058668 <718092089@qq.com> --- .../systemchannels/PlatformViewsChannel.ets | 18 +++++++++--------- .../platform/PlatformViewsController.ets | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/PlatformViewsChannel.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/PlatformViewsChannel.ets index 01c41d4120..30066899e9 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/PlatformViewsChannel.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/PlatformViewsChannel.ets @@ -65,9 +65,9 @@ export default class PlatformViewsChannel { let direction: Direction = Direction.Ltr; if (createArgs.get("direction") == 0) { - direction = Direction.Rtl; - } else if (createArgs.get("direction") == 1) { direction = Direction.Ltr; + } else if (createArgs.get("direction") == 1) { + direction = Direction.Rtl; } try { @@ -206,13 +206,13 @@ export default class PlatformViewsChannel { setDirection(call: MethodCall, result: MethodResult): void { const setDirectionArgs: Map = call.args; const newDirectionViewId: number = setDirectionArgs.get("id"); - const directionNumber: number = setDirectionArgs.get("direction"); - let direction: Direction = Direction.Ltr; - if (directionNumber == 0) { - direction = Direction.Rtl; - } else if (directionNumber == 1) { - direction = Direction.Ltr; - } + const direction: number = setDirectionArgs.get("direction"); + // let direction: Direction = Direction.Ltr; + // if (directionNumber == 0) { + // direction = Direction.Ltr; + // } else if (directionNumber == 1) { + // direction = Direction.Ltr; + // } try { this.handler?.setDirection(newDirectionViewId, direction); diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets index dffca31eae..8b0641aff3 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets @@ -196,8 +196,8 @@ export default class PlatformViewsController implements PlatformViewsAccessibili } setDirection(viewId: number, direction: Direction): void { - this.flutterView!.getPlatformViewSize().direction = direction; - // this.flutterView!.getEmbeddingNodeController().setRenderOption(platformView, surfaceId, NodeRenderType.RENDER_TYPE_TEXTURE, 300, 500, request.direction); + // this.flutterView!.getPlatformViewSize().direction = direction; + this.flutterView!.getEmbeddingNodeController().setRenderOption(this.flutterView!.getPlatformView()!, this.flutterView!.getSurfaceId(), NodeRenderType.RENDER_TYPE_TEXTURE, 300, 500, direction); this.flutterView!.getEmbeddingNodeController().rebuild(); // embeddedView.params.direction = direction; } -- Gitee From aa2027495e349615ed4823dbf035440bba534612 Mon Sep 17 00:00:00 2001 From: 18719058668 <718092089@qq.com> Date: Mon, 20 May 2024 15:30:41 +0800 Subject: [PATCH 6/8] add resize Signed-off-by: 18719058668 <718092089@qq.com> --- .../src/main/ets/plugin/platform/PlatformViewsController.ets | 1 + 1 file changed, 1 insertion(+) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets index 8b0641aff3..35b5ca7cc4 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets @@ -143,6 +143,7 @@ export default class PlatformViewsController implements PlatformViewsAccessibili this.flutterView!.getPlatformViewSize().height = request.newLogicalHeight; + onComplete.run(new PlatformViewBufferSize(request.newLogicalWidth, request.newLogicalHeight)); } offset(viewId: number, top: number, left: number): void { -- Gitee From e9993ba55c4fdf9683972c7ea54e45f925938bd6 Mon Sep 17 00:00:00 2001 From: 18719058668 <718092089@qq.com> Date: Tue, 21 May 2024 15:17:28 +0800 Subject: [PATCH 7/8] add resize function Signed-off-by: 18719058668 <718092089@qq.com> --- .../main/ets/embedding/ohos/FlutterPage.ets | 12 +++---- .../platform/PlatformViewsController.ets | 32 +++++++++++++------ 2 files changed, 28 insertions(+), 16 deletions(-) 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 093e7bbd16..12c9fd66d4 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 @@ -37,10 +37,14 @@ export struct FlutterPage { @State nodeContainerWidth: string | number = '100%' @State nodeContainerHeight: string | number = '100%' @State platformViewSize: PlatformViewParas = new PlatformViewParas(); + @StorageLink('nodeWidth') storageLinkWidth: number = 0; + @StorageLink('nodeHeight') storageLinkHeight: number = 0; private flutterView?: FlutterView | null private nodeController: EmbeddingNodeController | undefined = undefined aboutToAppear() { + AppStorage.setOrCreate('nodeWidth', 100); + AppStorage.setOrCreate('nodeHeight', 200); this.flutterView = FlutterManager.getInstance().getFlutterView(this.viewId); this.rootDvModel = this.flutterView!!.getDVModel().children; this.nodeController = this.flutterView!!.getEmbeddingNodeController(); @@ -70,12 +74,8 @@ export struct FlutterPage { build() { Stack() { NodeContainer(this.nodeController) - // .width(this.nodeContainerWidth) - // .height(this.nodeContainerHeight) - .width(this.platformViewSize.width) - .height(this.platformViewSize.height) - // .width(this.storageLinkWidth) - // .height(this.storageLinkHeight) + .width(this.storageLinkWidth) + .height(this.storageLinkHeight) // .onAppear(async () => { // console.log("nodeController nodeContainer appear") // await sleep(200); diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets index 35b5ca7cc4..71084cb8fe 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets @@ -102,7 +102,7 @@ export default class PlatformViewsController implements PlatformViewsAccessibili Log.i(TAG, "Enter createForPlatformViewLayer"); this.ensureValidRequest(request); - let platformView: PlatformView = this.createPlatformView(request, false); + let platformView: PlatformView = this.createPlatformView(request); this.configureForHybridComposition(platformView, request); } @@ -139,11 +139,18 @@ export default class PlatformViewsController implements PlatformViewsAccessibili let physicalHeight: number = this.toPhysicalPixels(request.newLogicalHeight); let viewId: number = request.viewId; Log.i(TAG, `Resize viewId ${viewId}, pw:${physicalWidth}, ph:${physicalHeight},lw:${request.newLogicalWidth}, lh:${request.newLogicalHeight}`); - this.flutterView!.getPlatformViewSize().width = request.newLogicalWidth; - this.flutterView!.getPlatformViewSize().height = request.newLogicalHeight; + let link1: SubscribedAbstractProperty = AppStorage.link('nodeWidth'); + let link2: SubscribedAbstractProperty = AppStorage.link('nodeHeight'); + link1.set(physicalWidth); + link2.set(physicalHeight); + // this.flutterView!.getPlatformViewSize().width = request.newLogicalWidth; + // this.flutterView!.getPlatformViewSize().height = request.newLogicalHeight; + this.flutterView!.getPlatformViewSize().direction = Direction.Rtl; + this.flutterView!.getEmbeddingNodeController().setRenderOption(this.flutterView!.getPlatformView()!, this.flutterView!.getSurfaceId(), NodeRenderType.RENDER_TYPE_TEXTURE, 300, 500, this.flutterView!.getPlatformViewSize().direction); + this.flutterView!.getEmbeddingNodeController().rebuild(); - onComplete.run(new PlatformViewBufferSize(request.newLogicalWidth, request.newLogicalHeight)); + onComplete.run(new PlatformViewBufferSize(physicalWidth, physicalHeight)); } offset(viewId: number, top: number, left: number): void { @@ -218,7 +225,8 @@ export default class PlatformViewsController implements PlatformViewsAccessibili Log.e(TAG, "Setting direction to a null view with id: " + viewId); return; } - focusControl.requestFocus("flutterXComponent"); + // focusControl.requestFocus("flutterXComponent"); + focusControl.requestFocus(this.flutterView?.getId()); } synchronizeToNativeViewHierarchy(yes: boolean): void { throw new Error('Method not implemented.'); @@ -244,8 +252,8 @@ export default class PlatformViewsController implements PlatformViewsAccessibili } } - private createPlatformView(request: PlatformViewCreationRequest, wrapContext: boolean): PlatformView { - Log.i(TAG, "Enter createPlatformView"); + private createPlatformView(request: PlatformViewCreationRequest): PlatformView { + Log.i(TAG, "begin createPlatformView"); const viewFactory: PlatformViewFactory = this.registry.getFactory(request.viewType); if (viewFactory == null) { throw new Error("Trying to create a platform view of unregistered type: " + request.viewType) @@ -293,9 +301,13 @@ export default class PlatformViewsController implements PlatformViewsAccessibili let wrappedBuilder: WrappedBuilder<[Params]> = platformView.getView(); this.flutterView?.setWrappedBuilder(wrappedBuilder); this.flutterView?.setPlatformView(platformView); - this.flutterView!.getPlatformViewSize().width = request.logicalWidth; - this.flutterView!.getPlatformViewSize().height = request.logicalHeight; - this.flutterView!.getPlatformViewSize().direction = request.direction; + // this.flutterView!.getPlatformViewSize().width = request.logicalWidth; + // this.flutterView!.getPlatformViewSize().height = request.logicalHeight; + // this.flutterView!.getPlatformViewSize().direction = request.direction; + let link1: SubscribedAbstractProperty = AppStorage.link('nodeWidth'); + let link2: SubscribedAbstractProperty = AppStorage.link('nodeHeight'); + link1.set(request.logicalWidth); + link2.set(request.logicalHeight); this.flutterView!.getEmbeddingNodeController().setRenderOption(platformView, surfaceId, NodeRenderType.RENDER_TYPE_TEXTURE, 300, 500, request.direction); this.flutterView!.getEmbeddingNodeController().rebuild(); Log.i(TAG, "Create platform view success"); -- Gitee From 716790dcc93ea0d37b55b1881c96f85b8e4d5321 Mon Sep 17 00:00:00 2001 From: 18719058668 <718092089@qq.com> Date: Wed, 22 May 2024 10:44:29 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 18719058668 <718092089@qq.com> --- .../ohos/EmbeddingNodeController.ets | 36 +++++-------- .../main/ets/embedding/ohos/FlutterPage.ets | 46 +--------------- .../main/ets/plugin/platform/PlatformView.ets | 2 - .../platform/PlatformViewsController.ets | 54 +++++++------------ 4 files changed, 35 insertions(+), 103 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/EmbeddingNodeController.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/EmbeddingNodeController.ets index 7ce67e5a5c..a78f35ff4f 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/EmbeddingNodeController.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/EmbeddingNodeController.ets @@ -38,8 +38,6 @@ struct ButtonComponent { .border({ width: 2, color: Color.Red}) .backgroundColor(this.bkColor) } - .width(this.params.width) - .height(this.params.height) } } @@ -54,38 +52,32 @@ export class EmbeddingNodeController extends NodeController { private rootNode: BuilderNode<[Params]> | undefined | null = null; private wrappedBuilder: WrappedBuilder<[Params]> | null = null; private platformView: PlatformView | undefined = undefined; - private embedId_ : string = ""; - private surfaceId_ : string = ""; - private renderType_ :NodeRenderType = NodeRenderType.RENDER_TYPE_DISPLAY; - private width_ : number = 0; - private height_ : number = 0; + private embedId : string = ""; + private surfaceId : string = ""; + private renderType :NodeRenderType = NodeRenderType.RENDER_TYPE_DISPLAY; private direction: Direction = Direction.Auto; - private type_ : string = ""; - private isDestroy_ : boolean = false; + private isDestroy : boolean = false; - - setRenderOption(platformView: PlatformView, surfaceId: string, renderType: NodeRenderType, width: number, height: number, direction: Direction) { + setRenderOption(platformView: PlatformView, surfaceId: string, renderType: NodeRenderType, direction: Direction) { if (platformView == undefined) { console.log("nodeController platformView undefined") } else { this.wrappedBuilder = platformView.getView(); } - this.platformView = platformView; - this.surfaceId_ = surfaceId; - this.renderType_ = renderType; - this.width_ = width; - this.height_ = height; + this.surfaceId = surfaceId; + this.renderType = renderType; this.direction = direction; } + makeNode(uiContext: UIContext): FrameNode | null{ - this.rootNode = new BuilderNode(uiContext, { surfaceId: this.surfaceId_, type: this.renderType_}); + this.rootNode = new BuilderNode(uiContext, { surfaceId: this.surfaceId, type: this.renderType}); if (this.wrappedBuilder == null) { console.log("nodeController makeNode 1") - this.rootNode.build(wrapBuilder(ButtonBuilder), {width : this.width_, height : this.height_}); + this.rootNode.build(wrapBuilder(ButtonBuilder), {}); } else { console.log("nodeController makeNode 2") - this.rootNode.build(this.wrappedBuilder, {width : this.width_, height : this.height_, direction: this.direction, platformView: this.platformView}); + this.rootNode.build(this.wrappedBuilder, {direction: this.direction, platformView: this.platformView}); } return this.rootNode.getFrameNode(); } @@ -102,12 +94,12 @@ export class EmbeddingNodeController extends NodeController { this.rootNode?.update(arg); } getEmbedId() : string { - return this.embedId_; + return this.embedId; } setDestroy(isDestroy : boolean) : void { - this.isDestroy_ = isDestroy; - if (this.isDestroy_) { + this.isDestroy = isDestroy; + if (this.isDestroy) { this.rootNode = null; } } 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 12c9fd66d4..9d17e66231 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 @@ -12,13 +12,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import Any from '../../plugin/common/Any'; + import Log from '../../util/Log'; -import { DVModel, DVModelChildren, DynamicView } from '../../view/DynamicView/dynamicView'; -import { FlutterView, PlatformViewParas } from '../../view/FlutterView'; +import { FlutterView } from '../../view/FlutterView'; import { EmbeddingNodeController } from './EmbeddingNodeController'; import FlutterManager from './FlutterManager'; -import { NodeRenderType } from '@ohos.arkui.node'; const TAG = "FlutterPage"; @@ -27,26 +25,19 @@ const TAG = "FlutterPage"; */ @Component export struct FlutterPage { - @State rootDvModel: DVModelChildren | undefined = undefined @Prop viewId: string = "" @Prop xComponentType: XComponentType = XComponentType.TEXTURE @Builder doNothingBuilder() {} @BuilderParam splashScreenView: () => void = this.doNothingBuilder; @State showSplashScreen: boolean = true; - @State nodeContainerWidth: string | number = '100%' - @State nodeContainerHeight: string | number = '100%' - @State platformViewSize: PlatformViewParas = new PlatformViewParas(); @StorageLink('nodeWidth') storageLinkWidth: number = 0; @StorageLink('nodeHeight') storageLinkHeight: number = 0; private flutterView?: FlutterView | null private nodeController: EmbeddingNodeController | undefined = undefined aboutToAppear() { - AppStorage.setOrCreate('nodeWidth', 100); - AppStorage.setOrCreate('nodeHeight', 200); this.flutterView = FlutterManager.getInstance().getFlutterView(this.viewId); - this.rootDvModel = this.flutterView!!.getDVModel().children; this.nodeController = this.flutterView!!.getEmbeddingNodeController(); this.flutterView?.addFirstFrameListener(this) } @@ -57,18 +48,6 @@ export struct FlutterPage { onFirstFrame() { this.showSplashScreen = false; - if (this.flutterView != null) { - let surfaceId: string = this.flutterView?.getSurfaceId() - Log.d(TAG, "nodeController onLoad surfaceId:" + surfaceId); - this.nodeContainerWidth = this.flutterView?.getPlatformViewSize().width; - this.nodeContainerHeight = this.flutterView?.getPlatformViewSize().height; - this.platformViewSize = this.flutterView?.getPlatformViewSize(); - Log.d(TAG, "nodeController nodeContainerWidth :" + this.nodeContainerWidth); - Log.d(TAG, "nodeController nodeContainerHeight :" + this.nodeContainerHeight); - // this.nodeController!!.setRenderOption(this.flutterView?.getPlatformView()!, surfaceId, NodeRenderType.RENDER_TYPE_TEXTURE, 300, 500, this.platformViewSize.direction); - // Log.d(TAG, "nodeController rebuild"); - // this.nodeController!!.rebuild(); - } } build() { @@ -76,17 +55,6 @@ export struct FlutterPage { NodeContainer(this.nodeController) .width(this.storageLinkWidth) .height(this.storageLinkHeight) - // .onAppear(async () => { - // console.log("nodeController nodeContainer appear") - // await sleep(200); - // if (this.flutterView != null) { - // let surfaceId: string = this.flutterView?.getSurfaceId() - // Log.d(TAG, "nodeController onLoad surfaceId:" + surfaceId); - // this.nodeController!!.setRenderOption(this.flutterView?.getPlatformView()!, surfaceId, NodeRenderType.RENDER_TYPE_TEXTURE, 300, 500); - // Log.d(TAG, "nodeController rebuild"); - // this.nodeController!!.rebuild(); - // } - // }) XComponent({ id: this.viewId, type: this.xComponentType, libraryname: 'flutter' }) .focusable(true) @@ -101,16 +69,6 @@ export struct FlutterPage { }) .backgroundColor(Color.Transparent) - // ForEach(this.rootDvModel!!, (child: Any) => { - // DynamicView({ - // model: child as DVModel, - // params: child.params, - // events: child.events, - // children: child.children, - // customBuilder: child.builder - // }) - // }) - if (this.showSplashScreen) { this.splashScreenView(); } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformView.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformView.ets index 55ff1c8a9f..320e5e973d 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformView.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformView.ets @@ -16,8 +16,6 @@ import { DVModel, DynamicView } from '../../view/DynamicView/dynamicView' export declare class Params { - width : number - height : number direction: Direction platformView : PlatformView } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets index 71084cb8fe..21cd6283d1 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets @@ -68,6 +68,8 @@ export default class PlatformViewsController implements PlatformViewsAccessibili private currentFrameUsedOverlayLayerIds: HashSet; private currentFrameUsedPlatformViewIds: HashSet; private platformViewParent: Map; + private nodeWidthLink: SubscribedAbstractProperty = AppStorage.link('nodeWidth'); + private nodeHeightLink: SubscribedAbstractProperty = AppStorage.link('nodeHeight'); constructor() { this.registry = new PlatformViewRegistryImpl(); @@ -139,14 +141,16 @@ export default class PlatformViewsController implements PlatformViewsAccessibili let physicalHeight: number = this.toPhysicalPixels(request.newLogicalHeight); let viewId: number = request.viewId; Log.i(TAG, `Resize viewId ${viewId}, pw:${physicalWidth}, ph:${physicalHeight},lw:${request.newLogicalWidth}, lh:${request.newLogicalHeight}`); - let link1: SubscribedAbstractProperty = AppStorage.link('nodeWidth'); - let link2: SubscribedAbstractProperty = AppStorage.link('nodeHeight'); - link1.set(physicalWidth); - link2.set(physicalHeight); - // this.flutterView!.getPlatformViewSize().width = request.newLogicalWidth; - // this.flutterView!.getPlatformViewSize().height = request.newLogicalHeight; + let oldNodeWidth: number = AppStorage.get('nodeWidth')! + let oldNodeHeight: number = AppStorage.get('nodeHeight')! + if ((oldNodeWidth == physicalWidth) && (oldNodeHeight == physicalHeight)) { + onComplete.run(new PlatformViewBufferSize(physicalWidth, physicalHeight)); + return; + } + this.nodeWidthLink.set(physicalWidth); + this.nodeHeightLink.set(physicalHeight); this.flutterView!.getPlatformViewSize().direction = Direction.Rtl; - this.flutterView!.getEmbeddingNodeController().setRenderOption(this.flutterView!.getPlatformView()!, this.flutterView!.getSurfaceId(), NodeRenderType.RENDER_TYPE_TEXTURE, 300, 500, this.flutterView!.getPlatformViewSize().direction); + this.flutterView!.getEmbeddingNodeController().setRenderOption(this.flutterView!.getPlatformView()!, this.flutterView!.getSurfaceId(), NodeRenderType.RENDER_TYPE_TEXTURE, this.flutterView!.getPlatformViewSize().direction); this.flutterView!.getEmbeddingNodeController().rebuild(); @@ -155,21 +159,6 @@ export default class PlatformViewsController implements PlatformViewsAccessibili offset(viewId: number, top: number, left: number): void { Log.i(TAG, `Offset is id${viewId}, t:${top}, l:${left}`); - - - // let viewWrapper: PlatformViewWrapper | null = this.viewWrappers.get(viewId) || null; - // if (viewWrapper == null) { - // Log.e(TAG, "Setting offset for an unknown platform view with id: " + viewId); - // return; - // } - // - // let physicalTop = this.toPhysicalPixels(top); - // let physicalLeft = this.toPhysicalPixels(left); - // let params = viewWrapper.getDvModel()!.params; - // this.setParams(params!, "marginTop", physicalTop); - // this.setParams(params!, "marginLeft", physicalLeft); - // viewWrapper.setLayoutParams(params!); - } onTouch(touch: PlatformViewTouch): void { @@ -204,10 +193,8 @@ export default class PlatformViewsController implements PlatformViewsAccessibili } setDirection(viewId: number, direction: Direction): void { - // this.flutterView!.getPlatformViewSize().direction = direction; - this.flutterView!.getEmbeddingNodeController().setRenderOption(this.flutterView!.getPlatformView()!, this.flutterView!.getSurfaceId(), NodeRenderType.RENDER_TYPE_TEXTURE, 300, 500, direction); + this.flutterView!.getEmbeddingNodeController().setRenderOption(this.flutterView!.getPlatformView()!, this.flutterView!.getSurfaceId(), NodeRenderType.RENDER_TYPE_TEXTURE, direction); this.flutterView!.getEmbeddingNodeController().rebuild(); - // embeddedView.params.direction = direction; } validateDirection(direction:number):boolean { @@ -236,7 +223,7 @@ export default class PlatformViewsController implements PlatformViewsAccessibili Log.i(TAG, "Enter createForTextureLayer"); this.ensureValidRequest(request); - let platformView: PlatformView = this.createPlatformView(request, true); + let platformView: PlatformView = this.createPlatformView(request); let textureId = this.configureForTextureLayerComposition(platformView, request); this.viewIdWithTextureId.set(request.viewId, textureId); return textureId; @@ -272,7 +259,7 @@ export default class PlatformViewsController implements PlatformViewsAccessibili let embeddedView: WrappedBuilder<[Params]> = platformView.getView(); if (embeddedView == null) { - throw new Error("PlatformView#getView() returned null, but an dynamic view reference was expected."); + throw new Error("PlatformView#getView() returned null, but an WrappedBuilder reference was expected."); } @@ -301,14 +288,11 @@ export default class PlatformViewsController implements PlatformViewsAccessibili let wrappedBuilder: WrappedBuilder<[Params]> = platformView.getView(); this.flutterView?.setWrappedBuilder(wrappedBuilder); this.flutterView?.setPlatformView(platformView); - // this.flutterView!.getPlatformViewSize().width = request.logicalWidth; - // this.flutterView!.getPlatformViewSize().height = request.logicalHeight; - // this.flutterView!.getPlatformViewSize().direction = request.direction; - let link1: SubscribedAbstractProperty = AppStorage.link('nodeWidth'); - let link2: SubscribedAbstractProperty = AppStorage.link('nodeHeight'); - link1.set(request.logicalWidth); - link2.set(request.logicalHeight); - this.flutterView!.getEmbeddingNodeController().setRenderOption(platformView, surfaceId, NodeRenderType.RENDER_TYPE_TEXTURE, 300, 500, request.direction); + let physicalWidth: number = this.toPhysicalPixels(request.logicalWidth); + let physicalHeight: number = this.toPhysicalPixels(request.logicalHeight); + this.nodeWidthLink.set(physicalWidth); + this.nodeHeightLink.set(physicalHeight); + this.flutterView!.getEmbeddingNodeController().setRenderOption(platformView, surfaceId, NodeRenderType.RENDER_TYPE_TEXTURE, request.direction); this.flutterView!.getEmbeddingNodeController().rebuild(); Log.i(TAG, "Create platform view success"); -- Gitee