When I try to animate rotation mapped to an iOS compass, the animation does full circle in opposite direction.
There has been related question about this for CSS3 transforms, suggesting that I should just keep increasing the degrees over 360 and it will just wrap around. Well this technique cannot be used with the sensor data as it just goes from 359, 360, straight to 0. And the interpolation algorithm in React Native just doesn't handle this.
This is my current code:
const degrees = useRef(new Animated.Value(0)).current;
useEffect(() => {
Animated.timing(
degrees,
{
toValue: location.trueHeading,
useNativeDriver: true
}
).start();
}, [location.trueHeading])
const renderArrow = () => {
return (
<Animated.View
style={{
transform: [{
rotate: ((degrees.interpolate({
inputRange: [0, 360],
outputRange: ['0deg', '-360deg']
})))
}]
}}
>
<IconArrow />
</Animated.View>
)
}
I do not need specific answer for React Native. General answer how would you solve this issue will suffice.
Thank you