From 20d4978c1ba1fa84e8845e86711810fe296568b4 Mon Sep 17 00:00:00 2001 From: Jarvis <10179211+JiaVVis@user.noreply.gitee.com> Date: Mon, 19 Aug 2024 13:39:02 +0000 Subject: [PATCH] =?UTF-8?q?gesture=E5=B1=9E=E6=80=A7=E7=94=B1=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E5=8F=82=E6=95=B0checkMouseWheel=E6=9D=A5=E6=8E=A7?= =?UTF-8?q?=E5=88=B6--=E8=A7=A3=E5=86=B3=E5=A4=9A=E5=BC=95=E6=93=8E?= =?UTF-8?q?=E4=B8=8B=E6=BB=9A=E5=8A=A8=E4=B8=8D=E5=93=8D=E5=BA=94=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: Jarvis <10179211+JiaVVis@user.noreply.gitee.com> --- .../main/ets/embedding/ohos/FlutterPage.ets | 128 +++++++++++++----- 1 file changed, 93 insertions(+), 35 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 390bd370c6..4e5cdbf062 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 @@ -31,47 +31,58 @@ export struct FlutterPage { @Builder doNothingBuilder() {} @BuilderParam splashScreenView: () => void = this.doNothingBuilder; - @State showSplashScreen: boolean = true; - - @State checkFullScreen: boolean = true; - @State checkKeyboard: boolean = true; - @State checkGesture: boolean = true; - - @StorageLink('nodeWidth') storageLinkWidth: number = 0; - @StorageLink('nodeHeight') storageLinkHeight: number = 0; - - @State rootDvModel: DVModelChildren | undefined = undefined - - @State isNeedUpdate: boolean = false; + @Builder defaultPage() { + Stack() { + ForEach(this.rootDvModel!!, (child: ESObject) => { + DynamicView({ + model: child as DVModel, + params: child.params, + events: child.events, + children: child.children, + customBuilder: child.builder + }) + }, (child: ESObject) => `${child.id_}`) - private flutterView?: FlutterView | null - private lastArea?: Area; - private panOption: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Up | PanDirection.Down }); - aboutToAppear() { - this.flutterView = FlutterManager.getInstance().getFlutterView(this.viewId); - this.flutterView?.addFirstFrameListener(this) + Text('') + .id('emptyFocusText' + this.viewId) + .size({ width: 0, height: 0 }) + .opacity(0) + .focusable(true) - this.flutterView?.setCheckFullScreen(this.checkFullScreen) - this.flutterView?.setCheckKeyboard(this.checkKeyboard) - this.flutterView?.setCheckGesture(this.checkGesture) + 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.Transparent) - this.rootDvModel = this.flutterView!!.getDVModel().children - getContext().eventHub.on(OHOS_FLUTTER_PAGE_UPDATE, () => { - this.isNeedUpdate = true; + if (this.showSplashScreen) { + this.splashScreenView(); + } + } + .defaultFocus(true) + .onAreaChange((oldValue: Area, newValue: Area) => { + if (!this.lastArea || oldValue.width != newValue.width + || oldValue.height != newValue.height) { + Log.d(TAG, "onAreaChange, old=" + JSON.stringify(oldValue)); + Log.d(TAG, "onAreaChange, new=" + JSON.stringify(newValue)); + this.lastArea = newValue; + this.flutterView?.onAreaChange(newValue) + } + }) + .onKeyPreIme((event: KeyEvent) => { + Log.d(TAG, "onKeyEvent " + event.type); + this.flutterView?.onKeyEvent(event); + return false; }) } - - aboutToDisappear() { - this.flutterView?.removeFirstFrameListener(this); - getContext().eventHub.off(OHOS_FLUTTER_PAGE_UPDATE) - } - - onFirstFrame() { - this.showSplashScreen = false; - } - - build() { + @Builder defaultPage() { Stack() { ForEach(this.rootDvModel!!, (child: ESObject) => { DynamicView({ @@ -136,4 +147,51 @@ export struct FlutterPage { }) ) } + @State showSplashScreen: boolean = true; + + @State checkFullScreen: boolean = true; + @State checkKeyboard: boolean = true; + @State checkGesture: boolean = true; + + @StorageLink('nodeWidth') storageLinkWidth: number = 0; + @StorageLink('nodeHeight') storageLinkHeight: number = 0; + + @State rootDvModel: DVModelChildren | undefined = undefined + + @State isNeedUpdate: boolean = false; + + private flutterView?: FlutterView | null + private lastArea?: Area; + private panOption: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Up | PanDirection.Down }); + + aboutToAppear() { + this.flutterView = FlutterManager.getInstance().getFlutterView(this.viewId); + this.flutterView?.addFirstFrameListener(this) + + this.flutterView?.setCheckFullScreen(this.checkFullScreen) + this.flutterView?.setCheckKeyboard(this.checkKeyboard) + this.flutterView?.setCheckGesture(this.checkGesture) + + this.rootDvModel = this.flutterView!!.getDVModel().children + getContext().eventHub.on(OHOS_FLUTTER_PAGE_UPDATE, () => { + this.isNeedUpdate = true; + }) + } + + aboutToDisappear() { + this.flutterView?.removeFirstFrameListener(this); + getContext().eventHub.off(OHOS_FLUTTER_PAGE_UPDATE) + } + + onFirstFrame() { + this.showSplashScreen = false; + } + + build() { + if (this.checkMouseWheel) { + this.mouseWheelPage(); + } else { + this.defaultPage(); + } + } } -- Gitee