Skip to content

Commit

Permalink
fix transition
Browse files Browse the repository at this point in the history
  • Loading branch information
pesto13 committed Sep 25, 2024
1 parent 50cce59 commit 1907410
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Scoprimi/src/components/lobby/LobbyPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ const LobbyPlayer: React.FC<PlayerProps> = ({ name, image, isReadyToGame, admin,
const [startX, setStartX] = useState<number | null>(null);
const [currentX, setCurrentX] = useState<number | null>(null);
const [showDeleteBtn, setShowDeleteBtn] = useState(false);
const [transitionEnabled, setTransitionEnabled] = useState(false);

const handleTouchStart = (e: React.TouchEvent) => {
setStartX(e.touches[0].clientX);
setCurrentX(e.touches[0].clientX);
// Durante il drag spengo la transition
setTransitionEnabled(false);
};

const handleTouchMove = (e: React.TouchEvent) => {
Expand All @@ -35,6 +38,8 @@ const LobbyPlayer: React.FC<PlayerProps> = ({ name, image, isReadyToGame, admin,
setShowDeleteBtn(false);
}
}
// finito il drag la abilito
setTransitionEnabled(true);
setStartX(null);
setCurrentX(null);
};
Expand All @@ -47,14 +52,14 @@ const LobbyPlayer: React.FC<PlayerProps> = ({ name, image, isReadyToGame, admin,

return (
<div
className={`player-item swipeable`}
className={'player-item swipeable'}
key={name}
onTouchStart={handleTouchStart}
onTouchMove={handleTouchMove}
onTouchEnd={handleTouchEnd}
style={{
transform: `translateX(${translateX}px)`,
transition: 'transform 0.3s ease',
transition: transitionEnabled ? 'transform 0.3s ease' : 'none', // Applica la transition al rilascio, non durante il drag
}}
>
<div className="player-image">
Expand Down

0 comments on commit 1907410

Please sign in to comment.