Skip to content

Commit 585ef8b

Browse files
authored
Merge pull request #2013 from VisActor/feat/fix-issue-of-animation-custom-type
fix: fix issue of custom type
2 parents a2835c8 + 2c2a6c9 commit 585ef8b

File tree

4 files changed

+31
-9
lines changed

4 files changed

+31
-9
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"comment": "fix: fix issue of custom type\n\n",
5+
"type": "none",
6+
"packageName": "@visactor/vrender-animate"
7+
}
8+
],
9+
"packageName": "@visactor/vrender-animate",
10+
"email": "lixuef1313@163.com"
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"comment": "fix: fix issue of custom type\n\n",
5+
"type": "none",
6+
"packageName": "@visactor/vrender-components"
7+
}
8+
],
9+
"packageName": "@visactor/vrender-components",
10+
"email": "lixuef1313@163.com"
11+
}

packages/vrender-animate/src/executor/animate-executor.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
IAnimationChannelInterpolator
1313
} from './executor';
1414
import { cloneDeep, isArray, isFunction } from '@visactor/vutils';
15+
import { getCustomType } from './utils';
1516

1617
interface IAnimateExecutor {
1718
execute: (params: IAnimationConfig) => void;
@@ -171,8 +172,7 @@ export class AnimateExecutor implements IAnimateExecutor {
171172
duration: (slice.duration as number) * scale,
172173
effects: effects.map(effect => {
173174
const custom = effect.custom ?? AnimateExecutor.builtInAnimateMap[(effect.type as any) ?? 'fromTo'];
174-
const customType =
175-
custom && isFunction(custom) ? (/^class\s/.test(Function.prototype.toString.call(custom)) ? 1 : 2) : 0;
175+
const customType = getCustomType(custom);
176176
return {
177177
...effect,
178178
custom,
@@ -198,12 +198,7 @@ export class AnimateExecutor implements IAnimateExecutor {
198198
(params as IAnimationTypeConfig).custom ??
199199
AnimateExecutor.builtInAnimateMap[(params as IAnimationTypeConfig).type ?? 'fromTo'];
200200

201-
const customType =
202-
parsedParams.custom && isFunction(parsedParams.custom)
203-
? /^class\s/.test(Function.prototype.toString.call(parsedParams.custom))
204-
? 1
205-
: 2
206-
: 0;
201+
const customType = getCustomType(parsedParams.custom);
207202
parsedParams.customType = customType;
208203

209204
if (totalTime) {
@@ -565,7 +560,7 @@ export class AnimateExecutor implements IAnimateExecutor {
565560
from = parsedFromProps.from;
566561
}
567562
const custom = effect.custom ?? AnimateExecutor.builtInAnimateMap[type];
568-
const customType = (effect as any).customType;
563+
const customType = effect.custom ? (effect as any).customType : getCustomType(custom);
569564
this._handleRunAnimate(
570565
animate,
571566
custom,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { isFunction } from '@visactor/vutils';
2+
3+
export function getCustomType(custom: any): number {
4+
return custom && isFunction(custom) ? (/^class\s/.test(Function.prototype.toString.call(custom)) ? 1 : 2) : 0;
5+
}

0 commit comments

Comments
 (0)