I'm trying to rotate an image using React Native. I have managed to do this as shown in the example below, but I would prefer that the arrow spins to the new bearing using the shorter route (i.e. clockwise in this case instead of counterclockwise).
If the current bearingAnim
value is 315
and the next value is 45
the rotation will transition backwards, rather than going from 315 => 45
.
How can I adjust the code to use the shortest rotation?
const bearing = this.bearingAnim.interpolate({
inputRange: [0, 360],
outputRange: ['0deg', '360deg'],
});
return <Animated.Image style={{ transform: [{ rotate: bearing }] }} source={markerGreen} />;