Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
react-native-haptic-feedback
Advanced tools
The react-native-haptic-feedback package provides a way to trigger haptic feedback (vibration) on iOS and Android devices. This can be used to enhance user experience by providing tactile feedback for various actions within a React Native application.
Triggering Haptic Feedback
This feature allows you to trigger haptic feedback using the `trigger` method. The example demonstrates how to trigger a light impact haptic feedback when a button is pressed.
import React from 'react';
import { Button, View } from 'react-native';
import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
const App = () => {
const triggerHapticFeedback = () => {
const options = {
enableVibrateFallback: true,
ignoreAndroidSystemSettings: false
};
ReactNativeHapticFeedback.trigger('impactLight', options);
};
return (
<View>
<Button title="Trigger Haptic Feedback" onPress={triggerHapticFeedback} />
</View>
);
};
export default App;
Customizing Haptic Feedback
This feature allows you to customize the type of haptic feedback. The example shows how to trigger a 'notificationSuccess' haptic feedback, which can be used to indicate a successful action.
import React from 'react';
import { Button, View } from 'react-native';
import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
const App = () => {
const triggerCustomHapticFeedback = () => {
const options = {
enableVibrateFallback: true,
ignoreAndroidSystemSettings: false
};
ReactNativeHapticFeedback.trigger('notificationSuccess', options);
};
return (
<View>
<Button title="Trigger Custom Haptic Feedback" onPress={triggerCustomHapticFeedback} />
</View>
);
};
export default App;
The react-native-vibration package provides a simple API to trigger vibration on both iOS and Android devices. Unlike react-native-haptic-feedback, it does not offer different types of haptic feedback but focuses on basic vibration functionality.
The expo-haptics package is part of the Expo ecosystem and provides a comprehensive set of haptic feedback options. It offers more granular control over haptic feedback types compared to react-native-haptic-feedback and is well-integrated with the Expo framework.
$ npm install react-native-haptic-feedback --save
$ react-native link react-native-haptic-feedback
Libraries
➜ Add Files to [your project's name]
node_modules
➜ react-native-haptic-feedback
and add RNReactNativeHapticFeedback.xcodeproj
libRNReactNativeHapticFeedback.a
to your project's Build Phases
➜ Link Binary With Libraries
Cmd+R
)<android/app/src/main/java/[...]/MainApplication.java
import com.reactlibrary.RNReactNativeHapticFeedbackPackage;
to the imports at the top of the filenew RNReactNativeHapticFeedbackPackage()
to the list returned by the getPackages()
methodandroid/settings.gradle
:
include ':react-native-haptic-feedback'
project(':react-native-haptic-feedback').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-haptic-feedback/android')
android/app/build.gradle
:
compile project(':react-native-haptic-feedback')
import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
ReactNativeHapticFeedback.trigger('impactLight');
Method | Description |
---|---|
trigger (method) | Trigger haptic feedback. Possible values are "selection", "impactLight", "impactMedium", "impactHeavy", "notificationSuccess", "notificationWarning", "notificationError" (default: "selection") |
FAQs
Basic haptic feedback for iOS and android
The npm package react-native-haptic-feedback receives a total of 163,111 weekly downloads. As such, react-native-haptic-feedback popularity was classified as popular.
We found that react-native-haptic-feedback demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.