@@ -103,6 +103,10 @@ cordovaModule.exports = QRScannerAdapter;
103
103
/***/ ( function ( module , exports ) {
104
104
105
105
module . exports = function createQRScanner ( cordova ) {
106
+ var initialStyles = { ...document . body . style } ;
107
+ var backgroundTransparent = true ;
108
+ var backgroundTimeouts = [ ] ;
109
+
106
110
// The native implementations should return their status as ['string':'string']
107
111
// dictionaries. Boolean values are encoded to '0' and '1', respectively.
108
112
function stringToBool ( string ) {
@@ -134,6 +138,21 @@ function convertStatus(statusDictionary) {
134
138
} ;
135
139
}
136
140
141
+ // Reset body style attribute and clear pending timeouts for omit unexpected style changes.
142
+ function resetBodyStyles ( ) {
143
+ setTimeout ( function ( ) {
144
+ backgroundTransparent = false ;
145
+ for ( var backgroundTimeout of backgroundTimeouts ) {
146
+ if ( backgroundTimeout ) {
147
+ clearTimeout ( backgroundTimeout ) ;
148
+ }
149
+ }
150
+ for ( var key of Object . keys ( document . body . style ) ) {
151
+ document . body . style [ key ] = initialStyles [ key ] ?? '' ;
152
+ }
153
+ } , 100 ) ;
154
+ }
155
+
137
156
// Simple utility method to ensure the background is transparent. Used by the
138
157
// plugin to force re-rendering immediately after the native webview background
139
158
// is made transparent.
@@ -142,16 +161,17 @@ function clearBackground() {
142
161
if ( body . style ) {
143
162
body . style . backgroundColor = 'rgba(0,0,0,0.01)' ;
144
163
body . style . backgroundImage = '' ;
145
- setTimeout ( function ( ) {
146
- body . style . backgroundColor = 'transparent' ;
147
- } , 1 ) ;
164
+ if ( backgroundTransparent ) {
165
+ backgroundTimeouts . push ( setTimeout ( function ( ) {
166
+ body . style . backgroundColor = 'transparent' ;
167
+ } , 1 ) ) ;
168
+ }
148
169
if ( body . parentNode && body . parentNode . style ) {
149
170
body . parentNode . style . backgroundColor = 'transparent' ;
150
171
body . parentNode . style . backgroundImage = '' ;
151
172
}
152
173
}
153
174
}
154
-
155
175
function errorCallback ( callback ) {
156
176
if ( ! callback ) {
157
177
return null ;
@@ -259,10 +279,12 @@ function doneCallback(callback, clear) {
259
279
260
280
return {
261
281
prepare : function ( callback ) {
282
+ backgroundTransparent = true ;
262
283
cordova . exec ( successCallback ( callback ) , errorCallback ( callback ) , 'QRScanner' , 'prepare' , [ ] ) ;
263
284
} ,
264
285
destroy : function ( callback ) {
265
286
cordova . exec ( doneCallback ( callback , true ) , null , 'QRScanner' , 'destroy' , [ ] ) ;
287
+ resetBodyStyles ( ) ;
266
288
} ,
267
289
scan : function ( callback ) {
268
290
if ( ! callback ) {
@@ -339,4 +361,4 @@ module.exports = cordova;
339
361
340
362
/***/ } )
341
363
342
- /******/ } ) ;
364
+ /******/ } ) ;
0 commit comments