mkuczera / react-native-haptic-feedback

React-Native Haptic Feedback for iOS with Android similar behaviour.
MIT License
872 stars 106 forks source link

check haptic system settings before triggering #28

Closed adkenyon closed 5 years ago

adkenyon commented 5 years ago

Haptic feedback triggers despite the user's system settings. (If they turn off haptic via the accessibility settings then haptic does disable).

The change checks the haptic system settings prior to triggering and will return if haptic is disabled.

mkuczera commented 5 years ago

Hi, thank you for the contribution. Due to the fact that i actually don´t know if some people want this behaviour, i would prefer to have it as an optional settings value for the trigger like "ignoreAndroidSettings"

Greetings

Michael

adkenyon commented 5 years ago

Hello @mkuczera,

What are your thoughts on the trigger function arguments. I can either add a third parameter or change the second parameter to an options object (examples below). I guess a third option would be to make the second argument dynamic, in that it accepts a bool or config object. Adding a thrid argument is the easiest to implement, but long term having a config object is much more extensible.

// Using a 3rd parameter
ReactNativeHapticFeedback.trigger('impactLight', true, true);

// using a config object
const options = {
    enableVibrateFallback: true,
    ignoreAndroidSystemSettings: true
};

ReactNativeHapticFeedback.trigger('impactLight', options);
adkenyon commented 5 years ago

Hey @mkuczera,

After sleeping on it I decided to go with the third option. You can use the same trigger args as seen in v1.6 (type:string, enableVibrateFallback:bool) and the updated args (type:string, options:object). I've updated the type definition and cos to reflect the new arguments. Let me know what you think

mkuczera commented 5 years ago

Hey, thanks that is looking awesome so far. Wanted to go for the options argument as well. I will check everything and create a new release on the upcoming weekend :)

Greetings Michael