Giter Site home page Giter Site logo

mkuczera / react-native-haptic-feedback Goto Github PK

View Code? Open in Web Editor NEW
832.0 10.0 100.0 597 KB

React-Native Haptic Feedback for iOS with Android similar behaviour.

License: MIT License

Java 45.22% JavaScript 4.44% Objective-C 8.53% Ruby 10.47% Objective-C++ 18.92% TypeScript 12.42%
android haptic haptic-feedback ios react-native

react-native-haptic-feedback's People

Contributors

adkenyon avatar fishkingsin avatar gronxb avatar j-piasecki avatar jeremybarbet avatar kasajei avatar kylerjensen avatar lavegaa avatar lightlii avatar marcosrdz avatar matiaskorhonen avatar mkuczera avatar mriddle avatar mrloh avatar mrousavy avatar pinpong avatar plaa avatar pontusab avatar prashoon123 avatar remoblaser avatar romick2005 avatar rushatgabhane avatar rverbytskyi avatar stebogit avatar stefanmomm avatar steffeydev avatar thenishantgiri avatar uutarou10 avatar wolewicki avatar yunchanpark avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-haptic-feedback's Issues

Autolinking?

Is it possible for this package to enable React Native Autolinking? https://github.com/react-native-community/cli/blob/master/docs/autolinking.md

Not sure what would be needed for it, but since almost every package out there these days does it, it shouldn't be that hard i guess ;-)

Now we always get this error when running/building the app:
image
How do others deal with this? Just ignore it? ^_^

Edit: Android autolinking works. It only needs a few changes for iOS (podfiles). We now use this to mute the error: https://github.com/react-native-community/cli/blob/master/docs/autolinking.md#how-can-i-disable-autolinking-for-unsupported-library

I'm running react-native 0.57.8...only certain notifications work

I tested the different settings on iOS and only these work for me (iPhone6S iOS 12.1.4):

  • selection
  • impactMedium
  • notificationWarning

All settings work on Android

Testing with:

const a = ['selection', 'impactLight', 'impactMedium', 'impactHeavy', 'notificationSuccess', 'notificationWarning', 'notificationError']
const rnd_vibration = a[Math.floor(Math.random()*6)]
console.log('vibrate: ', rnd_vibration)
ReactNativeHapticFeedback.trigger(rnd_vibration, true)

type Boolean not supported by RCTConvert

Getting this error on iOS:

Unknown argument type 'Boolean'. Extend RCTConvert to support this type.

Changing the argument to type BOOL (supported by RCTConvert natively) fixes the issue.

android doc fix

Open up android/app/src/main/java/[...]/MainActivity.java

i wonder if that should be

Open up android/app/src/main/java/[...]/MainApplication.java

since i only see getPackages() in the latter.

In Samsung Galaxy phones not work

That's working and confirmed on Nexus/Pixel phones, some Huawei, etc, but isn't working for Samsung Galaxy phones and we should cover this segment.

app crashes if v.hasVibrate() == false

Caused by java.lang.NoSuchMethodError
No static method createPredefined(I)Landroid/os/VibrationEffect; in class Landroid/os/VibrationEffect;
or its super classes (declaration of 'android.os.VibrationEffect' appears in /system/framework/framework.jar)
com.mkuczera.VibrateWithCreatePredefined.apply (VibrateWithCreatePredefined.java:20)

Build Process Error "Undefined symbol: _AudioServicesPlaySystemSound"

After upgrading to v2.2.0 we are getting the following error during the build process.
Screenshot 2023-11-06 at 2 37 30 PM

We've tried manually setting up iOS based on the docs but when we attempt to add RNReactNativeHapticFeedback.xcodeproj to the Libraries and move to the next step, it does not show up when we attempt to 'Link Binary To Libraries'. libRNReactNativeHapticFeedback.a is not listed as one of the libraries available.

We can also confirm that attempting to click on RNReactNativeHapticFeedback.xcodeproj in the Library dropdown yields a 'The file could not be opened.' popup.
Screenshot 2023-11-06 at 3 01 11 PM

Screenshot 2023-11-06 at 2 55 41 PM

This error also goes away if we manually link the Audiotoolbox.framework to the package. Any help would be appreciated.

Fallback for devices that doesn't support Taptic Engine

The Taptic Engine is supported from iPhone 6S. The iPhone SE for example supports the latest iOS, but doesn't support haptic feedback. If I trigger a feedback nothing happens.

I see two alternatives that'd improve this library:

  1. Trigger a default vibration if the taptic engine isn't present.

  2. Expose a function that tells if the taptic engine is available (the current function only checks for iOS >= 10.0). If not present the developer may decide to fallback to a default vibration.

Not working with react native 0.61.5

Hi,
I just installed on my new react native project. I have cd to pod to install as well but I'm having this warning at below

Screenshot 2019-12-05 at 12 02 22 PM

do you have any solution for that?

react-native-haptic-feedback : ^1.8.2
System:
    OS: macOS 10.15.1
    CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
    Memory: 27.80 MB / 32.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 10.16.3 - /usr/local/bin/node
    npm: 6.9.0 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
  IDEs:
    Android Studio: 3.5 AI-191.8026.42.35.5791312
    Xcode: 11.2.1/11B500 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.9.0 => 16.9.0
    react-native: 0.61.5 => 0.61.5
  npmGlobalPackages:
    react-native-cli: 2.0.1

error: Invalid Zip archive: Could not find central directory end

Didn't used to be a problem on 1.1.0, on 1.1.5, 1.1.6, & 1.1.7 I'm getting this error.. I haven't tried downgrading even further but reverting back to 1.1.0 always seems to work.

Anyone knows what's up?

OS: macOS
Deployment target: iPhone 6
RN: 0.55.4
React: 16.4.0

error: Invalid Zip archive: Could not find central directory end


** BUILD FAILED **

The following commands produced analyzer issues:

	Analyze RNFIRMessaging.m normal arm64
(1 command with analyzer issues)

The following build commands failed:
	PhaseScriptExecution Upload\ Debug\ Symbols\ to\ Sentry build/Build/Intermediates.noindex/Delta.build/Debug-iphoneos/Delta.build/Script-E2F64182CC5748C3B120353C.sh
(1 failure)

IMG

RNReactNativeHapticFeedback is not available

Hey! I want to use haptic vibration once button tap but I have faced weird issue.
When click button I am getting warning and haptic vibration is not working.

"react-native": "0.70.1",
"react-native-haptic-feedback": "^1.14.0",

Usage:
const onHeptic = () => ReactNativeHapticFeedback.trigger('impactMedium', options);

Is this package has any problem?

Building on android fails because lambda expressions are not supported for my gradle version

Hi! ๐Ÿ‘‹

Firstly, thanks for your work on this project! ๐Ÿ™‚

Today I used patch-package to patch [email protected] for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-haptic-feedback/android/src/main/java/com/mkuczera/RNReactNativeHapticFeedbackPackage.java b/node_modules/react-native-haptic-feedback/android/src/main/java/com/mkuczera/RNReactNativeHapticFeedbackPackage.java
index 945ff34..13cc1cb 100644
--- a/node_modules/react-native-haptic-feedback/android/src/main/java/com/mkuczera/RNReactNativeHapticFeedbackPackage.java
+++ b/node_modules/react-native-haptic-feedback/android/src/main/java/com/mkuczera/RNReactNativeHapticFeedbackPackage.java
@@ -1,4 +1,3 @@
-
 package com.mkuczera;
 
 import androidx.annotation.Nullable;
@@ -26,21 +25,24 @@ public class RNReactNativeHapticFeedbackPackage extends TurboReactPackage {
 
     @Override
     public ReactModuleInfoProvider getReactModuleInfoProvider() {
-        return () -> {
-            final Map<String, ReactModuleInfo> moduleInfos = new HashMap<>();
-            boolean isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
-            moduleInfos.put(
-                    RNReactNativeHapticFeedbackModuleImpl.NAME,
-                    new ReactModuleInfo(
-                            RNReactNativeHapticFeedbackModuleImpl.NAME,
-                            RNReactNativeHapticFeedbackModuleImpl.NAME,
-                            false, // canOverrideExistingModule
-                            false, // needsEagerInit
-                            true, // hasConstants
-                            false, // isCxxModule
-                            isTurboModule // isTurboModule
-            ));
-            return moduleInfos;
+        return new ReactModuleInfoProvider() {
+            @Override
+            public Map<String, ReactModuleInfo> getReactModuleInfos() {
+                final Map<String, ReactModuleInfo> moduleInfos = new HashMap<>();
+                boolean isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
+                moduleInfos.put(
+                        RNReactNativeHapticFeedbackModuleImpl.NAME,
+                        new ReactModuleInfo(
+                                RNReactNativeHapticFeedbackModuleImpl.NAME,
+                                RNReactNativeHapticFeedbackModuleImpl.NAME,
+                                false, // canOverrideExistingModule
+                                false, // needsEagerInit
+                                true,  // hasConstants
+                                false, // isCxxModule
+                                isTurboModule // isTurboModule
+                        ));
+                return moduleInfos;
+            }
         };
     }
 }

This issue body was partially generated by patch-package.

minSdkVersion is hard-coded

The library has hard-coded minSdkVersion to be 16, instead of pulling it from the root project. This causes our Android Detox build to fail. (Not sure why the main build works but Detox build fails.)

I have a PR to fix the issue. In the meantime one can use "react-native-haptic-feedback": "github:plaa/react-native-haptic-feedback"

New arch not working (crashing at pod install)

I've read that v2.0 supports the React Native Fabric ("new arch"). I'm on v2.0.2 but if I pod install with RCT_NEW_ARCH_ENABLED=1 pod install codegen runs successfully on all the other pods but on react-native-haptic-feedback it fails with:

Here is the error:

Error: ENOENT: no such file or directory, lstat '/path/to/my/project/node_modules/react-native-haptic-feedback/src'
    at Object.lstatSync (node:fs:1561:3)
    at /path/to/my/project/node_modules/react-native-codegen/lib/cli/combine/combine-js-to-schema-cli.js:26:10
    at Array.forEach (<anonymous>)
    at Object.<anonymous> (/path/to/my/project/node_modules/react-native-codegen/lib/cli/combine/combine-js-to-schema-cli.js:25:10)
    at Module._compile (node:internal/modules/cjs/loader:1155:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
    at Module.load (node:internal/modules/cjs/loader:1033:32)
    at Function.Module._load (node:internal/modules/cjs/loader:868:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:22:47 {
  errno: -2,
  syscall: 'lstat',
  code: 'ENOENT',
  path: '/path/to/my/project/node_modules/react-native-haptic-feedback/src'
}
Error: Command failed: node /path/to/my/project/node_modules/react-native-codegen/lib/cli/combine/combine-js-to-schema-cli.js --platform ios /var/folders/_m/n09zdv0j27nc57hp777p49xr0000gn/T/RNHapticFeedbackSpecKdJ631/schema.json /path/to/my/project/node_modules/react-native-haptic-feedback/src
/path/to/my/project/node_modules/flow-parser/flow_parser.js:807
throw a}function
^

Error: ENOENT: no such file or directory, lstat '/path/to/my/project/node_modules/react-native-haptic-feedback/src'
    at Object.lstatSync (node:fs:1561:3)
    at /path/to/my/project/node_modules/react-native-codegen/lib/cli/combine/combine-js-to-schema-cli.js:26:10
    at Array.forEach (<anonymous>)
    at Object.<anonymous> (/path/to/my/project/node_modules/react-native-codegen/lib/cli/combine/combine-js-to-schema-cli.js:25:10)
    at Module._compile (node:internal/modules/cjs/loader:1155:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
    at Module.load (node:internal/modules/cjs/loader:1033:32)
    at Function.Module._load (node:internal/modules/cjs/loader:868:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:22:47 {
  errno: -2,
  syscall: 'lstat',
  code: 'ENOENT',
  path: '/path/to/my/project/node_modules/react-native-haptic-feedback/src'
}

    at checkExecSyncError (node:child_process:861:11)
    at execSync (node:child_process:932:15)
    at executeNodeScript (/path/to/my/project/node_modules/react-native/scripts/codegen/generate-artifacts-executor.js:38:3)
    at generateSchema (/path/to/my/project/node_modules/react-native/scripts/codegen/generate-artifacts-executor.js:314:3)
    at /path/to/my/project/node_modules/react-native/scripts/codegen/generate-artifacts-executor.js:373:26
    at Array.forEach (<anonymous>)
    at generateNativeCodegenFiles (/path/to/my/project/node_modules/react-native/scripts/codegen/generate-artifacts-executor.js:362:13)
    at Object.execute (/path/to/my/project/node_modules/react-native/scripts/codegen/generate-artifacts-executor.js:532:5)
    at Object.<anonymous> (/path/to/my/project/node_modules/react-native/scripts/generate-codegen-artifacts.js:64:10) {
  status: 7,
  signal: null,
  output: [
    null,
    <Buffer >,
    <Buffer 2f 55 73 65 72 73 2f 43 61 6e 2f 44 6f 63 75 6d 65 6e 74 73 2f 50 72 6f 67 72 61 6d 6d 69 6e 67 2f 52 65 61 63 74 2f 44 61 56 69 6e 63 69 2f 6e 6f 64 ... 1152 more bytes>
  ],
  pid: 20816,
  stdout: <Buffer >,
  stderr: <Buffer 2f 55 73 65 72 73 2f 43 61 6e 2f 44 6f 63 75 6d 65 6e 74 73 2f 50 72 6f 67 72 61 6d 6d 69 6e 67 2f 52 65 61 63 74 2f 44 61 56 69 6e 63 69 2f 6e 6f 64 ... 1152 more bytes>
}
.

 #  from /path/to/my/project/ios/Podfile:35
 #  -------------------------------------------
 #  
 >    use_react_native!(
 #      :path => config[:reactNativePath],
 #  -------------------------------------------

[!] [Codegen] warn: using experimental new codegen integration

I've tried deleting Pods directory, Podfile.lock, and ios's build directory but no avail, still the same error.

Build issue - Execution failed for task ':react-native-haptic-feedback:compileDebugJavaWithJavac'.

Hey @mkuczera, I've just installed "react-native-haptic-feedback": "2.1.0" in a "react-native": "^0.72.3" project.
But running an android build - ./gradlew assembleDebug, results in this error below in the class RNReactNativeHapticFeedbackPackage on this line in the getReactModuleInfoProvider function.

I notice one difference in your package source as it uses gradle-7.0.2-bin whereas my project uses gradle-8.0.1-all.
But I couldn't downgrade to 7.0.2 since my project relies on newer gradle configuration.

It seems like the compiler doesn't recognise the Map - cannot find the symbol "Map" in the context of the code

Can you help in any way to resolve this build issue?
Or if version 2.1.0 is compatible with [email protected]?

Error log out from ./gradlew assembleDebug command:

> Configure project :react-native-reanimated
No AAR for react-native-reanimated found. Attempting to build from source.
Android gradle plugin: 7.4.2
Gradle: 8.0.1
WARNING:Software Components will not be created automatically for Maven publishing from Android Gradle Plugin 8.0. To opt-in to the future behavior, set the Gradle property android.disableAutomaticComponentCreation=true in the `gradle.properties` file or use the new publishing DSL.

> Task :react-native-haptic-feedback:compileDebugJavaWithJavac FAILED
/Users/brianvarley/Projects/react-native-prototyping/node_modules/react-native-haptic-feedback/android/src/main/java/com/mkuczera/RNReactNativeHapticFeedbackPackage.java:29: error: cannot find symbol
            final Map<String, ReactModuleInfo> moduleInfos = new HashMap<>();
                  ^
  symbol:   class Map
  location: class RNReactNativeHapticFeedbackPackage

I've added some details about my package.json dependencies, node and java versions below:

[email protected]
[email protected]

 "dependencies": {
    "@mgcrea/react-native-dnd": "^1.4.0",
    "bluebird": "^3.7.2",
    "convert-units": "^2.3.4",
    "event-emitter": "^0.3.5",
    "fbjs": "^3.0.5",
    "npm": "^9.8.1",
    "prop-types": "^15.8.1",
    "react": "18.2.0",
    "react-dom": "^18.2.0",
    "react-native": "^0.72.3",
    "react-native-cli": "^2.0.1",
    "react-native-config": "^1.5.1",
    "react-native-gesture-handler": "2.9.0",
    "react-native-haptic-feedback": "2.1.0",
    "react-native-svg": "^13.10.0",
  },

Issue with types export assignment

I think there might be an issue with the typings introduced in #78

TypeScript complains to me about line 35 of index.d.ts that "An export assignment cannot be used in a module with other exported elements"

See below in screenshot
Screenshot 2022-07-15 at 12 50 51 pm

'impactLight' no effect on iPhones 6S

Hi!

I tested the package and only 'selection' and 'impactMedium' have any effect whatsoever.
Is this because the phone does not support lighter vibrations?

Thank you very much in advance!

Not working on IOS 14.4, RN 0.64

I follow the guide for installation and the code snippet.
I get the error warning as below even I have try with different method:

WARN  RNReactNativeHapticFeedback is not available
const options = {
  enableVibrateFallback: true,
  ignoreAndroidSystemSettings: false,
};

ReactNativeHapticFeedback.trigger('selection', options); // selection | impactLight and etc.....

Feedback upon click, not release

A key feature of Android buttons are the subtle sound and haptic they produce as feedback to touches.
Using your amazing library is the closest I've come to reproducing that.

On native android, the feedback is generated immediately as the touch is encountered.
But in react-native, when I use your ReactNativeHapticFeedback.trigger('selection') on a onPress, the feedback only comes on the release of the touch. Is there a way to work around this?

Also, as a feature request, can you have a sound to play on Android devices, thus completing the circle of native feedback

[iOs] haptic feedback does not working if mic on

Hello,

Is there any solution to use haptic feedback when mic is active on iOs ?

React-Native: 0.63.4
expo: 42.0.1

`const options = {
enableVibrateFallback: true,
ignoreAndroidSystemSettings: false,
};

ReactNativeHapticFeedback.trigger("selection", options);
`

Thanks,

RNReactNativeHapticFeedback is not available

I checked the similar issues, but wasn't been able to resolved it mine.
Had a RNReactNativeHapticFeedback is not available warning, and no feedback when I clicked on the button. Running on the latest iOS version (13.4), Expo version 2.15.2, and react-native 0.62.
IMG_5075

here is my log in my console.

RNReactNativeHapticFeedback is not available
- node_modules/expo/build/environment/muteWarnings.fx.js:18:23 in warn
- node_modules/react-native-haptic-feedback/index.js:14:22 in RNReactNativeHapticFeedback.trigger
* components/Twitter/TwitterHeart.js:13:24 in onPress
- node_modules/react-native/Libraries/Components/Touchable/TouchableHighlight.js:336:45 in createReactClass$argument_0.touchableHandlePress
* [native code]:null in touchableHandlePress
- node_modules/react-native/Libraries/Components/Touchable/Touchable.js:880:34 in TouchableMixin._performSideEffectsForTransition
* [native code]:null in _performSideEffectsForTransition
- node_modules/react-native/Libraries/Components/Touchable/Touchable.js:779:44 in TouchableMixin._receiveSignal
* [native code]:null in _receiveSignal
- node_modules/react-native/Libraries/Components/Touchable/Touchable.js:490:24 in TouchableMixin.touchableHandleResponderRelease
* [native code]:null in touchableHandleResponderRelease
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:307:15 in invokeGuardedCallbackImpl
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:531:36 in invokeGuardedCallback
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:555:30 in invokeGuardedCallbackAndCatchFirstError
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:722:42 in executeDispatch
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:744:20 in executeDispatchesInOrder
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:907:29 in executeDispatchesAndRelease
* [native code]:null in forEach
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:887:16 in forEachAccumulated
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:932:21 in runEventsInBatch
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:1096:19 in runExtractedPluginEventsInBatch
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:2796:6 in batchedUpdates$argument_0
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:18791:14 in batchedUpdates$1
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:2709:30 in batchedUpdates
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:2794:17 in batchedUpdates$argument_0
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:2870:28 in receiveTouches
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:436:47 in __callFunction
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:111:26 in __guard$argument_0
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:384:10 in __guard
- node_modules/react-native/Libraries/BatchedBridge/Messa

Not have any clue in what to do.
Thx very much for your potential help :)

How to control iOS vibration in case of fallback?

Right now we can use enableVibrateFallback to enable old iPhones to vibrate (because there's no haptic feedback available). However, based on docs, the default vibration is 1 second.

However, based on React Native official docs, on iOS, the vibration duration is fixed at roughly 400 milliseconds.

Why are we using a different default vibration using this library? Also, is it possible to reduce to the minimum (let's say, those 400ms)?

Thank you guys ๐Ÿš€

What is the maximum duration time of vibration in ios

Description

I am making an exercise app, and I have the haptic activated when the round starts, the problem is that a round lasts 50 seconds, if it passes 25 seconds it stops vibrating, this only happens on iOS, I would like to know if there is a restriction in the library about the maximum haptic time, this problem in android does not happen.

My example code

const options = {
enableVibrateFallback: false,
ignoreAndroidSystemSettings: true
};

const interval = useRef(null);

const hapticLight = () => {
trigger("impactLight", options)
}

useEffect(() => {
interval.current = setInterval(() => {
hapticLight()
}, 100);
return () => clearInterval(interval.current);
}, []);

Package version
"react": "17.0.2",
"react-native": "0.66.5",
"react-native-haptic-feedback": "^2.0.0",

Example visual
Captura de pantalla 2023-05-25 a la(s) 7 19 09 p m

iOS: Only works when called outside of function; not activated on button press

The ReactNativeHapticFeedback.trigger() only activates if outside a function (based on limited testing). I want it to activate on button press.

For example, this works:

import ReactNativeHapticFeedback from "react-native-haptic-feedback";

const MyScreen = () => {
ReactNativeHapticFeedback.trigger("selection");
}

...but these don't:

import ReactNativeHapticFeedback from "react-native-haptic-feedback";
import { ConfirmDialog } from 'react-native-simple-dialogs';
import { Button } from 'react-native-elements';

const MyScreen = () => {

    const handleButtonPress = () => {
      ReactNativeHapticFeedback.trigger("selection");
    }

    <ConfirmDialog
    ...
    positiveButton={{
      title: "Button 1",
      onPress: handleButtonPress
    }}
    />

    <Button 
     ...
    title="Button 2"
    onPress={() => handleButtonPress()}
    />

    <Button 
     ...
    title="Button 3"
    onPress={ReactNativeHapticFeedback.trigger("selection")}
    />

}

Using options such as below does not help:

const options = {
  enableVibrateFallback: true,
  ignoreAndroidSystemSettings: false
};

Using different methods other than "selection" don't help either.

However, it activates fine on button press on my Android device (which seems to fall back to vibration & doesn't have haptic feedback).

At one point I glanced at my Xcode logs and surprisingly saw some non-React-Native logs, 3 or 4 of which were related to the haptics engine not starting. One of them said react-native-haptic-feedback failed to prewarm core haptics engine. Google shows absolutely 0 results for this error.

Off to ugly old React Native Vibrate I guess...

UPDATE: The exact same bug occurs with Vibration.vibrate() too! ๐Ÿ˜ตโ€๐Ÿ’ซ It works fine outside of an onPress event, but as soon as it's implemented into an onPress, it does nothing. This issue is documented by others here. I think this issue is rooted in a React Native bug, potentially conflicting with libraries or environment setup...

iOS 14.8 | React Native 0.64.2

Cross-reference to react-native Vibration.vibrate() issue: facebook/react-native#23404 (comment)


UPDATE 2: Just created a brand new React Native project on the latest React Native (0.66.0). With the below code, onPress={ReactNativeHapticFeedback.trigger("selection")} activates when I open the app, but not when I press the button! ๐Ÿคฏ Same exact behavior with Vibration.vibrate() (except it vibrates when the app is launched instead of doing the haptic feedback of course), so I think it's a React Native issue, rather than this library's.

import React, { useEffect } from 'react';
import {
  View,
  Button,
} from 'react-native';
import ReactNativeHapticFeedback from "react-native-haptic-feedback";

const App = () => {

  return (
    <View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}} >
    <Button
    title="Buzz!"
    onPress={ReactNativeHapticFeedback.trigger("selection")} />
    </View>
  );
};

export default App;

iOS 14.8 | React Native 0.66.0

New facebook/react-native GitHub issue opened by me

react-native-haptic-feedback not working with latest version

The react-native-haptic-feedback library is not working with the latest version. Despite implementing the code as documented, no haptic feedback is being generated and there are no errors or warnings being displayed when interacting with components.

no feedback on iOS with new version

Used to work perfectly, but now there is no haptic feedback on iPhone X running iOS 11.3. Adding the boolean argument "true" results in the heavy vibration.

No vibration can be produced otherwise.

New architecture

Hello. Are there any plans to update this library to support TurboModules? If so, is there anything we can help with?

Detect haptics?

Is there a way to detect if your device has haptics? Getting a persistent warning on Simulator when using this library which I would like to avoid.

Now working on fallback devices

it is working fine in all high end ios and all android but not working on low end ios,
i am using this code
ReactNativeHapticFeedback.trigger('notificationWarning', true);
please suggest

iOS 13 Not Working

This does not seem to be working on iOS 13, has anyone been experiencing the same issues?

Why does Android use the Vibrations API instead of View.performHapticFeedback + HapticFeedbackConstants

When digging into the code for Android I saw you are using the Android Vibration API. The haptic feedback on Android right now is very aggressive and a lot more 'in your face' than the nice subtle haptics on iOS delivered by UIImpactFeedbackGenerator.

There are APIs available for Android that use Haptics which allow for much more subtle feedback patterns:

Is there a specific reason for this choice? Otherwise, it might be interesting to implement this (I'd be happy to help via PR)

Invalid configuration class (null) for generator <UIImpactFeedbackGenerator>

Hi,

I'm using your library and it's a pretty good library.

But I've issues with some of my users, as you can see, this error is raise.

NSInternalInconsistencyException: Invalid configuration class (null) for generator <UIImpactFeedbackGenerator: 0x282784e10: prepared=0>

User running on IOS 12.4.1(16G102)

I don't know if you have any idea about that ?

Thanks

Calling haptic too frequently seems to cause crash

Hi,

I'm creating a swipe selector for a project and I was using this library to get a native feedback on iOS device, and it seems that when I swipe too quickly this library is called many times and it is causing some issues, causing the app to crash.

Enqueued from CHHapticEngineDispatchQueue

Anyone got this before ?

Error at bundling before release

Environment:
React-Native: 0.57.7
OS: MacOS

How to reproduce:
Run the following script:

react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/

Log:
node_modules/react-native-haptic-feedback/index.js: Unexpected token (22:19)

22 | const triggerHaptic(type, options) {
^
23 | try {
24 | NativeModules.RNReactNativeHapticFeedback.trigger(type, options);
25 | } catch (err) {

I don't get any haptic on IPhone 8

Hi,
I tested the package and it works fine on android.But nothing work on IPhone8.
I tried all parameters of the method. I don't get any errors or warnings on the console.

My example code

    haptic() {
        const hapticOptions = {
            enableVibrateFallback: false,
            ignoreAndroidSystemSettings: true,
        };

        const hapticTriggerType = Platform.select({
            ios: 'selection',
            android: 'notificationSuccess'
        });

        ReactNativeHapticFeedback.trigger(hapticTriggerType, hapticOptions)
    }

Package version

   "react": "16.13.1",
   "react-native": "0.63.4",
   "react-native-haptic-feedback": "^1.13.0"

Test device info

Model name: iPhone8
Software Version: 14.5.1

License file in repo?

Hi,

Would you mind adding an MIT license file into the body of this repository? Your NPM registry and package.json declare it as MIT licensed, but I don't see one in the repository, and I don't think I can use this code base without that. I think Github has a button on the repo settings to do that for you.

Thanks!

iOS Re-use generators for better performance

I switched from my custom haptic feedback solution to this library because I don't have time to maintain my own library, and noticed worse performance using this library when activating a series of rapid haptic (light impact) vibrations. After comparing with my code, my bet is that it is because on iOS, you allocate a new generator object every time the method is called. Instead, for best performance, you should only create one generator object for each type of feedback and re-use that object for future calls of the same time. This should create faster response time and take less energy. I'll create a PR for this later if I have time, but figured I'd mention it in case you want to take it on instead. Hopefully this makes sense, I can provide more details if needed.

Jcenter shut down causes problems on the module

Today we have started to see this issue :

':react-native-haptic-feedback'.
> Could not resolve all artifacts for configuration ':react-native-haptic-feedback:classpath'.
   > Could not resolve com.android.tools.build:builder:3.0.0.
     Required by:
         project :react-native-haptic-feedback > com.android.tools.build:gradle:3.0.0 > com.android.tools.build:gradle-core:3.0.0
      > Could not resolve com.android.tools.build:builder:3.0.0.
         > Could not get resource 'https://jcenter.bintray.com/com/android/tools/build/builder/3.0.0/builder-3.0.0.pom'.
            > Could not HEAD 'https://jcenter.bintray.com/com/android/tools/build/builder/3.0.0/builder-3.0.0.pom'.
               > Read timed out
   > Could not resolve org.eclipse.jdt.core.compiler:ecj:4.6.1.
     Required by:
         project :react-native-haptic-feedback > com.android.tools.build:gradle:3.0.0 > com.android.tools.build:gradle-core:3.0.0 > com.android.tools.lint:lint:26.0.0
      > Skipped due to earlier error
   > Could not resolve com.google.code.gson:gson:2.3.
     Required by:
         project :react-native-haptic-feedback > com.android.tools.build:gradle:3.0.0 > com.android.tools.build:gradle-core:3.0.0 > com.android.tools.lint:lint:26.0.0 > com.android.tools.build:manifest-merger:26.0.0
         project :react-native-haptic-feedback > com.android.tools.build:gradle:3.0.0 > com.android.tools.build:gradle-core:3.0.0 > com.android.tools.lint:lint:26.0.0 > com.android.tools.build:manifest-merger:26.0.0 > com.android.tools:sdklib:26.0.0
      > Skipped due to earlier error
   > Could not resolve com.google.errorprone:error_prone_annotations:2.0.18.
     Required by:
         project :react-native-haptic-feedback > com.android.tools.build:gradle:3.0.0 > com.android.tools.build:gradle-core:3.0.0 > com.android.tools.build:gradle-api:3.0.0 > com.google.guava:guava:22.0
      > Skipped due to earlier error
   > Could not resolve org.jetbrains.kotlin:kotlin-reflect:1.1.3-2.
     Required by:
         project :react-native-haptic-feedback > com.android.tools.build:gradle:3.0.0 > com.android.tools.build:gradle-core:3.0.0 > com.android.tools.lint:lint:26.0.0 > com.android.tools.lint:lint-checks:26.0.0 > com.android.tools.lint:lint-api:26.0.0
      > Skipped due to earlier error

Is there any workaround on this?
Thank you in advance!

there is problem in docs implementation

hey developers,

I've discovered that the documentation for passing options value contains a small problem.
const options = {
enableVibrateFallback: true,
ignoreAndroidSystemSettings: false,
};
passing these as options doesn't perform haptic feedback which is mention in docs
insead,
const options = {
enableVibrateFallback: false,
ignoreAndroidSystemSettings: true,
};
by passing these as options it is performing haptic feedback

i request you to check docs and perform necessary changes

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.