Skip to content

Commit 64d6507

Browse files
committed
refactor: optimize animation loops in Portal canvases (#8790)
1 parent e4523c6 commit 64d6507

3 files changed

Lines changed: 28 additions & 67 deletions

File tree

apps/portal/canvas/HeaderCanvas.mjs

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ class HeaderCanvas extends Base {
7373
* @protected
7474
*/
7575
className: 'Portal.canvas.HeaderCanvas',
76-
/**
77-
* @member {Number|null} animationId_=null
78-
*/
79-
animationId_: null,
8076
/**
8177
* Remote method access
8278
* @member {Object} remote
@@ -110,6 +106,10 @@ class HeaderCanvas extends Base {
110106
* @member {String|null} activeId=null
111107
*/
112108
activeId = null
109+
/**
110+
* @member {Number|null} animationId=null
111+
*/
112+
animationId = null
113113
/**
114114
* @member {String|null} canvasId=null
115115
*/
@@ -157,21 +157,6 @@ class HeaderCanvas extends Base {
157157
*/
158158
waveBuffers = {bgA: null, bgB: null, fgA: null, fgB: null}
159159

160-
/**
161-
* Triggered after the animationId config got changed
162-
* @param {Number|null} value
163-
* @param {Number|null} oldValue
164-
*/
165-
afterSetAnimationId(value, oldValue) {
166-
if (oldValue) {
167-
if (hasRaf) {
168-
cancelAnimationFrame(oldValue)
169-
} else {
170-
clearTimeout(oldValue)
171-
}
172-
}
173-
}
174-
175160
/**
176161
* Clears the graph state and stops the render loop.
177162
*/
@@ -226,7 +211,9 @@ class HeaderCanvas extends Base {
226211
me.context = canvas.getContext('2d');
227212
me.initParticles(canvas.width, canvas.height); // Init particles
228213
me.updateResources(canvas.width, canvas.height); // Init buffers/gradients
229-
hasChange && me.renderLoop()
214+
if (hasChange && !me.animationId) {
215+
me.renderLoop()
216+
}
230217
} else {
231218
setTimeout(checkCanvas, 50)
232219
}

apps/portal/canvas/HomeCanvas.mjs

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,6 @@ class HomeCanvas extends Base {
107107
* @protected
108108
*/
109109
className: 'Portal.canvas.HomeCanvas',
110-
/**
111-
* @member {Number|null} animationId_=null
112-
*/
113-
animationId_: null,
114110
/**
115111
* Remote method access for the App Worker.
116112
* Allows the UI to control the simulation state and input.
@@ -144,6 +140,10 @@ class HomeCanvas extends Base {
144140
* @member {Float32Array|null} agentBuffer=null
145141
*/
146142
agentBuffer = null
143+
/**
144+
* @member {Number|null} animationId=null
145+
*/
146+
animationId = null
147147
/**
148148
* ID of the canvas element in the DOM.
149149
* @member {String|null} canvasId=null
@@ -207,21 +207,6 @@ class HomeCanvas extends Base {
207207
*/
208208
time = 0
209209

210-
/**
211-
* Triggered after the animationId config got changed
212-
* @param {Number|null} value
213-
* @param {Number|null} oldValue
214-
*/
215-
afterSetAnimationId(value, oldValue) {
216-
if (oldValue) {
217-
if (hasRaf) {
218-
cancelAnimationFrame(oldValue)
219-
} else {
220-
clearTimeout(oldValue)
221-
}
222-
}
223-
}
224-
225210
/**
226211
* Clears the graph state and stops the render loop.
227212
* Used when the component is destroyed or the route changes.
@@ -688,7 +673,9 @@ class HomeCanvas extends Base {
688673
if (canvas) {
689674
me.context = canvas.getContext('2d');
690675
me.updateSize({width: canvas.width, height: canvas.height});
691-
hasChange && me.renderLoop()
676+
if (hasChange && !me.animationId) {
677+
me.renderLoop()
678+
}
692679
} else {
693680
setTimeout(checkCanvas, 50)
694681
}

apps/portal/canvas/ServicesCanvas.mjs

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,13 @@ class ServicesCanvas extends Base {
103103
}
104104

105105
static config = {
106-
/**
107-
* @member {String} className='Portal.canvas.ServicesCanvas'
108-
* @protected
109-
*/
110-
className: 'Portal.canvas.ServicesCanvas',
111-
/**
112-
* @member {Number|null} animationId_=null
113-
*/
114-
animationId_: null,
115-
/**
116-
* Remote method access for the App Worker.
106+
/**
107+
* @member {String} className='Portal.canvas.ServicesCanvas'
108+
* @protected
109+
*/
110+
className: 'Portal.canvas.ServicesCanvas',
111+
/**
112+
* Remote method access for the App Worker.
117113
* Allows the UI (Controller) to control the simulation state and input.
118114
* @member {Object} remote
119115
* @protected
@@ -143,6 +139,10 @@ class ServicesCanvas extends Base {
143139
theme_: 'light'
144140
}
145141

142+
/**
143+
* @member {Number|null} animationId=null
144+
*/
145+
animationId = null
146146
/**
147147
* ID of the canvas element in the DOM.
148148
* @member {String|null} canvasId=null
@@ -238,21 +238,6 @@ class ServicesCanvas extends Base {
238238
*/
239239
rotation = {x: -0.4, y: 0} // Base tilt (radians) - Floor Perspective
240240

241-
/**
242-
* Triggered after the animationId config got changed
243-
* @param {Number|null} value
244-
* @param {Number|null} oldValue
245-
*/
246-
afterSetAnimationId(value, oldValue) {
247-
if (oldValue) {
248-
if (hasRaf) {
249-
cancelAnimationFrame(oldValue)
250-
} else {
251-
clearTimeout(oldValue)
252-
}
253-
}
254-
}
255-
256241
/**
257242
* Clears the graph state and stops the render loop.
258243
* Used when the component is destroyed or the route changes to release memory.
@@ -707,7 +692,9 @@ class ServicesCanvas extends Base {
707692
if (canvas) {
708693
me.context = canvas.getContext('2d');
709694
me.updateSize({width: canvas.width, height: canvas.height});
710-
hasChange && me.renderLoop()
695+
if (hasChange && !me.animationId) {
696+
me.renderLoop()
697+
}
711698
} else {
712699
setTimeout(checkCanvas, 50)
713700
}

0 commit comments

Comments
 (0)