Skip to content

Commit b29265f

Browse files
committed
fix(canvas): native raf
1 parent 7da0315 commit b29265f

2 files changed

Lines changed: 38 additions & 4 deletions

File tree

packages/canvas/Canvas/index.android.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,23 @@ export class Canvas extends CanvasBase {
154154
this._canvas.setEnabled(value);
155155
}
156156

157+
onLoaded(): void {
158+
super.onLoaded();
159+
if (this.__native__context && this._didPause) {
160+
this.__native__context.__startRaf();
161+
this._didPause = false;
162+
}
163+
}
164+
165+
onUnloaded(): void {
166+
super.onUnloaded();
167+
if (!this.__native__context) {
168+
return;
169+
}
170+
this._didPause = true;
171+
this.__native__context.__stopRaf();
172+
}
173+
157174
// @ts-ignore
158175
get android() {
159176
return this._canvas;

packages/canvas/Canvas/index.ios.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,19 @@ export class Canvas extends CanvasBase {
8686
this._readyListener = listener.new();
8787
this._canvas.setListener(this._readyListener);
8888
this._canvas.enterBackgroundListener = () => {
89-
if (!this.native) {
89+
if (!this.__native__context) {
9090
return;
9191
}
92-
this.native.__stopRaf();
92+
this.__native__context.__stopRaf();
9393
};
9494

9595
(global as any).__canvasLoaded = true;
9696

9797
this._canvas.becomeActiveListener = () => {
98-
if (!this.native) {
98+
if (!this.__native__context) {
9999
return;
100100
}
101-
this.native.__startRaf();
101+
this.__native__context.__startRaf();
102102
};
103103

104104
this._canvas.touchEventListener = (event, recognizer) => {
@@ -132,6 +132,23 @@ export class Canvas extends CanvasBase {
132132
this._canvas.userInteractionEnabled = value;
133133
}
134134

135+
onLoaded(): void {
136+
super.onLoaded();
137+
if (this.__native__context && this._didPause) {
138+
this.__native__context.__startRaf();
139+
this._didPause = false;
140+
}
141+
}
142+
143+
onUnloaded(): void {
144+
super.onUnloaded();
145+
if (!this.__native__context) {
146+
return;
147+
}
148+
this._didPause = true;
149+
this.__native__context.__stopRaf();
150+
}
151+
135152
// @ts-ignore
136153
get ios() {
137154
return this._canvas;

0 commit comments

Comments
 (0)