BouarourMohammed / react-native-animated-rolling-numbers

🚀 The Animated Rolling Numbers component for React Native seamlessly blends a sophisticated number rotation effect with dynamic value updates, creating an engaging and interactive experience that enhances your user interfaces with a touch of elegance and excitement.
119 stars 6 forks source link

Idea: Haptic feedback #8

Closed ravanscafi closed 4 days ago

ravanscafi commented 1 week ago

Hello! Thanks for the component, it works really well!

I would love a haptic feedback/effect when the numbers roll.

(it could also work with an onAnimationStarts event or something like that)

What do you think?

BouarourMohammed commented 6 days ago

Thank you for the kind words! I'm glad the component is working well for you.

Regarding the haptic feedback suggestion, I think it's a great idea! However, we can achieve this without updating the package itself. Since the animation is triggered when the state updates, you can add haptic feedback externally using one of the following approaches:

Example 1: Using react-native-haptic-feedback

import HapticFeedback, { HapticFeedbackTypes } from 'react-native-haptic-feedback';

function hapticFeedback(type: HapticFeedbackTypes = 'impactLight', force = false) {  
  HapticFeedback.trigger(type, {  
    enableVibrateFallback: force,  
    ignoreAndroidSystemSettings: force,  
  });  
}

useEffect(() => {  
  hapticFeedback();  
}, [numberValue]);  // Replace `numberValue` with the state controlling the animation

Example 2: Using expo-haptics

import * as Haptics from 'expo-haptics';

useEffect(() => {  
  Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light);  
}, [numberValue]);  // Replace `numberValue` with the state controlling the animation

These approaches keep the package lightweight and avoid adding extra dependencies while still achieving the desired effect.