finish animate
This commit is contained in:
@@ -114,7 +114,7 @@ function Blocks(props: PropsWithChildren<BlockProps>) {
|
|||||||
|
|
||||||
const [animateProps, animationEdit]: [CSSProperties, CSSProperties] = useMemo(() => {
|
const [animateProps, animationEdit]: [CSSProperties, CSSProperties] = useMemo(() => {
|
||||||
const [normal, editProps] = mergeAnimate(props.data.animate, {
|
const [normal, editProps] = mergeAnimate(props.data.animate, {
|
||||||
isPause: props.config.timelineNeedleConfig.status === 'pause' ? true : false,
|
isPause: props.config.timelineNeedleConfig.status !== 'start' ? true : false,
|
||||||
delay:
|
delay:
|
||||||
props.config.timelineNeedleConfig.status === 'stop'
|
props.config.timelineNeedleConfig.status === 'stop'
|
||||||
? props.config.timelineNeedleConfig.current
|
? props.config.timelineNeedleConfig.current
|
||||||
|
@@ -47,6 +47,8 @@ export interface TimeLineNeedleConfigType {
|
|||||||
resetFunc: Function;
|
resetFunc: Function;
|
||||||
pauseFunc: Function;
|
pauseFunc: Function;
|
||||||
current: number;
|
current: number;
|
||||||
|
isRefresh: boolean;
|
||||||
|
setNeedle: Function;
|
||||||
}
|
}
|
||||||
|
|
||||||
const animateTicker = new Array(iter).fill(1).map((_, y) => y);
|
const animateTicker = new Array(iter).fill(1).map((_, y) => y);
|
||||||
@@ -186,50 +188,62 @@ const needleHeadEvent = (
|
|||||||
config: UserConfig
|
config: UserConfig
|
||||||
) => {
|
) => {
|
||||||
return {
|
return {
|
||||||
onMouseDown: (e: React.MouseEvent) => {
|
onMouseDown: async (e: React.MouseEvent) => {
|
||||||
console.log('down', setNeedle, config, e.clientX);
|
e.persist();
|
||||||
// 调整为stop模式,
|
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
if (
|
||||||
|
config.timelineNeedleConfig.status === 'start' ||
|
||||||
|
!config.timelineNeedleConfig.isRefresh
|
||||||
|
) {
|
||||||
|
await config.timelineNeedleConfig.resetFunc();
|
||||||
|
}
|
||||||
setNeedle((p) => {
|
setNeedle((p) => {
|
||||||
needleState.origin = p;
|
needleState.origin = p;
|
||||||
return p;
|
return p;
|
||||||
});
|
});
|
||||||
needleState.isDrag = true;
|
needleState.isDrag = true;
|
||||||
needleState.startX = e.clientX;
|
needleState.startX = e.clientX;
|
||||||
|
config.blockForceUpdate.forEach((v) => {
|
||||||
|
v();
|
||||||
|
});
|
||||||
if (timer) {
|
if (timer) {
|
||||||
window.clearInterval(timer);
|
window.clearInterval(timer);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
const needleMoveEvent = (
|
export const needleMoveEvent = (config: UserConfig) => {
|
||||||
setNeedle: React.Dispatch<React.SetStateAction<number>>,
|
const setNeedle = config.timelineNeedleConfig.setNeedle;
|
||||||
config: UserConfig
|
|
||||||
) => {
|
|
||||||
return {
|
return {
|
||||||
onMouseMove: (e: React.MouseEvent) => {
|
onMouseMove: async (e: React.MouseEvent) => {
|
||||||
if (needleState.isDrag) {
|
if (needleState.isDrag) {
|
||||||
console.log('move', e.clientX, config);
|
e.persist(); //不加这个很容易导致clientx为null
|
||||||
const diff = e.clientX - needleState.startX;
|
const diff = e.clientX - needleState.startX;
|
||||||
setNeedle(() => {
|
setNeedle(() => {
|
||||||
const shouldMoveX = needleState.origin + diff;
|
const shouldMoveX = needleState.origin + diff;
|
||||||
if (shouldMoveX < initialLeft) {
|
if (shouldMoveX < initialLeft) {
|
||||||
|
config.timelineNeedleConfig.current = 0;
|
||||||
return initialLeft;
|
return initialLeft;
|
||||||
} else if (shouldMoveX > ruleWidth) {
|
} else if (shouldMoveX > ruleWidth) {
|
||||||
|
config.timelineNeedleConfig.current = (ruleWidth - initialLeft) / 20;
|
||||||
return ruleWidth;
|
return ruleWidth;
|
||||||
} else {
|
} else {
|
||||||
|
config.timelineNeedleConfig.current = (shouldMoveX - initialLeft) / 20;
|
||||||
return shouldMoveX;
|
return shouldMoveX;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
config.timelineNeedleConfig.status = 'stop';
|
||||||
|
config.blockForceUpdate.forEach((v) => {
|
||||||
|
v();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onMouseUp: () => {
|
onMouseUp: () => {
|
||||||
console.log('up');
|
|
||||||
needleState.isDrag = false;
|
needleState.isDrag = false;
|
||||||
needleState.startX = 0;
|
needleState.startX = 0;
|
||||||
},
|
},
|
||||||
onDoubleClick: (e: React.MouseEvent) => {
|
onDoubleClick: () => {
|
||||||
console.log('dbclick', e.clientX, (e.target as HTMLDivElement).getBoundingClientRect().width);
|
// 这个暂时搞不定,可以在起始点埋个点位得到坐标值进行计算。
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -336,6 +350,7 @@ export function TimeLine(props: TimeLineProps) {
|
|||||||
await needleReset();
|
await needleReset();
|
||||||
}
|
}
|
||||||
props.config.timelineNeedleConfig.status = 'start';
|
props.config.timelineNeedleConfig.status = 'start';
|
||||||
|
props.config.timelineNeedleConfig.isRefresh = false;
|
||||||
refreshBlock();
|
refreshBlock();
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
timer = window.setInterval(() => {
|
timer = window.setInterval(() => {
|
||||||
@@ -367,6 +382,7 @@ export function TimeLine(props: TimeLineProps) {
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
props.config.timelineNeedleConfig.status = 'pause';
|
props.config.timelineNeedleConfig.status = 'pause';
|
||||||
props.config.timelineNeedleConfig.current = 0;
|
props.config.timelineNeedleConfig.current = 0;
|
||||||
|
props.config.timelineNeedleConfig.isRefresh = true;
|
||||||
setNeedle(initialLeft);
|
setNeedle(initialLeft);
|
||||||
refreshBlock();
|
refreshBlock();
|
||||||
res();
|
res();
|
||||||
@@ -376,6 +392,7 @@ export function TimeLine(props: TimeLineProps) {
|
|||||||
|
|
||||||
const needlePause = () => {
|
const needlePause = () => {
|
||||||
props.config.timelineNeedleConfig.status = 'pause';
|
props.config.timelineNeedleConfig.status = 'pause';
|
||||||
|
props.config.timelineNeedleConfig.isRefresh = false;
|
||||||
if (timer) {
|
if (timer) {
|
||||||
window.clearInterval(timer);
|
window.clearInterval(timer);
|
||||||
}
|
}
|
||||||
@@ -385,7 +402,7 @@ export function TimeLine(props: TimeLineProps) {
|
|||||||
props.config.timelineNeedleConfig.resetFunc = needleReset;
|
props.config.timelineNeedleConfig.resetFunc = needleReset;
|
||||||
props.config.timelineNeedleConfig.runFunc = needlePlay;
|
props.config.timelineNeedleConfig.runFunc = needlePlay;
|
||||||
props.config.timelineNeedleConfig.pauseFunc = needlePause;
|
props.config.timelineNeedleConfig.pauseFunc = needlePause;
|
||||||
|
props.config.timelineNeedleConfig.setNeedle = setNeedle;
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={`${props.classes} ant-menu yh-timeline-wrap`}
|
className={`${props.classes} ant-menu yh-timeline-wrap`}
|
||||||
@@ -433,6 +450,7 @@ export function TimeLine(props: TimeLineProps) {
|
|||||||
cursor: 'pointer',
|
cursor: 'pointer',
|
||||||
marginRight: '10px',
|
marginRight: '10px',
|
||||||
}}
|
}}
|
||||||
|
title="reset"
|
||||||
>
|
>
|
||||||
<ReloadOutlined
|
<ReloadOutlined
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
@@ -446,6 +464,7 @@ export function TimeLine(props: TimeLineProps) {
|
|||||||
cursor: 'pointer',
|
cursor: 'pointer',
|
||||||
marginRight: '10px',
|
marginRight: '10px',
|
||||||
}}
|
}}
|
||||||
|
title="pause"
|
||||||
>
|
>
|
||||||
<PauseCircleOutlined
|
<PauseCircleOutlined
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
@@ -478,7 +497,6 @@ export function TimeLine(props: TimeLineProps) {
|
|||||||
overflow: 'hidden',
|
overflow: 'hidden',
|
||||||
position: 'relative',
|
position: 'relative',
|
||||||
}}
|
}}
|
||||||
{...needleMoveEvent(setNeedle, props.config)}
|
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
className="yh-timeline-needle-head"
|
className="yh-timeline-needle-head"
|
||||||
|
@@ -356,11 +356,13 @@ export class UserConfig {
|
|||||||
scrollDom: null,
|
scrollDom: null,
|
||||||
};
|
};
|
||||||
public timelineNeedleConfig: TimeLineNeedleConfigType = {
|
public timelineNeedleConfig: TimeLineNeedleConfigType = {
|
||||||
status: 'stop',
|
status: 'start',
|
||||||
runFunc: () => {},
|
runFunc: () => {},
|
||||||
resetFunc: () => {},
|
resetFunc: () => {},
|
||||||
pauseFunc: () => {},
|
pauseFunc: () => {},
|
||||||
|
setNeedle: () => {},
|
||||||
current: 0,
|
current: 0,
|
||||||
|
isRefresh: true,
|
||||||
};
|
};
|
||||||
public blockForceUpdate: Array<Function> = [];
|
public blockForceUpdate: Array<Function> = [];
|
||||||
public waitAnimate = false;
|
public waitAnimate = false;
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { RefObject } from 'react';
|
import React, { RefObject } from 'react';
|
||||||
import { blockFocus, containerFocusRemove } from '../focusHandler';
|
import { blockFocus, containerFocusRemove } from '../focusHandler';
|
||||||
import { marklineConfig } from '../markline/marklineConfig';
|
import { marklineConfig } from '../markline/marklineConfig';
|
||||||
import { resizerMouseMove, resizerMouseUp } from '../resizeHandler';
|
import { resizerMouseMove, resizerMouseUp } from '../resizeHandler';
|
||||||
@@ -14,6 +14,7 @@ import { rotateMouseMove, rotateMouseUp } from '../rotateHandler';
|
|||||||
import { specialCoList } from '../utils/special';
|
import { specialCoList } from '../utils/special';
|
||||||
import { marklineState } from '../markline/state';
|
import { marklineState } from '../markline/state';
|
||||||
import { itemHeight } from '../../components/timeLine/timelineItem';
|
import { itemHeight } from '../../components/timeLine/timelineItem';
|
||||||
|
import { needleMoveEvent } from '../../components/timeLine/timeline';
|
||||||
|
|
||||||
export const innerDrag = function (
|
export const innerDrag = function (
|
||||||
item: IBlockType,
|
item: IBlockType,
|
||||||
@@ -150,6 +151,7 @@ export const innerContainerDragUp = function (config: UserConfig) {
|
|||||||
marklineState.sortRight = null;
|
marklineState.sortRight = null;
|
||||||
marklineState.sortBottom = null;
|
marklineState.sortBottom = null;
|
||||||
iframeWrapperMove(config);
|
iframeWrapperMove(config);
|
||||||
|
needleMoveEvent(config).onMouseUp();
|
||||||
wrapperMoveMouseUp(config);
|
wrapperMoveMouseUp(config);
|
||||||
selectRangeMouseUp(e, config);
|
selectRangeMouseUp(e, config);
|
||||||
if (innerDragState.ref && innerDragState.ref.current) {
|
if (innerDragState.ref && innerDragState.ref.current) {
|
||||||
@@ -171,5 +173,8 @@ export const innerContainerDragUp = function (config: UserConfig) {
|
|||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
onMouseUp,
|
onMouseUp,
|
||||||
|
onMouseMove: (e: React.MouseEvent) => {
|
||||||
|
needleMoveEvent(config).onMouseMove(e);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user