I have a react functional component Svg
being used as an icon for the Bottom-TabBar. On route change the current state.index
is compared to the route index
. The result which essentially is a boolean state isFocused
is passed to the Svg.
I am trying to animate the Svg based on this state and can not get the simple operation completed using reanimated. I am most certain that the value of fill is not being updated in useAnimatedProps
hook but I lack the experience of having deep knowledge with reanimated. Any help will be greatly appreciated
import Animated, {
useAnimatedProps,
useSharedValue,
} from 'react-native-reanimated';
import Svg, { Circle, Path } from 'react-native-svg';
const AnimatedSvg = Animated.createAnimatedComponent(Svg);
export default ({ isFocused }) => {
const fill = useSharedValue({ fill: 'transparent' });
const animatedProps = useAnimatedProps(() => {
isFocused
? (fill.value = { fill: 'red' })
: (fill.value = { fill: 'transparent' });
return fill.value;
});
return (
<AnimatedSvg
xmlns="http://www.w3.org/2000/svg"
width={24}
height={24}
animatedProps={animatedProps}
stroke={'white'}
strokeWidth={2}
strokeLinecap="round"
strokeLinejoin="round"
className="feather feather-search">
<Circle cx={11} cy={11} r={8} />
<Path d="m21 21-4.35-4.35" />
</AnimatedSvg>
);
};