diff --git a/packages/accessibility/src/AccessibilityManager.js b/packages/accessibility/src/AccessibilityManager.js index cadb269..b8cdde5 100644 --- a/packages/accessibility/src/AccessibilityManager.js +++ b/packages/accessibility/src/AccessibilityManager.js @@ -41,6 +41,11 @@ */ constructor(renderer) { + /** + * @type {?HTMLElement} + * @private + */ + this._hookDiv = null; if ((Device.tablet || Device.phone) && !navigator.isCocoonJS) { this.createTouchHook(); @@ -139,6 +144,7 @@ /** * Creates the touch hooks. * + * @private */ createTouchHook() { @@ -157,10 +163,26 @@ { this.isMobileAccessibility = true; this.activate(); - document.body.removeChild(hookDiv); + this.destroyTouchHook(); }); document.body.appendChild(hookDiv); + this._hookDiv = hookDiv; + } + + /** + * Destroys the touch hooks. + * + * @private + */ + destroyTouchHook() + { + if (!this._hookDiv) + { + return; + } + document.body.removeChild(this._hookDiv); + this._hookDiv = null; } /** @@ -529,6 +551,7 @@ */ destroy() { + this.destroyTouchHook(); this.div = null; for (let i = 0; i < this.children.length; i++) diff --git a/packages/accessibility/src/AccessibilityManager.js b/packages/accessibility/src/AccessibilityManager.js index cadb269..b8cdde5 100644 --- a/packages/accessibility/src/AccessibilityManager.js +++ b/packages/accessibility/src/AccessibilityManager.js @@ -41,6 +41,11 @@ */ constructor(renderer) { + /** + * @type {?HTMLElement} + * @private + */ + this._hookDiv = null; if ((Device.tablet || Device.phone) && !navigator.isCocoonJS) { this.createTouchHook(); @@ -139,6 +144,7 @@ /** * Creates the touch hooks. * + * @private */ createTouchHook() { @@ -157,10 +163,26 @@ { this.isMobileAccessibility = true; this.activate(); - document.body.removeChild(hookDiv); + this.destroyTouchHook(); }); document.body.appendChild(hookDiv); + this._hookDiv = hookDiv; + } + + /** + * Destroys the touch hooks. + * + * @private + */ + destroyTouchHook() + { + if (!this._hookDiv) + { + return; + } + document.body.removeChild(this._hookDiv); + this._hookDiv = null; } /** @@ -529,6 +551,7 @@ */ destroy() { + this.destroyTouchHook(); this.div = null; for (let i = 0; i < this.children.length; i++) diff --git a/packages/accessibility/test/AccessibilityManager.js b/packages/accessibility/test/AccessibilityManager.js index 78509a9..662ac61 100644 --- a/packages/accessibility/test/AccessibilityManager.js +++ b/packages/accessibility/test/AccessibilityManager.js @@ -1,5 +1,6 @@ const { AccessibilityManager } = require('../'); const { CanvasRenderer } = require('@pixi/canvas-renderer'); +const Device = require('ismobilejs'); describe('PIXI.accessibility.AccessibilityManager', function () { @@ -25,4 +26,19 @@ expect(renderer.plugins.accessibility).to.be.instanceof(AccessibilityManager); renderer.destroy(); }); + + it('should remove touch hook when destroyed', function () + { + const phone = Device.phone; + + Device.phone = true; + const manager = new AccessibilityManager(); + const hookDiv = manager._hookDiv; + + expect(hookDiv).to.be.instanceof(HTMLElement); + expect(document.body.contains(hookDiv)).to.be.true; + manager.destroy(); + expect(document.body.contains(hookDiv)).to.be.false; + Device.phone = phone; + }); });