canvasframework 0.5.53 → 0.5.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -55,18 +55,29 @@ class Camera extends Component {
55
55
  }
56
56
 
57
57
  async _mount() {
58
- super._mount?.();
59
-
60
- // Redémarrage auto si besoin
61
- if (this.autoStart && !this.stream && !this.isStarting) {
62
- this.isStarting = true;
63
- await this.startCamera();
64
- this.isStarting = false;
65
- }
66
-
67
- this.setupEventListeners();
58
+ super._mount?.();
59
+
60
+ // CORRECTION : Ne démarrer que si visible ET pas en navigation
61
+ if (this.visible &&
62
+ this.autoStart &&
63
+ !this.stream &&
64
+ !this.isStarting &&
65
+ !this.framework._isNavigating) {
66
+ this.isStarting = true;
67
+ await this.startCamera();
68
+ this.isStarting = false;
69
+ }
70
+
71
+ this.setupEventListeners();
68
72
  }
69
-
73
+
74
+ onUnmount() {
75
+ this.removeEventListeners();
76
+ this.stopCamera();
77
+ if (this.flashTimer) clearTimeout(this.flashTimer);
78
+ if (this.previewTimeout) clearTimeout(this.previewTimeout);
79
+ }
80
+
70
81
  destroy() {
71
82
  this.removeEventListeners();
72
83
  this.stopCamera();
@@ -57,8 +57,8 @@ class FloatedCamera extends Component {
57
57
  async _mount() {
58
58
  super._mount?.();
59
59
 
60
- // Redémarrage auto si besoin
61
- if (this.autoStart && !this.stream && !this.isStarting) {
60
+ // CORRECTION : Ne démarrer que si visible ET pas en navigation
61
+ if (this.visible && this.autoStart && !this.stream && !this.isStarting && !this.framework._isNavigating) {
62
62
  this.isStarting = true;
63
63
  await this.startCamera();
64
64
  this.isStarting = false;
@@ -66,6 +66,13 @@ class FloatedCamera extends Component {
66
66
 
67
67
  this.setupEventListeners();
68
68
  }
69
+
70
+ onUnmount() {
71
+ this.removeEventListeners();
72
+ this.stopCamera();
73
+ if (this.flashTimer) clearTimeout(this.flashTimer);
74
+ if (this.previewTimeout) clearTimeout(this.previewTimeout);
75
+ }
69
76
 
70
77
  destroy() {
71
78
  this.removeEventListeners();
@@ -53,7 +53,8 @@ class QRCodeReader extends Component {
53
53
  async _mount() {
54
54
  super._mount?.();
55
55
 
56
- if (this.autoStart && !this.stream && !this.isStarting) {
56
+ // CORRECTION : Ne démarrer que si visible ET pas en navigation
57
+ if (this.visible && this.autoStart && !this.stream && !this.isStarting && !this.framework._isNavigating) {
57
58
  this.isStarting = true;
58
59
  await this.startCamera();
59
60
  this.isStarting = false;
@@ -61,6 +62,12 @@ class QRCodeReader extends Component {
61
62
 
62
63
  this.setupEventListeners();
63
64
  }
65
+
66
+ onUnmount() {
67
+ this.stopScanning();
68
+ this.removeEventListeners();
69
+ this.stopCamera();
70
+ }
64
71
 
65
72
  destroy() {
66
73
  this.stopScanning();
@@ -87,6 +94,22 @@ class QRCodeReader extends Component {
87
94
  document.head.appendChild(script);
88
95
  }
89
96
  }
97
+
98
+ static cleanupAllQRReaders() {
99
+ const allVideos = document.querySelectorAll('video');
100
+ allVideos.forEach(video => {
101
+ if (video.srcObject) {
102
+ const stream = video.srcObject;
103
+ if (stream && stream.getTracks) {
104
+ stream.getTracks().forEach(track => track.stop());
105
+ }
106
+ video.srcObject = null;
107
+ }
108
+ if (video.parentNode) {
109
+ video.parentNode.removeChild(video);
110
+ }
111
+ });
112
+ }
90
113
 
91
114
  setupEventListeners() {
92
115
  this.onTouchStart = this.handleTouchStart.bind(this);
@@ -126,6 +149,7 @@ class QRCodeReader extends Component {
126
149
  }
127
150
 
128
151
  async startCamera() {
152
+ QRCodeReader.cleanupAllQRReaders();
129
153
  if (this.stream) return;
130
154
 
131
155
  try {
@@ -2004,7 +2004,6 @@ class CanvasFramework {
2004
2004
  // Destroy le composant pour être sûr
2005
2005
  if (comp.destroy && typeof comp.destroy === 'function') {
2006
2006
  comp.destroy();
2007
- comp._unmount();
2008
2007
  }
2009
2008
  }
2010
2009
 
@@ -2041,9 +2040,13 @@ class CanvasFramework {
2041
2040
 
2042
2041
  // ===== CRÉER LES NOUVEAUX COMPOSANTS =====
2043
2042
  this.components = [];
2043
+ this._isNavigating = true; // ✅ Flag pour empêcher l'auto-démarrages
2044
+
2044
2045
  if (typeof route.component === 'function') {
2045
2046
  route.component(this, params, query);
2046
2047
  }
2048
+
2049
+ this._isNavigating = false; // ✅ Navigation terminée
2047
2050
 
2048
2051
  // ===== LANCER L'ANIMATION DE TRANSITION =====
2049
2052
  if (animate && !this.transitionState.isTransitioning) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canvasframework",
3
- "version": "0.5.53",
3
+ "version": "0.5.55",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/beyons/CanvasFramework.git"