From f2673b91fe5ee9a5fb869d58571113532c8614e5 Mon Sep 17 00:00:00 2001 From: Andrew Prifer <2991360+AndrewPrifer@users.noreply.github.com> Date: Fri, 10 Jun 2022 17:56:35 +0200 Subject: [PATCH] Fix useFrameStampPositionRef (#209) --- .../AggregatedKeyframeTrack.tsx | 2 -- .../FrameStampPositionProvider.tsx | 31 ++++++++++--------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/theatre/studio/src/panels/SequenceEditorPanel/DopeSheet/Right/AggregatedKeyframeTrack/AggregatedKeyframeTrack.tsx b/theatre/studio/src/panels/SequenceEditorPanel/DopeSheet/Right/AggregatedKeyframeTrack/AggregatedKeyframeTrack.tsx index 351b3f1..275b1f0 100644 --- a/theatre/studio/src/panels/SequenceEditorPanel/DopeSheet/Right/AggregatedKeyframeTrack/AggregatedKeyframeTrack.tsx +++ b/theatre/studio/src/panels/SequenceEditorPanel/DopeSheet/Right/AggregatedKeyframeTrack/AggregatedKeyframeTrack.tsx @@ -481,11 +481,9 @@ function useDragForAggregateKeyframeDot( debugName: 'AggregateKeyframeDot/useDragKeyframe', onDragStart(event) { logger._debug('onDragStart', {target: event.target}) - console.log(event.target) const positionToFind = Number((event.target as HTMLElement).dataset.pos) const props = getPropsForPosition(positionToFind) if (!props) { - console.log('exit') logger._debug('no props found for ', {positionToFind}) return false } diff --git a/theatre/studio/src/panels/SequenceEditorPanel/FrameStampPositionProvider.tsx b/theatre/studio/src/panels/SequenceEditorPanel/FrameStampPositionProvider.tsx index 9a689bb..866c254 100644 --- a/theatre/studio/src/panels/SequenceEditorPanel/FrameStampPositionProvider.tsx +++ b/theatre/studio/src/panels/SequenceEditorPanel/FrameStampPositionProvider.tsx @@ -130,28 +130,31 @@ export const useLockFrameStampPositionRef = () => { useLayoutEffect(() => { return () => { - lockRef.current!.unlock() + lockRef.current?.unlock() } - }, [val]) + }, []) return useMemo(() => { - let prevShouldLock: false | {pos: number} = false + let prevLock: {shouldLock: boolean; pos: number} | undefined = undefined return (shouldLock: boolean, posValue: number) => { - if (shouldLock === prevShouldLock) return - if (shouldLock) { - if (!prevShouldLock) { + // Do if shouldLock changed + if (prevLock?.shouldLock !== shouldLock) { + if (shouldLock) { lockRef.current = getLock() - lockRef.current.set(posValue) - prevShouldLock = {pos: posValue} - } else if (prevShouldLock.pos !== posValue) { - lockRef.current?.set(posValue) } else { - // all the same params + lockRef.current?.unlock() } - } else { - lockRef.current!.unlock() - prevShouldLock = false } + + // Do if position changed + if (prevLock?.pos !== posValue) { + if (shouldLock) { + lockRef.current?.set(posValue) + } + } + + // Set arguments we are going to diff against next time + prevLock = {shouldLock, pos: posValue} } }, [getLock]) }