繁体   English   中英

如何在 ios 上获得半毫秒的振动与 expo 本机反应?

[英]How to get half a millisecond vibration on ios in react native with expo?

如何在 ios 上获得半毫秒的振动与 expo 本机反应? 类似于您在手机键盘上打字时的振动。 我似乎用这个Vibration.vibrate([0, 0, 0, 30])在 android 上得到了它,但它在 ios 上没有复制相同的内容

这是下面的代码

<TouchableOpacity onPress={() => Vibration.vibrate([0, 0, 0, 30])} style={{ marginTop: 100, alignItems: 'center' }}>
        <Text style={{ fontSize: 20 }}>Vibrate</Text>
</TouchableOpacity>

react-native 中的振动是特定于平台的。

import { Vibration, Platform } from "react-native";

// vibrate is platform specific. default is 400ms
  const vibrate = () => {
    if (Platform.OS === "ios") {
      // this logic works in android too. you could omit the else statement
      const interval = setInterval(() => Vibration.vibrate(), 1000);
      // it will vibrate for 5 seconds
      setTimeout(() => clearInterval(interval), 5000);
    } else {
    
      Vibration.vibrate(5000);
    }
  };

然后将其用作回调:

<TouchableOpacity onPress={vibrate} style={{ marginTop: 100, alignItems: 'center' }}>
        <Text style={{ fontSize: 20 }}>Vibrate</Text>
</TouchableOpacity>

react-native-haptic-feedback makes the thing on iOS as mentioned by Medet Tleukabiluly here's the link: https://github.com/junina-de/react-native-haptic-feedback/ but unfortunately it didn't work on Android为了我。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM