Skip to content

Commit

Permalink
fix: relaibility (#574)
Browse files Browse the repository at this point in the history
  • Loading branch information
YoanRos authored May 2, 2024
1 parent 7b6d144 commit 67d5c77
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 28 deletions.
13 changes: 3 additions & 10 deletions app/src/components/CalendarSwitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,13 @@ const CalendarSwitch = ({ tab, setTab }) => {
const [animatedXValue] = useState(new Animated.Value(0));

useEffect(() => {
runAnimation(renderValue(tab));
}, [tab]);

const renderValue = () => {
return Number(tab === 'gains');
};

const runAnimation = (toValue) => {
Animated.timing(animatedXValue, {
toValue,
delay: 1,
toValue: tab === 'calendar' ? 0 : 1,
duration: 200,
useNativeDriver: false,
}).start();
};
}, [tab]);

return (
<Container onLayout={(e) => setComponentWidth(e.nativeEvent.layout.width)}>
Expand Down
20 changes: 2 additions & 18 deletions app/src/components/PeriodSwitchToggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,12 @@ const PeriodSwitchToggle = ({ period, setPeriod }) => {
const [animatedXValue] = useState(new Animated.Value(0));

useEffect(() => {
runAnimation(renderValue(period));
}, [period]);

const renderValue = () => {
switch (period) {
case 'monthly':
return 2;
case 'weekly':
return 1;
case 'daily':
default:
return 0;
}
};

const runAnimation = (toValue) => {
Animated.timing(animatedXValue, {
toValue,
toValue: period === 'daily' ? 0 : period === 'weekly' ? 1 : 2,
duration: 200,
useNativeDriver: false,
}).start();
};
}, [period]);

return (
<Container onLayout={(e) => setComponentWidth(e.nativeEvent.layout.width)}>
Expand Down

0 comments on commit 67d5c77

Please sign in to comment.