已合并
fix: Inconsistent with Android in repeated vibration mode #1069
zheng-jun-feng创建于 2025年5月28日
fix: Inconsistent with Android in repeated vibration mode #1069
已合并
zheng-jun-feng创建于 2025年5月28日
从已删除 :master合入到CPF-RN/ohos_react_nativemaster
zheng-jun-feng
zheng-jun-feng成员
2025年5月28日

描述

修复72重复震动模式与安卓不一致的问题

变更日志

测试步骤

demo:

import React, { useState, useEffect } from 'react';
import { StyleSheet, Button, View, Vibration, Text } from 'react-native';

const App = () => {
  const [vibrationPattern] = useState([5000, 3000, 5000, 1000]);   
  // 当重复震动开始第二轮之后的现象:
  // 72        第三个数振动,第一,二,四个数之和为间隔     
  // 安卓    第一个数间隔,第二个数震动,第三个数间隔,第四个数震动
  const [time, setTime] = useState(0);
  const [isVibrating, setIsVibrating] = useState(false);

  useEffect(() => {
    let interval = null;

    if (isVibrating) {
      interval = setInterval(() => {
        setTime(prevTime => prevTime + 1);
      }, 1000);
    } else {
      clearInterval(interval);
      setTime(0); // 重置时间
    }

    return () => clearInterval(interval);
  }, [isVibrating]);

  const startVibrationWithPattern = () => {
    Vibration.vibrate(vibrationPattern, true);
    setIsVibrating(true);
  };

  const stopVibrationAndResetTimer = () => {
    Vibration.cancel();
    setIsVibrating(false);
  };

  const vibrateOnce = () => {
    Vibration.vibrate(400);
  };

  const vibrateWithPattern = () => {
    Vibration.vibrate(vibrationPattern, false);
  };

  return (
    <View style={styles.container}>
      {/* 秒表 */}
      <Text style={styles.timerText}>{`时间: ${Math.floor(time / 60)}:${(time % 60).toString().padStart(2, '0')}`}</Text>

      {/* 震动控制 */}
      <Button title="震动0.4秒" onPress={vibrateOnce} />
      
      <View style={styles.buttonSpacer} />

      <Button title="按模式震动" onPress={vibrateWithPattern} />

      <View style={styles.buttonSpacer} />

      <Button title="重复震动模式" onPress={startVibrationWithPattern} />

      <View style={styles.buttonSpacer} />

      <Button title="取消震动" onPress={stopVibrationAndResetTimer} />
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
  buttonSpacer: {
    marginVertical: 15,
  },
  timerText: {
    fontSize: 24,
    marginBottom: 20,
  }
});

export default App;

合入前自检

  • [] 本PR已经在77分支开启PR或不需要在77分支合入
    • 如需合入77分支,PR地址:
likedislike
Pull Request已成功合入, 合并人@huangyouhua
(感谢 zheng-jun-feng 的贡献)
openharmony_ci
openharmony_ci成员
2025年5月28日 评论:

感谢提交 Pull Requests!
Thanks for submitting a pull request.

likedislike
openharmony_ciopenharmony_ci成员
2025年5月28日 删除了label:dco检查失败
openharmony_ciopenharmony_ci成员
2025年5月28日 添加了label:dco检查成功
zheng-jun-fengzheng-jun-feng成员
2025年5月28日 关联了issue:fix: Inconsistent with Android in repeated vibration mode
zheng-jun-feng
zheng-jun-feng成员
2025年5月28日 评论:

start build

likedislike
openharmony_ci
openharmony_ci成员
2025年5月28日 评论:

首次触发
门禁构建开始,包含静态检查、代码编译【ohos_react_native_master编译】,预计在60分钟内完成,门禁结果会同步发送到注册邮箱。您可以通过如下链接跟踪门禁进展:http://dcp.openharmony.cn/workbench/cicd/detail/6836839b64650f998bdaee2e/runlist

likedislike
openharmony_ciopenharmony_ci成员
2025年5月28日 删除了label:编译失败
openharmony_ciopenharmony_ci成员
2025年5月28日 添加了label:编译成功
openharmony_ciopenharmony_ci成员
2025年5月28日 添加了label:静态检查成功
openharmony_ciopenharmony_ci成员
2025年5月28日 通过测试
openharmony_ci
openharmony_ci成员
2025年5月28日 评论:

代码门禁通过
您可以通过如下链接查看门禁报告:http://dcp.openharmony.cn/workbench/cicd/detail/6836839b64650f998bdaee2e/runlist

静态检查:

# check type result report
1 codeCheck pass >>>

编译测试:
# Device build result package
1 ohos_react_native_master success >>>

likedislike
huangyouhua
huangyouhua2025年5月28日进行代码检视1
react-native-harmony/Libraries/Vibration/Vibration.harmony.js
已过期
@@ -41,7 +41,6 @@ function vibrateScheduler(
4141 if (repeat) {
4242 // $FlowFixMe[reassign-const]
4343 nextIndex = 0;
44- shouldVibrate = true;
huangyouhua
huangyouhua2025年5月28日评论:

确认pattern数组长度为奇数时的场景,是否满足官网规格的描述

likedislike
zheng-jun-fengzheng-jun-feng成员
2025年5月28日 测试状态已重置,测试人: openharmony_ci
zheng-jun-fengzheng-jun-feng成员
2025年5月28日 强制推送  1 个提交:0f50e60a-fix:Inconsistent with Android in repeated vibration mode
openharmony_ciopenharmony_ci成员
2025年5月28日 删除了label:静态检查成功
openharmony_ciopenharmony_ci成员
2025年5月28日 删除了label:编译成功
openharmony_ci
openharmony_ci成员
2025年5月28日 评论:

代码有更新,重置PR验证状态

likedislike
zheng-jun-fengzheng-jun-feng成员
2025年5月28日 解决了最后一个问题
openharmony_ci
openharmony_ci成员
2025年5月28日 评论:

感谢提交 Pull Requests!
Thanks for submitting a pull request.

likedislike
openharmony_ciopenharmony_ci成员
2025年5月28日 删除了label:dco检查失败
zheng-jun-feng
zheng-jun-feng成员
2025年5月28日 评论:

start build

likedislike
openharmony_ci
openharmony_ci成员
2025年5月28日 评论:

本地或库上代码有更新,全量重新构建,重置所有关联PR的验证状态
门禁构建开始,包含静态检查、代码编译【ohos_react_native_master编译】,预计在60分钟内完成,门禁结果会同步发送到注册邮箱。您可以通过如下链接跟踪门禁进展:http://dcp.openharmony.cn/workbench/cicd/detail/6836fe5764650f998b7e3767/runlist

likedislike
openharmony_ciopenharmony_ci成员
2025年5月28日 删除了label:编译失败
openharmony_ciopenharmony_ci成员
2025年5月28日 添加了label:编译成功
openharmony_ciopenharmony_ci成员
2025年5月28日 添加了label:静态检查成功
openharmony_ciopenharmony_ci成员
2025年5月28日 通过测试
openharmony_ci
openharmony_ci成员
2025年5月28日 评论:

代码门禁通过
您可以通过如下链接查看门禁报告:http://dcp.openharmony.cn/workbench/cicd/detail/6836fe5764650f998b7e3767/runlist

静态检查:

# check type result report
1 codeCheck pass >>>

编译测试:
# Device build result package
1 ohos_react_native_master success >>>

likedislike
huangyouhuahuangyouhua
2025年5月28日 添加了 squash commit 备注:fix: Inconsistent with Android in repeated vibration mode
zheng-jun-fengzheng-jun-feng成员
2025年5月29日 将linhandev设为评审人
linhandevlinhandev
2025年5月29日 通过了评审
huangyouhuahuangyouhua
2025年5月29日 通过审查
huangyouhuahuangyouhua
2025年5月29日 关闭了关联的issue
huangyouhuahuangyouhua
2025年5月29日 合入了pull request