From 1beb3ed96cd90b872988591d79c5a1de28f5617c Mon Sep 17 00:00:00 2001 From: yihuiyang Date: Wed, 8 Nov 2023 10:23:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A9=AC=E8=BE=BE=E9=9C=87?= =?UTF-8?q?=E5=8A=A8=E6=97=B6=E9=97=B4=E6=A8=A1=E6=8B=9F=E9=9C=87=E5=8A=A8?= =?UTF-8?q?=E5=BC=BA=E5=BA=A6=20=E8=B0=83=E7=94=A8HapticFeedback.vibrate?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E9=85=8D=E7=BD=AEvibrate=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yihuiyang --- .../engine/systemchannels/PlatformChannel.ets | 15 +++++---------- .../src/main/ets/plugin/PlatformPlugin.ets | 16 ++++++++-------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/PlatformChannel.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/PlatformChannel.ets index e2ff4f357a..615dac78fb 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/PlatformChannel.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/PlatformChannel.ets @@ -119,17 +119,12 @@ export default class PlatformChannel { HapticFeedbackType.HEAVY_IMPACT, HapticFeedbackType.SELECTION_CLICK ]; - for (let i = 0; i < feedbackTypes.length; i++) { - let feedbackType: string = feedbackTypes[i]; - if ( - (HapticFeedbackType[feedbackType] == encodedName) || - (HapticFeedbackType[feedbackType] == null && encodedName == null) - ) { - return HapticFeedbackType[feedbackType]; - } + if (feedbackTypes.includes(encodedName as HapticFeedbackType)) { + return encodedName as HapticFeedbackType; + } else { + Log.e(PlatformChannel.TAG, "No such HapticFeedbackType:" + encodedName); + return HapticFeedbackType.STANDARD; } - Log.e(PlatformChannel.TAG, "No such HapticFeedbackType:" + encodedName); - return HapticFeedbackType.STANDARD; } getClipboardContentFormatFromValue(encodedName: string): ClipboardContentFormat { diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/PlatformPlugin.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/PlatformPlugin.ets index 2fa7cbf589..8c757c2a47 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/PlatformPlugin.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/PlatformPlugin.ets @@ -107,24 +107,24 @@ class PlatformPluginCallback implements PlatformMessageHandler { vibrateHapticFeedback(feedbackType: HapticFeedbackType) { switch (feedbackType) { case HapticFeedbackType.STANDARD: - vibrator.startVibration({ type: 'time', duration: 100 }, + vibrator.startVibration({ type: 'time', duration: 75 }, { id: 0, usage: 'touch' }); break; case HapticFeedbackType.LIGHT_IMPACT: - vibrator.startVibration({ type: 'time', duration: 100 }, - { id: 0, usage: 'notification' }).then(); + vibrator.startVibration({ type: 'time', duration: 25 }, + { id: 0, usage: 'touch' }); break; case HapticFeedbackType.MEDIUM_IMPACT: - vibrator.startVibration({ type: 'time', duration: 100 }, - { id: 0, usage: 'ring' }); + vibrator.startVibration({ type: 'time', duration: 150 }, + { id: 0, usage: 'touch' }); break; case HapticFeedbackType.HEAVY_IMPACT: - vibrator.startVibration({ type: 'time', duration: 100 }, - { id: 0, usage: 'alarm' }); + vibrator.startVibration({ type: 'time', duration: 300 }, + { id: 0, usage: 'touch' }); break; case HapticFeedbackType.SELECTION_CLICK: vibrator.startVibration({ type: 'time', duration: 100 }, - { id: 0, usage: 'physicalFeedback' }); + { id: 0, usage: 'touch' }); break; } } -- Gitee