From ddaafddf931763fd0d0649bcd1bd75db8916ab21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B7=B1=E8=93=9D?= Date: Fri, 19 Jul 2024 11:41:05 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E4=BA=8B=E4=BB=B6=E5=88=86?= =?UTF-8?q?=E5=8F=91=E9=97=AE=E9=A2=98=EF=BC=8C=E5=B0=A4=E5=85=B6=E6=98=AF?= =?UTF-8?q?=E5=BC=80=E5=90=AF=E5=A4=9A=E5=B1=82PlatformView=EF=BC=8C?= =?UTF-8?q?=E7=82=B9=E5=87=BB=E9=A1=B6=E9=83=A8platformview=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E4=BC=9A=E5=88=86=E5=8F=91=E5=BA=95=E9=83=A8=E7=9A=84?= =?UTF-8?q?platformview=E4=B8=8A=E3=80=82=20Signed-off-by:=20zhouyi=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/ets/embedding/engine/FlutterNapi.ets | 35 ++++++++++++++----- .../platform/PlatformViewsController.ets | 27 ++++++++++++-- 2 files changed, 51 insertions(+), 11 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterNapi.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterNapi.ets index e738299052..5bf0f60f64 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterNapi.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterNapi.ets @@ -30,6 +30,7 @@ import FlutterManager from '../ohos/FlutterManager'; import deviceInfo from '@ohos.deviceInfo'; import TouchEventProcessor from '../ohos/TouchEventProcessor'; import { EmbeddingNodeController } from '../ohos/EmbeddingNodeController'; +import { CustomTouchEvent } from '../../plugin/platform/CustomTouchEvent'; const TAG = "FlutterNapi"; @@ -404,17 +405,33 @@ export default class FlutterNapi { /** Dispatch Touch Event */ onTouchEvent(strings: Array): void { - Log.d(TAG, "called onTouchEvent "); FlutterManager.getInstance().getFlutterViewList().forEach((value) => { - let length = value.getDVModel().children.length; + let length = value.getDVModel().children.length for (let index = length - 1; index >= 0; index--) { - let dvModel = value.getDVModel().children[index]; - let params = dvModel.getLayoutParams(); - let params2 = params as Record; - let nodeController = params2['nodeController'] as EmbeddingNodeController; - let left = params2['left'] as number ?? 0; - let top = params2['top'] as number ?? 0; - nodeController.postEvent(TouchEventProcessor.getInstance().constureCustomTouchEvent(strings, top, left)); + let dvModel = value.getDVModel().children[index] + let params = dvModel.getLayoutParams() as Record; + let left = params['left'] as number ?? 0; + let top = params['top'] as number ?? 0; + let down = params['down'] as boolean ?? false; + if (down) { + //如果flutter端判断当前platformView是可点击的,则将事件分发出去 + let touchEvent = TouchEventProcessor.getInstance().constureCustomTouchEvent(strings, top, left); + let nodeController = params['nodeController'] as EmbeddingNodeController; + nodeController.postEvent(touchEvent) + } else if (strings[6] == '0' && !down) { + //如果触摸事件为OH_NATIVEXCOMPONENT_DOWN=0类型,且在flutter端还没判断当前view是否处于点击区域内,则 + //将点击事件存储在list列表中。 + let touchEvent = TouchEventProcessor.getInstance().constureCustomTouchEvent(strings, top, left); + let array: Array | undefined = params['touchEvent'] as Array + if (array == undefined) { + array = [] + params['touchEvent'] = array + } + array.push(touchEvent) + } else if (strings[0] == '1' && strings[6] == '1') { + //如果当前触控手指的个数为1个,且当前点击类型为OH_NATIVEXCOMPONENT_UP,则清空列表数据 + params['touchEvent'] = undefined + } } }); } 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 78021254cc..27c59234a5 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 @@ -190,8 +190,31 @@ export default class PlatformViewsController implements PlatformViewsAccessibili } onTouch(touch: PlatformViewTouch): void { - console.log("nodeController onTouch:do nothing") - // do nothing + let viewWrapper: undefined | PlatformViewWrapper = this.viewWrappers.get(touch.viewId) + if (viewWrapper != undefined) { + let dvModel = viewWrapper.getDvModel() + let params = dvModel.getLayoutParams() as Record; + //接收到点击类型为down的时候 + if (touch.action == 0) { + //将当前点击状态设置为true + params['down'] = true + //首次收到触控点击类型为 OH_NATIVEXCOMPONENT_DOWN ,则将存到列表中的事件分发出去 + let touchEventArray: Array | undefined = params['touchEvent'] as Array + if (touchEventArray != undefined) { + let nodeController = params['nodeController'] as EmbeddingNodeController; + for (let it of touchEventArray) { + nodeController.postEvent(it) + } + //首次执行完之后,将列表数据置空 + params['touchEvent'] = undefined + } + //当前接收的事件类型为up的时候 + } else if (touch.action == 1) { + //手指抬起之后,将当前点击状态设置为false。测试了一下,多个手指突然抬起,最后返回的状态也是1 + //所以,这边就以状态抬起,代表当前用户不点击platformview了 + params['down'] = false + } + } } setDirection(viewId: number, direction: Direction): void { -- Gitee