From 2f1b6627bd861d328086e27f29f9be9d881eeb3a Mon Sep 17 00:00:00 2001 From: yinjiacheng Date: Mon, 21 Oct 2024 12:08:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0web-view=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/component/web-view/web-view.test.js | 32 +++++------------------ pages/component/web-view/web-view.uvue | 15 +++-------- 2 files changed, 10 insertions(+), 37 deletions(-) diff --git a/pages/component/web-view/web-view.test.js b/pages/component/web-view/web-view.test.js index b20b7f5a..091e610f 100644 --- a/pages/component/web-view/web-view.test.js +++ b/pages/component/web-view/web-view.test.js @@ -44,43 +44,23 @@ describe('component-native-web-view', () => { x: 1, y: info.statusBarHeight + 44 + 1 }); - start = Date.now(); - await page.waitFor(async () => { - return (await page.data('eventTouchstart')) && (await page.data('eventTap')) || (Date.now() - start > 500); - }); + await page.waitFor(500); if(process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios') == false) { - expect(await page.data('eventTouchstart')).toEqual({ - clientX: 1, - clientY: 1 - }); - - expect(await page.data('eventTap')).toEqual({ - clientX: 1, - clientY: 1 - }); + expect(await page.data('isTouchEnable')).toBe(true); } await page.setData({ - pointerEvents: 'none' + pointerEvents: 'none', + isTouchEnable: false }); await page.waitFor(100); await program.tap({ x: 10, y: info.statusBarHeight + 44 + 10 }); - start = Date.now(); - await page.waitFor(async () => { - return (await page.data('eventTouchstart')) && (await page.data('eventTap')) || (Date.now() - start > 500); - }); + await page.waitFor(500); if(process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios') == false) { - expect(await page.data('eventTouchstart')).toEqual({ - clientX: 1, - clientY: 1 - }); - expect(await page.data('eventTap')).toEqual({ - clientX: 1, - clientY: 1 - }); + expect(await page.data('isTouchEnable')).toBe(false); } await page.setData({ pointerEvents: 'auto' diff --git a/pages/component/web-view/web-view.uvue b/pages/component/web-view/web-view.uvue index f8fb9bec..aa3210af 100644 --- a/pages/component/web-view/web-view.uvue +++ b/pages/component/web-view/web-view.uvue @@ -71,9 +71,8 @@ eventLoading: null as UTSJSONObject | null, eventLoad: null as UTSJSONObject | null, eventError: null as UTSJSONObject | null, - eventTouchstart: null as UTSJSONObject | null, - eventTap: null as UTSJSONObject | null, - pointerEvents: 'auto' + pointerEvents: 'auto', + isTouchEnable: false } }, onReady() { @@ -183,18 +182,12 @@ // 自动化测试 touchstart(event : UniTouchEvent) { if (this.autoTest) { - this.eventTouchstart = { - clientX: Math.ceil(event.touches[0].clientX), - clientY: Math.ceil(event.touches[0].clientY) - }; + isTouchEnable = event.touches[0].clientX > 0 && event.touches[0].clientY > 0; } }, tap(event : UniPointerEvent) { if (this.autoTest) { - this.eventTap = { - clientX: Math.ceil(event.clientX), - clientY: Math.ceil(event.clientY) - }; + isTouchEnable = event.clientX > 0 && event.clientY > 0; } }, getWindowInfo() : GetWindowInfoResult { -- GitLab