Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
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.
Thanks to all the amazing contributors for their support.
Made with contrib.rocks.
Install the react-native-haptic-feedback
package using npm or yarn:
$ npm install react-native-haptic-feedback --save # or use $ yarn add react-native-haptic-feedback
:information_source: Note: Starting from React Native version 0.60, native modules are auto-linked. For more details, refer to the official documentation.
For React Native 0.60 and above, manual linking is generally unnecessary. Auto-linking handles the process automatically.
If you're using an older React Native version or face issues with auto-linking, follow these manual linking steps:
$ react-native link react-native-haptic-feedback
$ cd ios && pod install
If you encounter issues with the previous step on iOS, clean up and reinstall the dependencies using these commands:
$ rm -rf ios/Pods && rm -rf ios/build && cd ios && pod install && cd ../
$ rm -rf node_modules && rm yarn.lock
$ yarn install # or use $ npm install
Open Your Project in Xcode: Launch Xcode and navigate to your project in the project navigator.
Add RNReactNativeHapticFeedback Project: Right-click on the "Libraries" folder in the project navigator and select "Add Files to [your project's name]". Locate RNReactNativeHapticFeedback.xcodeproj
in your project's node_modules
directory and add it.
Navigate to Project Settings: In Xcode, select your project from the project navigator to access project settings.
Select App Target: Under the "Targets" section, choose the target corresponding to your app.
Link Binary With Libraries: Go to the "Build Phases" tab and expand the "Link Binary With Libraries" section.
Add Library: Click the "+" button to add a library.
Add libRNReactNativeHapticFeedback.a: From the list of libraries, select libRNReactNativeHapticFeedback.a
and add it.
Run Your Project: Press Cmd+R
to build and run your project in the iOS simulator or on a connected device.
Configure MainApplication.java: Open android/app/src/main/java/[...]/MainApplication.java
.
import com.mkuczera.RNReactNativeHapticFeedbackPackage;
Modify settings.gradle: Append the following lines to android/settings.gradle
:
include ':react-native-haptic-feedback'
project(':react-native-haptic-feedback').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-haptic-feedback/android')
To use the library, import it in your JavaScript file:
import ReactNativeHapticFeedback from "react-native-haptic-feedback";
// Optional configuration
const options = {
enableVibrateFallback: true,
ignoreAndroidSystemSettings: false,
};
// Trigger haptic feedback
ReactNativeHapticFeedback.trigger("impactLight", options);
Alternatively, you can use the named import:
import { trigger } from "react-native-haptic-feedback";
// Optional configuration
const options = {
enableVibrateFallback: true,
ignoreAndroidSystemSettings: false,
};
// Trigger haptic feedback
trigger("impactLight", options);
trigger(method, options)
Use this method to trigger haptic feedback.
Argument | Description |
---|---|
method | Specifies the type of haptic feedback. See the list of available methods below. |
options.enableVibrateFallback | :iphone: iOS only. If haptic feedback is unavailable (iOS < 10 OR Device < iPhone6s), vibrate with default method (heavy 1s) (default: false). |
options.ignoreAndroidSystemSettings | :android: Android only. If haptic is disabled in the Android system settings, this allows ignoring the setting and triggering haptic feedback. (default: false). |
Here's an overview of the available methods and their compatibility:
Method | Android | iOS |
---|---|---|
impactLight | ✅ | ✅ |
impactMedium | ✅ | ✅ |
impactHeavy | ✅ | ✅ |
rigid | ✅ | ✅ |
soft | ✅ | ✅ |
notificationSuccess | ✅ | ✅ |
notificationWarning | ✅ | ✅ |
notificationError | ✅ | ✅ |
selection | ❌ | ✅ |
clockTick | ✅ | ❌ |
contextClick | ✅ | ❌ |
keyboardPress | ✅ | ❌ |
keyboardRelease | ✅ | ❌ |
keyboardTap | ✅ | ❌ |
longPress | ✅ | ❌ |
textHandleMove | ✅ | ❌ |
virtualKey | ✅ | ❌ |
virtualKeyRelease | ✅ | ❌ |
effectClick | ✅ | ❌ |
effectDoubleClick | ✅ | ❌ |
effectHeavyClick | ✅ | ❌ |
effectTick | ✅ | ❌ |
If you're using version 1.6.0 or earlier, you can use this method:
import ReactNativeHapticFeedback from "react-native-haptic-feedback";
// Trigger haptic feedback with vibrate fallback
ReactNativeHapticFeedback.trigger("method", enableVibrateFallback);
Where method
can be one of: "selection", "impactLight", "impactMedium", "impactHeavy", "notificationSuccess", "notificationWarning", or "notificationError". The enableVibrateFallback
option is for iOS devices without haptic feedback support.
We recommend using the newer approach for enhanced flexibility and improved compatibility.
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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.