From db9fa60d8e56e6a35f182f2d21ad2295b23bd41d Mon Sep 17 00:00:00 2001 From: Daybrush Date: Mon, 10 Jun 2019 00:51:39 +0900 Subject: [PATCH] fix: fix setTime timing --- .../src/react-scenejs-timeline/Timeline.tsx | 17 ++++++++++++----- .../src/react-scenejs-timeline/types.ts | 1 + 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/react-scenejs-timeline/src/react-scenejs-timeline/Timeline.tsx b/packages/react-scenejs-timeline/src/react-scenejs-timeline/Timeline.tsx index 8eeb825..eac2e48 100644 --- a/packages/react-scenejs-timeline/src/react-scenejs-timeline/Timeline.tsx +++ b/packages/react-scenejs-timeline/src/react-scenejs-timeline/Timeline.tsx @@ -39,6 +39,7 @@ export default class Timeline extends PureProps { selectedProperty: "", selectedTime: -1, init: false, + updateTime: false, }; private isExportCSS = false; private axes!: Axes; @@ -137,15 +138,19 @@ export default class Timeline extends PureProps { this.initKeyController(); } public componentDidUpdate(prevProps: TimelineProps, prevState: TimelineState) { - if (this.state.init) { - this.state.init = false; + const state = this.state; + + if (state.init) { + state.init = false; this.scrollArea.foldAll(); } if (prevProps.scene !== this.props.scene) { this.releaseScene(prevProps.scene); this.setState(this.initScene(this.props.scene, true)); - } else { + } + if (state.updateTime) { + state.updateTime = false; this.setTime(); } } @@ -171,6 +176,7 @@ export default class Timeline extends PureProps { timelineInfo: getTimelineInfo(scene), maxTime, maxDuration, + updateTime: true, init: isInit, }); @@ -536,10 +542,11 @@ export default class Timeline extends PureProps { } private initKeyController() { window.addEventListener("blur", () => { - this.setState({ alt: false }); + if (this.state.alt === true) { + this.setState({ alt: false }); + } }); - // if (props.keyboard) { if (this.props.keyboard) { this.keycon!.keydown("space", ({ inputEvent }) => { inputEvent.preventDefault(); diff --git a/packages/react-scenejs-timeline/src/react-scenejs-timeline/types.ts b/packages/react-scenejs-timeline/src/react-scenejs-timeline/types.ts index ec738a3..23785ef 100644 --- a/packages/react-scenejs-timeline/src/react-scenejs-timeline/types.ts +++ b/packages/react-scenejs-timeline/src/react-scenejs-timeline/types.ts @@ -25,6 +25,7 @@ export interface TimelineState { timelineInfo: TimelineInfo; selectedProperty: string; selectedTime: number; + updateTime: boolean; init: boolean; } export interface PropertiesInfo {