Vibration
sunnylqm(100.00%)
本文档贡献者:Vibrates the device.
Example
- 函数组件示例
- Class组件示例
Android apps should request the
android.permission.VIBRATE
permission by adding<uses-permission android:name="android.permission.VIBRATE"/>
toAndroidManifest.xml
.
The Vibration API is implemented as a
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
call on iOS.
Reference
Methods
vibrate()
Vibration.vibrate(?pattern: number | Array<number>, ?repeat: boolean)
Triggers a vibration with a fixed duration.
On Android, the vibration duration defaults to 400 milliseconds, and an arbitrary vibration duration can be specified by passing a number as the value for the pattern
argument. On iOS, the vibration duration is fixed at roughly 400 milliseconds.
The vibrate()
method can take a pattern
argument with an array of numbers that represent time in milliseconds. You may set repeat
to true to run through the vibration pattern in a loop until cancel()
is called.
On Android, the odd indices of the pattern
array represent the vibration duration, while the even ones represent the separation time. On iOS, the numbers in the pattern
array represent the separation time, as the vibration duration is fixed.
参数:
Name | Type | Required | Description | Platform |
---|---|---|---|---|
pattern | number | No | Vibration duration in milliseconds. Defaults to 400 ms. | Android |
pattern | Array of numbers | No | Vibration pattern as an array of numbers in milliseconds. | Android, iOS |
repeat | boolean | No | Repeat vibration pattern until cancel(), default to false. | Android, iOS |
cancel()
Vibration.cancel();
Call this to stop vibrating after having invoked vibrate()
with repetition enabled.