Skip to content

Commit 044e2c3

Browse files
committed
fix(barcode-scanner): resolve scan() after cleanup in windowed mode on iOS
Reorder operations in metadataOutput so that dismantleCamera() and webview restoration run before invoke.resolve(). Previously, resolve() was called first and destroy() immediately after, which restored webView.isOpaque before the IPC response reached JavaScript — causing the scan() promise to never settle in windowed mode.
1 parent 84dd8ec commit 044e2c3

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

plugins/barcode-scanner/ios/Sources/BarcodeScannerPlugin.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,19 @@ class BarcodeScannerPlugin: Plugin, AVCaptureMetadataOutputObjectsDelegate {
122122
jsObject["content"] = found.stringValue
123123
}
124124

125-
invoke?.resolve(jsObject)
126-
// Stop processing further detections immediately to prevent
127-
// duplicate resolve calls during the delay window below.
125+
// Stop scanning and clean up camera and webview state before
126+
// resolving. In windowed mode, restoring webView.isOpaque after
127+
// resolve() prevents the IPC response from reaching JavaScript.
128128
self.isScanning = false
129-
// Delay destroy so the IPC response reaches the JS layer before
130-
// the webview properties (isOpaque, backgroundColor) are restored.
131-
// Without this, the promise returned by scan() never resolves in
132-
// windowed mode on iOS.
133-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { [weak self] in
134-
self?.destroy()
129+
dismantleCamera()
130+
if windowed {
131+
let backgroundColor = previousBackgroundColor ?? UIColor.white
132+
webView.isOpaque = true
133+
webView.backgroundColor = backgroundColor
134+
webView.scrollView.backgroundColor = backgroundColor
135135
}
136+
invoke?.resolve(jsObject)
137+
invoke = nil
136138

137139
}
138140
}

0 commit comments

Comments
 (0)