diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/TouchEventProcessor.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/TouchEventProcessor.ets index e6100e08335ae582e9a048471e017163ba749c3a..582d2dca293534c70c87fe75256877b07891ecf8 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/TouchEventProcessor.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/TouchEventProcessor.ets @@ -257,6 +257,10 @@ export default class TouchEventProcessor { //如果flutter端判断当前platformView是可点击的,则将事件分发出去 let touchEvent = TouchEventProcessor.getInstance().constureCustomTouchEvent(strings, top, left); let nodeController = params['nodeController'] as EmbeddingNodeController; + // 保证platformviewcontroller.ets的onTouch的down属性正常结束 + if (touchEvent.type === TouchType.Up) { + params['down'] === false; + } nodeController.postEvent(touchEvent) } else { //如果触摸事件为OH_NATIVEXCOMPONENT_DOWN=0,且只有一个手指,说明是下一次点击了,这时候需要清空上一次的数据 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 5c929c84186bf8f3e27de4978f6e83107b079e9e..45c4177ae286ebcf583a6b14fef02292f91e36db 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 @@ -65,6 +65,20 @@ class DVModelJson { this.build = build; } } +enum TouchEventType { + /// Action code for when a primary pointer touched the screen. + ACTION_DOWN = 0, + /// Action code for when a primary pointer stopped touching the screen. + ACTION_UP = 1, + /// Action code for when the event only includes information about pointer movement. + ACTION_MOVE = 2, + /// Action code for when a motion event has been canceled. + ACTION_CANCEL = 3, + /// Action code for when a secondary pointer touched the screen. + ACTION_POINTER_DOWN = 5, + /// Action code for when a secondary pointer touched the screen. + ACTION_POINTER_UP = 6, +} const TAG = "PlatformViewsController" @@ -203,12 +217,12 @@ export default class PlatformViewsController implements PlatformViewsAccessibili let dvModel = viewWrapper.getDvModel() let params = dvModel.getLayoutParams() as Record; //接收到点击类型为down的时候 - if (touch.action == 0) { + if (touch.action === TouchEventType.ACTION_DOWN) { //将当前点击状态设置为true params['down'] = true //首次收到触控点击类型为 OH_NATIVEXCOMPONENT_DOWN ,则将存到列表中的事件分发出去 let touchEventArray: Array | undefined = params['touchEvent'] as Array - if (touchEventArray != undefined) { + if (touchEventArray !== undefined) { let nodeController = params['nodeController'] as EmbeddingNodeController; for (let it of touchEventArray) { nodeController.postEvent(it) @@ -216,9 +230,9 @@ export default class PlatformViewsController implements PlatformViewsAccessibili //首次执行完之后,将列表数据置空 params['touchEvent'] = undefined } - //当前接收的事件类型为up的时候 - } else if (touch.action == 1) { - //手指抬起之后,将当前点击状态设置为false。测试了一下,多个手指突然抬起,最后返回的状态也是1 + //当前接收的事件类型为up的时候 + } else if (touch.action === TouchEventType.ACTION_UP) { + //手指抬起之后,将当前点击状态设置为false。测试了一下,多个手指突然抬起,最后返回的状态也是ACTION_UP //所以,这边就以状态抬起,代表当前用户不点击platformview了 params['down'] = false }