GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(animations): implement getPosition in browser animation builder (… · angular/angular@5a765f0

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages
    • animations
      • src/players
        • animation_group_player.ts
        • animation_player.ts
      • test
        • animation_group_player_spec.ts
    • platform-browser/animations/src
      • animation_builder.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: packages/animations/src/players/animation_group_player.ts
+7-6Lines 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-
let min = 0;
152-
this.players.forEach(player => {
153-
const p = player.getPosition();
154-
min = Math.min(p, min);
155-
});
156-
return min;
151+
const longestPlayer =
152+
this.players.reduce((longestSoFar: AnimationPlayer|null, player: AnimationPlayer) => {
153+
const newPlayerIsLongest =
154+
longestSoFar === null || player.totalTime > longestSoFar.totalTime;
155+
return newPlayerIsLongest ? player : longestSoFar;
156+
}, null);
157+
return longestPlayer != null ? longestPlayer.getPosition() : 0;
157158
}
158159

159160
beforeDestroy(): void {
Collapse file

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

Copy file name to clipboardExpand all lines: packages/animations/src/players/animation_player.ts
+5-2Lines 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
public parentPlayer: AnimationPlayer|null = null;
128129
public readonly totalTime: 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-
return 0;
192+
return this.totalTime ? this._position / this.totalTime : 1;
190193
}
191194

192195
/** @internal */
Collapse file

‎packages/animations/test/animation_group_player_spec.ts‎

Copy file name to clipboard
+41Lines 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+
const players: NoopAnimationPlayer[] = [];
16+
const groupPlayer = new AnimationGroupPlayer(players);
17+
expect(groupPlayer.getPosition()).toBe(0);
18+
}));
19+
20+
it('should getPosition of a single player in a group', fakeAsync(() => {
21+
const player = new NoopAnimationPlayer(5, 5);
22+
player.setPosition(0.2);
23+
const players = [player];
24+
const groupPlayer = new AnimationGroupPlayer(players);
25+
expect(groupPlayer.getPosition()).toBe(0.2);
26+
}));
27+
28+
it('should getPosition based on the longest player in the group', fakeAsync(() => {
29+
const longestPlayer = new NoopAnimationPlayer(5, 5);
30+
longestPlayer.setPosition(0.2);
31+
const players = [
32+
new NoopAnimationPlayer(1, 4),
33+
new NoopAnimationPlayer(4, 1),
34+
new NoopAnimationPlayer(7, 0),
35+
longestPlayer,
36+
new NoopAnimationPlayer(1, 1),
37+
];
38+
const groupPlayer = new AnimationGroupPlayer(players);
39+
expect(groupPlayer.getPosition()).toBe(0.2);
40+
}));
41+
});
Collapse file

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

Copy file name to clipboardExpand all lines: packages/platform-browser/animations/src/animation_builder.ts
+1-1Lines 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-
return 0;
114+
return this._renderer.engine.players[+this.id]?.getPosition() ?? 0;
115115
}
116116

117117
public totalTime = 0;

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.