Fix useFrameStampPositionRef (#209)
This commit is contained in:
parent
34c7b06baf
commit
f2673b91fe
2 changed files with 17 additions and 16 deletions
|
@ -481,11 +481,9 @@ function useDragForAggregateKeyframeDot(
|
||||||
debugName: 'AggregateKeyframeDot/useDragKeyframe',
|
debugName: 'AggregateKeyframeDot/useDragKeyframe',
|
||||||
onDragStart(event) {
|
onDragStart(event) {
|
||||||
logger._debug('onDragStart', {target: event.target})
|
logger._debug('onDragStart', {target: event.target})
|
||||||
console.log(event.target)
|
|
||||||
const positionToFind = Number((event.target as HTMLElement).dataset.pos)
|
const positionToFind = Number((event.target as HTMLElement).dataset.pos)
|
||||||
const props = getPropsForPosition(positionToFind)
|
const props = getPropsForPosition(positionToFind)
|
||||||
if (!props) {
|
if (!props) {
|
||||||
console.log('exit')
|
|
||||||
logger._debug('no props found for ', {positionToFind})
|
logger._debug('no props found for ', {positionToFind})
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,28 +130,31 @@ export const useLockFrameStampPositionRef = () => {
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
return () => {
|
return () => {
|
||||||
lockRef.current!.unlock()
|
lockRef.current?.unlock()
|
||||||
}
|
}
|
||||||
}, [val])
|
}, [])
|
||||||
|
|
||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
let prevShouldLock: false | {pos: number} = false
|
let prevLock: {shouldLock: boolean; pos: number} | undefined = undefined
|
||||||
return (shouldLock: boolean, posValue: number) => {
|
return (shouldLock: boolean, posValue: number) => {
|
||||||
if (shouldLock === prevShouldLock) return
|
// Do if shouldLock changed
|
||||||
|
if (prevLock?.shouldLock !== shouldLock) {
|
||||||
if (shouldLock) {
|
if (shouldLock) {
|
||||||
if (!prevShouldLock) {
|
|
||||||
lockRef.current = getLock()
|
lockRef.current = getLock()
|
||||||
lockRef.current.set(posValue)
|
} else {
|
||||||
prevShouldLock = {pos: posValue}
|
lockRef.current?.unlock()
|
||||||
} else if (prevShouldLock.pos !== posValue) {
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do if position changed
|
||||||
|
if (prevLock?.pos !== posValue) {
|
||||||
|
if (shouldLock) {
|
||||||
lockRef.current?.set(posValue)
|
lockRef.current?.set(posValue)
|
||||||
} else {
|
|
||||||
// all the same params
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
lockRef.current!.unlock()
|
|
||||||
prevShouldLock = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set arguments we are going to diff against next time
|
||||||
|
prevLock = {shouldLock, pos: posValue}
|
||||||
}
|
}
|
||||||
}, [getLock])
|
}, [getLock])
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue