Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5a765f0

Browse files
literalpiemhevery
authored andcommitted
fix(animations): implement getPosition in browser animation builder (#39983)
Forward `getPosition` to `animation_group_player`.PRClose#39983
1 parent03c3e07 commit5a765f0

File tree

4 files changed

+54
-9
lines changed

4 files changed

+54
-9
lines changed

‎packages/animations/src/players/animation_group_player.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,13 @@ export class AnimationGroupPlayer implements AnimationPlayer {
148148
}
149149

150150
getPosition():number{
151-
letmin=0;
152-
this.players.forEach(player=>{
153-
constp=player.getPosition();
154-
min=Math.min(p,min);
155-
});
156-
returnmin;
151+
constlongestPlayer=
152+
this.players.reduce((longestSoFar:AnimationPlayer|null,player:AnimationPlayer)=>{
153+
constnewPlayerIsLongest=
154+
longestSoFar===null||player.totalTime>longestSoFar.totalTime;
155+
returnnewPlayerIsLongest ?player :longestSoFar;
156+
},null);
157+
returnlongestPlayer!=null ?longestPlayer.getPosition() :0;
157158
}
158159

159160
beforeDestroy():void{

‎packages/animations/src/players/animation_player.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ export class NoopAnimationPlayer implements AnimationPlayer {
124124
private_started=false;
125125
private_destroyed=false;
126126
private_finished=false;
127+
private_position=0;
127128
publicparentPlayer:AnimationPlayer|null=null;
128129
publicreadonlytotalTime:number;
129130
constructor(duration:number=0,delay:number=0){
@@ -184,9 +185,11 @@ export class NoopAnimationPlayer implements AnimationPlayer {
184185
}
185186
}
186187
reset():void{}
187-
setPosition(position:number):void{}
188+
setPosition(position:number):void{
189+
this._position=this.totalTime ?position*this.totalTime :1;
190+
}
188191
getPosition():number{
189-
return0;
192+
returnthis.totalTime ?this._position/this.totalTime :1;
190193
}
191194

192195
/**@internal */
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
*@license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
import{fakeAsync}from'@angular/core/testing';
9+
import{NoopAnimationPlayer}from'../src/animations';
10+
import{AnimationGroupPlayer}from'../src/players/animation_group_player';
11+
12+
13+
describe('AnimationGroupPlayer',()=>{
14+
it('should getPosition of an empty group',fakeAsync(()=>{
15+
constplayers:NoopAnimationPlayer[]=[];
16+
constgroupPlayer=newAnimationGroupPlayer(players);
17+
expect(groupPlayer.getPosition()).toBe(0);
18+
}));
19+
20+
it('should getPosition of a single player in a group',fakeAsync(()=>{
21+
constplayer=newNoopAnimationPlayer(5,5);
22+
player.setPosition(0.2);
23+
constplayers=[player];
24+
constgroupPlayer=newAnimationGroupPlayer(players);
25+
expect(groupPlayer.getPosition()).toBe(0.2);
26+
}));
27+
28+
it('should getPosition based on the longest player in the group',fakeAsync(()=>{
29+
constlongestPlayer=newNoopAnimationPlayer(5,5);
30+
longestPlayer.setPosition(0.2);
31+
constplayers=[
32+
newNoopAnimationPlayer(1,4),
33+
newNoopAnimationPlayer(4,1),
34+
newNoopAnimationPlayer(7,0),
35+
longestPlayer,
36+
newNoopAnimationPlayer(1,1),
37+
];
38+
constgroupPlayer=newAnimationGroupPlayer(players);
39+
expect(groupPlayer.getPosition()).toBe(0.2);
40+
}));
41+
});

‎packages/platform-browser/animations/src/animation_builder.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export class RendererAnimationPlayer implements AnimationPlayer {
111111
}
112112

113113
getPosition():number{
114-
return0;
114+
returnthis._renderer.engine.players[+this.id]?.getPosition()??0;
115115
}
116116

117117
publictotalTime=0;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp