1
1
module . exports = function createQRScanner ( cordova ) {
2
+ var initialStyles = { ...document . body . style } ;
3
+ var backgroundTransparent = true ;
4
+ var backgroundTimeouts = [ ] ;
5
+
2
6
// The native implementations should return their status as ['string':'string']
3
7
// dictionaries. Boolean values are encoded to '0' and '1', respectively.
4
8
function stringToBool ( string ) {
@@ -30,6 +34,21 @@ function convertStatus(statusDictionary) {
30
34
} ;
31
35
}
32
36
37
+ // Reset body style attribute and clear pending timeouts for omit unexpected style changes.
38
+ function resetBodyStyles ( ) {
39
+ setTimeout ( function ( ) {
40
+ backgroundTransparent = false ;
41
+ for ( var backgroundTimeout of backgroundTimeouts ) {
42
+ if ( backgroundTimeout ) {
43
+ clearTimeout ( backgroundTimeout ) ;
44
+ }
45
+ }
46
+ for ( var key of Object . keys ( document . body . style ) ) {
47
+ document . body . style [ key ] = initialStyles [ key ] ? initialStyles [ key ] : '' ;
48
+ }
49
+ } , 100 ) ;
50
+ }
51
+
33
52
// Simple utility method to ensure the background is transparent. Used by the
34
53
// plugin to force re-rendering immediately after the native webview background
35
54
// is made transparent.
@@ -38,9 +57,11 @@ function clearBackground() {
38
57
if ( body . style ) {
39
58
body . style . backgroundColor = 'rgba(0,0,0,0.01)' ;
40
59
body . style . backgroundImage = '' ;
41
- setTimeout ( function ( ) {
42
- body . style . backgroundColor = 'transparent' ;
43
- } , 1 ) ;
60
+ if ( backgroundTransparent ) {
61
+ backgroundTimeouts . push ( setTimeout ( function ( ) {
62
+ body . style . backgroundColor = 'transparent' ;
63
+ } , 1 ) ) ;
64
+ }
44
65
if ( body . parentNode && body . parentNode . style ) {
45
66
body . parentNode . style . backgroundColor = 'transparent' ;
46
67
body . parentNode . style . backgroundImage = '' ;
@@ -155,10 +176,12 @@ function doneCallback(callback, clear) {
155
176
156
177
return {
157
178
prepare : function ( callback ) {
179
+ backgroundTransparent = true ;
158
180
cordova . exec ( successCallback ( callback ) , errorCallback ( callback ) , 'QRScanner' , 'prepare' , [ ] ) ;
159
181
} ,
160
182
destroy : function ( callback ) {
161
183
cordova . exec ( doneCallback ( callback , true ) , null , 'QRScanner' , 'destroy' , [ ] ) ;
184
+ resetBodyStyles ( ) ;
162
185
} ,
163
186
scan : function ( callback ) {
164
187
if ( ! callback ) {
0 commit comments