Skip to content

Commit 3e92a09

Browse files
committed
use requestAnimationFrame (ref #123)
1 parent 802a2da commit 3e92a09

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

packages/react-ape/renderer/core/render.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ function renderApeQueue(
2222
onFinish: () => mixed
2323
) {
2424
if (apeContextGlobal && apeContextGlobal.renderQueue.length) {
25-
// const renderFrame = () => {
26-
// requestAnimationFrame(renderFrame);
27-
// apeContextGlobal.renderQueue.forEach(element => {
28-
// // element.render(apeContextGlobal, element.parentLayout)
29-
// renderApeElement(apeContextGlobal, element);
30-
// });
31-
// cancelAnimationFrame(renderFrame);
32-
// }
33-
// renderFrame();
25+
const queue = apeContextGlobal.renderQueue;
26+
const frame = () => {
27+
requestAnimationFrame(frame);
28+
const element = queue.shift();
29+
element.render(apeContextGlobal, element.parentLayout);
3430

35-
apeContextGlobal.renderQueue.forEach(element => {
36-
renderApeElement(apeContextGlobal, element);
37-
});
38-
onFinish();
31+
requestAnimationFrame(frame);
32+
33+
if (!queue.length) {
34+
cancelAnimationFrame(frame);
35+
onFinish();
36+
}
37+
}
38+
frame();
3939
}
4040
}
4141

packages/react-ape/renderer/reactApeRenderer.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ const ReactApeFiber = reconciler({
164164
// resetAfterCommit happens only for children changes
165165
renderQueue(apeContextGlobal, () => {
166166
apeContextGlobal.setSurfaceHeight(0);
167-
apeContextGlobal.renderQueue = [];
168167
});
169168
},
170169

@@ -187,7 +186,7 @@ const ReactApeFiber = reconciler({
187186
schedulePassiveEffects: FrameSchedulingScheduleDeferredCallback,
188187
cancelPassiveEffects: FrameSchedulingCancelDeferredCallback,
189188
noTimeout: -1,
190-
useSyncScheduling: true,
189+
useSyncScheduling: false,
191190
now: FrameSchedulingNow,
192191
isPrimaryRenderer: true,
193192
supportsMutation: true,

0 commit comments

Comments
 (0)