Skip to content

Commit

Permalink
At start, set first animation, but do not play. When manually selecte…
Browse files Browse the repository at this point in the history
…d animation, play it.
  • Loading branch information
AlbertoCasasOrtiz committed Nov 1, 2023
1 parent 8087eb0 commit 4294464
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/components/Components/AnimationView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const AnimationView : React.FC<AnimationViewProps> = (props:AnimationViewProps)
useEffect(() => {
if (props.animationList.length > 0)
setSelectedAnim(props.animationList[0].name)
handleAnimationChange(props.animationList[0].name, false)
}, [props.animationList]);


Expand All @@ -41,20 +42,26 @@ const AnimationView : React.FC<AnimationViewProps> = (props:AnimationViewProps)
setSpeed(Number(event.target.value))
}

const handleAnimationChange = (event: SelectChangeEvent) => {
const handleAnimationChangeEvent = (event: SelectChangeEvent) => {
const targetName = event.target.value as string
setSelectedAnim(event.target.value as string);
handleAnimationChange(targetName, true)
};

const handleAnimationChange = (animationName: string, animate: boolean) => {
const targetName = animationName
setSelectedAnim(animationName);
if ( targetName === ""){
curState.setAnimating(false)
}
else {
const idx = curState.animations.findIndex((value: AnimationClip, index: number)=>{return (value.name === targetName)})
if (idx !== -1) {
curState.currentAnimationIndex = idx
curState.setAnimating(true)
curState.setAnimating(animate)
}
}
setPlay(curState.animating)
if (animate)
setPlay(curState.animating)
//setAge(event.target.value as string);
};

Expand All @@ -67,7 +74,7 @@ const AnimationView : React.FC<AnimationViewProps> = (props:AnimationViewProps)
labelId="simple-select-standard-label"
label={t('visualizationControl.animate')}
value={selectedAnim}
onChange={handleAnimationChange}
onChange={handleAnimationChangeEvent}
disabled={props.animationList.length < 1}
>
{props.animationList.map(anim => (
Expand Down

0 comments on commit 4294464

Please sign in to comment.