NativeScript Vibrate
A vibrate NativeScript plugin for Android and iOS
Installation
Run the following command from the root of your project:
$ tns plugin add nativescript-vibrate
This command automatically installs the necessary files, as well as stores nativescript-texttospeech as a dependency in your project's package.json file.
Due to a current open issue with NativeScript, #669, the plugin needs to be added before adding any platforms with the tns add platform
command.
Permissions
Android
To use the vibrate functionality on Android your app must request permission access the vibrator. The plugin automatically adds the required permission shown below for you so you don't need to worry about editing the Android Manifest.
<uses-permission android:name="android.permission.VIBRATE" />
Usage
To use the vibrate module you must first require()
it:
var Vibrate = require("nativescript-vibrate").Vibrate;
var vibrator = new Vibrate();
If you use Typescript, you can require it this way:
import { Vibrate } from 'nativescript-vibrate';
let vibrator = new Vibrate();
After you have a reference to the module you can then call its vibrate(milliseconds)
method.
vibrator.vibrate(2000);
Notes
iOS
There is no API to vibrate for a specific amount of time, so it will vibrate for the default no matter what (the duration is ignored).
Development setup
For easier development and debugging purposes continue with the following steps:
- Open a command prompt/terminal, navigate to
src
folder and run npm run demo.ios
or npm run demo.android
to run the demo. - Open another command prompt/terminal, navigate to
src
folder and run npm run plugin.tscwatch
to watch for file changes in the plugin.
Now go and make a change to the plugin. It will be automatically applied to the demo project.
Unittesting
Open demo/app/tests/tests.js
and adjust its contents so the tests become meaningful in the context of the plugin and its features.
You can read more about this topic here.
Once you're ready to test the plugin's API go to src
folder and execute one of these commands:
npm run test.ios
npm run test.android
Clean plugin and demo files
Sometimes you may need to wipe away the node_modules
and demo/platforms
folders to reinstall them fresh.
- Run
npm run clean
to wipe those clean then you can can run npm i
to install fresh dependencies.