npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-hapticlabs

v0.4.1

Published

A package to play back haptics developed using Hapticlabs Studio

Downloads

50

Readme

react-native-hapticlabs

A package to play back haptics developed using Hapticlabs Studio. See Hapticlabs for more information.

Installation

npm install react-native-hapticlabs

Usage

Play haptics on Android:

import { playAndroidHaptics, playHLA, playOGG } from 'react-native-hapticlabs';

// Automatically selects the haptic feedback based on the device's haptic support level
playAndroidHaptics(
  'Android samples/Double click with audio-Simple pattern-Single Vibration'
).then(() => {
  console.log('Android haptics played');
});

// Plays back the HLA file and associated audio files
playHLA('Android samples/Double click with audio/lvl2/main.hla').then(() => {
  console.log('HLA played');
});

// Plays back the OGG file with haptic feedback if the device supports it
playOGG('Android samples/Simple pattern/lvl3/main.ogg').then(() => {
  console.log('OGG played');
});

Play haptics on iOS:

import {
  androidHapticSupportLevel,
  playAHAP,
  playAndroidHaptics,
  playHLA,
  playOGG,
} from 'react-native-hapticlabs';
import RNFS from 'react-native-fs';

// Plays back the AHAP files and associated other AHAP and audio files
playAHAP(RNFS.MainBundlePath + '/AHAP/9Bit.ahap').then(() => {
  console.log('Played ahap');
});

Play haptics on both Android and iOS:

import { playHaptics } from 'react-native-hapticlabs';
import RNFS from 'react-native-fs';

// Plays back an AHAP file on iOS and an HLA or OGG file on Android
playHaptics({
  iosPath: RNFS.MainBundlePath + '/AHAP/button.ahap',
  androidPath: 'Android samples/button',
}).then(() => {
  console.log('Played haptics');
});

Functions

playHLA

function playHLA(path: string): Promise<void>;

This command will play an HLA file from the specified path, including corresponding audio files.

Note: This command is only supported on Android.

Parameters:

  • path The path to the HLA file. This can be a path relative to the assets directory or a fully qualified path.

Returns:

A promise that resolves when the HLA file has been played.

playOGG

function playOGG(path: string): Promise<void>;

This command will play an OGG file from the specified path, including encoded haptic feedback.

If the device's haptic support level is less than 3, the device will play the audio file without haptic feedback. To automatically select adequate haptic feedback for the device, use playAndroidHaptics instead.

Note: This command is only supported on Android.

Parameters:

  • path The path to the OGG file. This can be a path relative to the assets directory or a fully qualified path.

Returns:

A promise that resolves when the OGG file has been played.

playAndroidHaptics

function playAndroidHaptics(directoryPath: string): Promise<void>;

This command will play a haptic pattern from the specified directoryPath.

Depending on the device's haptic support level, different haptic feedback will be played. For instance, if the device's haptic support level is 3, the device will play the haptic pattern specified in the lvl3 subdirectory. If the device's haptic support level is 0, no haptic feedback will be played.

Make sure that the directory follows the following structure:

directoryPath
├── lvl1
│   └── main.hla
├── lvl2
│   └── main.hla
└── lvl3
    └── main.ogg

Note: This command is only supported on Android.

Parameters:

  • directoryPath The path to the haptic pattern directory. This can be a path relative to the assets directory or a fully qualified path.

Returns:

A promise that resolves when the haptic pattern and accompanying audio signals have been played.

androidHapticSupportLevel

const androidHapticSupportLevel: 0 | 1 | 2 | 3;

The device's haptic support level. This value is a number between 0 and 3, where:

  • 0: The device does not support haptics.
  • 1: The device supports on / off haptic feedback.
  • 2: The device supports amplitude control haptic feedback.
  • 3: The device supports fully customizable haptic feedback.

Note: This value is only supported on Android.

playAHAP

function playAHAP(path: string): Promise<void>;

This command will play an AHAP file from the specified path, including corresponding AHAP files and audio files.

Note: This command is only supported on iOS.

Parameters:

  • path The path to the AHAP file.

Returns:

A promise that resolves when the AHAP file has been played.

playHaptics

function playHaptics(options: {
  iosPath: string;
  androidPath: string;
}): Promise<void>;

This command will play an AHAP file on iOS and an HLA or OGG file on Android. Internally, it will call playAHAP on iOS and playAndroidHaptics on Android.

Parameters:

  • options An object containing the paths to the AHAP file on iOS and the HLA or OGG file on Android:

    • iosPath The path to the AHAP file for iOS. See playAHAP for more information.
    • androidPath The path to the haptic pattern directory for Android. See playAndroidHaptics for more information.

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library