I'm trying to animate a 50px circle to expand to 100px over 2 seconds, then stay at 100px for 2 seconds before starting to shrink down to 50px over 2 seconds. Then repeat this indefinitely.
Currently I've nailed the expanding part, but I can't figure out how to keep it at max width/height for 2 seconds and then shrink it down.
import React, { FunctionComponent, useEffect } from 'react';
import Animated, {
useAnimatedStyle,
useSharedValue,
withDelay,
withRepeat,
withSpring,
withTiming,
} from 'react-native-reanimated';
import styled from 'styled-components/native';
const CircleAnimation: FunctionComponent<Props> = () => {
const widthAndHeight = useSharedValue(50);
const duration = 2;
const foregroundCircleStyle = useAnimatedStyle(() => {
return {
width: widthAndHeight.value,
height: widthAndHeight.value,
borderRadius: widthAndHeight.value / 2,
};
});
useEffect(() => {
widthAndHeight.value = withDelay(
2000,
withRepeat(
withTiming(100, {
duration: duration * 1000,
}),
-1,
false
)
);
}, [duration, widthAndHeight]);
return <ForegroundCircle style={[foregroundCircleStyle]} />
};
const ForegroundCircle = styled(Animated.View)`
width: 50px;
height: 50px;
border-radius: 25px;
background-color: yellow;
`;
export default CircleAnimation;