Perf: Avoid re-rendering keyframes when snap targets change
This commit is contained in:
parent
8f08499fb6
commit
f82c9d1155
1 changed files with 33 additions and 27 deletions
|
@ -5,7 +5,7 @@ import type {Keyframe} from '@theatre/core/projects/store/types/SheetState_Histo
|
||||||
import {usePrism, useVal} from '@theatre/react'
|
import {usePrism, useVal} from '@theatre/react'
|
||||||
import type {Pointer} from '@theatre/dataverse'
|
import type {Pointer} from '@theatre/dataverse'
|
||||||
import {val} from '@theatre/dataverse'
|
import {val} from '@theatre/dataverse'
|
||||||
import React, {Fragment} from 'react'
|
import React, {useMemo} from 'react'
|
||||||
import styled from 'styled-components'
|
import styled from 'styled-components'
|
||||||
import SingleKeyframeEditor from './KeyframeEditor/SingleKeyframeEditor'
|
import SingleKeyframeEditor from './KeyframeEditor/SingleKeyframeEditor'
|
||||||
import type {IContextMenuItem} from '@theatre/studio/uiComponents/simpleContextMenu/useContextMenu'
|
import type {IContextMenuItem} from '@theatre/studio/uiComponents/simpleContextMenu/useContextMenu'
|
||||||
|
@ -73,16 +73,14 @@ const BasicKeyframedTrack: React.VFC<BasicKeyframedTracksProps> = React.memo(
|
||||||
|
|
||||||
const snapToAllKeyframes = snapPositionsState.mode === 'snapToAll'
|
const snapToAllKeyframes = snapPositionsState.mode === 'snapToAll'
|
||||||
|
|
||||||
|
const track = useMemo(
|
||||||
|
() => ({data: trackData, id: leaf.trackId}),
|
||||||
|
[trackData, leaf.trackId],
|
||||||
|
)
|
||||||
|
|
||||||
const keyframeEditors = trackData.keyframes.map((kf, index) => (
|
const keyframeEditors = trackData.keyframes.map((kf, index) => (
|
||||||
<Fragment key={'keyframe-' + kf.id}>
|
|
||||||
{snapToAllKeyframes && (
|
|
||||||
<KeyframeSnapTarget
|
|
||||||
layoutP={layoutP}
|
|
||||||
leaf={leaf}
|
|
||||||
position={kf.position}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<SingleKeyframeEditor
|
<SingleKeyframeEditor
|
||||||
|
key={'keyframe-' + kf.id}
|
||||||
itemKey={createStudioSheetItemKey.forTrackKeyframe(
|
itemKey={createStudioSheetItemKey.forTrackKeyframe(
|
||||||
leaf.sheetObject,
|
leaf.sheetObject,
|
||||||
leaf.trackId,
|
leaf.trackId,
|
||||||
|
@ -90,17 +88,11 @@ const BasicKeyframedTrack: React.VFC<BasicKeyframedTracksProps> = React.memo(
|
||||||
)}
|
)}
|
||||||
keyframe={kf}
|
keyframe={kf}
|
||||||
index={index}
|
index={index}
|
||||||
track={{
|
track={track}
|
||||||
data: trackData,
|
|
||||||
id: leaf.trackId,
|
|
||||||
}}
|
|
||||||
layoutP={layoutP}
|
layoutP={layoutP}
|
||||||
leaf={leaf}
|
leaf={leaf}
|
||||||
selection={
|
selection={selectedKeyframeIds[kf.id] === true ? selection : undefined}
|
||||||
selectedKeyframeIds[kf.id] === true ? selection : undefined
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
</Fragment>
|
|
||||||
))
|
))
|
||||||
|
|
||||||
const snapTargets = snapPositions.map((position) => (
|
const snapTargets = snapPositions.map((position) => (
|
||||||
|
@ -112,6 +104,17 @@ const BasicKeyframedTrack: React.VFC<BasicKeyframedTracksProps> = React.memo(
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
|
|
||||||
|
const additionalSnapTargets = !snapToAllKeyframes
|
||||||
|
? null
|
||||||
|
: trackData.keyframes.map((kf) => (
|
||||||
|
<KeyframeSnapTarget
|
||||||
|
key={`additionalSnapTarget-${kf.id}`}
|
||||||
|
layoutP={layoutP}
|
||||||
|
leaf={leaf}
|
||||||
|
position={kf.position}
|
||||||
|
/>
|
||||||
|
))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container
|
<Container
|
||||||
ref={containerRef}
|
ref={containerRef}
|
||||||
|
@ -121,12 +124,15 @@ const BasicKeyframedTrack: React.VFC<BasicKeyframedTracksProps> = React.memo(
|
||||||
>
|
>
|
||||||
{keyframeEditors}
|
{keyframeEditors}
|
||||||
{snapTargets}
|
{snapTargets}
|
||||||
|
<>{additionalSnapTargets}</>
|
||||||
{contextMenu}
|
{contextMenu}
|
||||||
</Container>
|
</Container>
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
BasicKeyframedTrack.displayName = `BasicKeyframedTrack`
|
||||||
|
|
||||||
export default BasicKeyframedTrack
|
export default BasicKeyframedTrack
|
||||||
|
|
||||||
function useBasicKeyframedTrackContextMenu(
|
function useBasicKeyframedTrackContextMenu(
|
||||||
|
|
Loading…
Reference in a new issue