Skip to content

Commit

Permalink
feat: animate assignment button
Browse files Browse the repository at this point in the history
  • Loading branch information
julian-wasmeier-titanom committed May 24, 2024
1 parent 042f469 commit 730ca6d
Showing 1 changed file with 48 additions and 22 deletions.
70 changes: 48 additions & 22 deletions frontend/src/components/assignment-item.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Pressable, Text, View } from "react-native";
import React from "react";
import { Animated, Pressable, Text, View } from "react-native";

import BouncyCheckbox from "react-native-bouncy-checkbox";

Expand All @@ -20,32 +21,57 @@ export function AssignmentItem({
disabled = false,
onPress,
}: ListItemProps) {
const [isPressed, setIsPressed] = React.useState(false);

const scaleAnim = React.useRef(new Animated.Value(1)).current;

const scaleIn = () => {
Animated.spring(scaleAnim, {
toValue: 0.95,
friction: 5,
useNativeDriver: true,
}).start();
};

const scaleOut = () => {
Animated.spring(scaleAnim, {
toValue: 1,
friction: 5,
useNativeDriver: true,
}).start();
};

return (
<View className="p-2 bg-slate-900 flex-row justify-between items-start rounded-lg">
<Animated.View style={{ transform: [{ scale: scaleAnim }] }}>
<Pressable
className="bg-slate-900 flex-col items-start rounded-lg"
className={`p-2 bg-white justify-between items-center rounded-lg flex flex-row`}
onPress={() => onPress(id)}
onPressIn={scaleIn}
onPressOut={scaleOut}
disabled={disabled}
>
<Text
className={`font-semibold text-lg text-gray-200 ${
isCompleted && "line-through"
}`}
>
{title}
</Text>
<Text className="text-gray-100 text-lg">{description}</Text>
<View>
<Text
className={`font-semibold text-slate-900 text-lg ${
isCompleted && "line-through"
}`}
>
{title}
</Text>
<Text className="text-slate-500 text-lg">{description}</Text>
</View>
<BouncyCheckbox
size={25}
unFillColor="#FFFFFF"
fillColor="#7cc6f4"
iconStyle={{ borderColor: "black" }}
innerIconStyle={{ borderWidth: 2 }}
isChecked={isCompleted}
disabled={disabled}
onPress={() => onPress(id)}
className="justify-center"
/>
</Pressable>
<BouncyCheckbox
size={25}
unFillColor="#FFFFFF"
iconStyle={{ borderColor: "black" }}
innerIconStyle={{ borderWidth: 2 }}
isChecked={isCompleted}
disabled={disabled}
onPress={() => onPress(id)}
className="justify-center"
/>
</View>
</Animated.View>
);
}

0 comments on commit 730ca6d

Please sign in to comment.