Skip to content

Commit c5bcb7b

Browse files
committed
fix: fix reopening bug
1 parent 0a4e133 commit c5bcb7b

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

Classes/TiScannerModule.swift

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,18 @@ import PDFKit
1414

1515
@objc(TiScannerModule)
1616
class TiScannerModule: TiModule {
17+
18+
var _scanner: VNDocumentCameraViewController?
1719

18-
lazy var scanner: VNDocumentCameraViewController? = {
19-
let scannerViewController = VNDocumentCameraViewController()
20-
scannerViewController.delegate = self
20+
func scannerInstance() -> VNDocumentCameraViewController {
21+
if let scanner = _scanner {
22+
return scanner
23+
}
24+
_scanner = VNDocumentCameraViewController()
25+
_scanner!.delegate = self
2126

22-
return scannerViewController
23-
}()
27+
return _scanner!
28+
}
2429

2530
var currentScan: VNDocumentCameraScan?
2631

@@ -33,9 +38,8 @@ class TiScannerModule: TiModule {
3338
}
3439

3540
func dismissAndCleanup() {
36-
scanner?.dismiss(animated: true, completion: nil)
37-
scanner?.delegate = nil
38-
scanner = nil
41+
_scanner?.delegate = nil
42+
_scanner = nil
3943
}
4044

4145
// MARK: Public APIs
@@ -47,9 +51,7 @@ class TiScannerModule: TiModule {
4751

4852
@objc(showScanner:)
4953
func showScanner(unused: [Any]?) {
50-
if let scanner = scanner {
51-
TiApp.controller().present(scanner, animated: true, completion: nil)
52-
}
54+
TiApp.controller().present(scannerInstance(), animated: true, completion: nil)
5355
}
5456

5557
@objc(imageOfPageAtIndex:)
@@ -119,18 +121,24 @@ class TiScannerModule: TiModule {
119121
extension TiScannerModule: VNDocumentCameraViewControllerDelegate {
120122
func documentCameraViewControllerDidCancel(_ controller: VNDocumentCameraViewController) {
121123
fireEvent("cancel")
124+
125+
controller.dismiss(animated: true, completion: nil)
122126
dismissAndCleanup()
123127
}
124128

125129
func documentCameraViewController(_ controller: VNDocumentCameraViewController, didFailWithError error: Error) {
126130
fireEvent("error", with: ["error": error.localizedDescription])
131+
132+
controller.dismiss(animated: true, completion: nil)
127133
dismissAndCleanup()
128134
}
129135

130136
func documentCameraViewController(_ controller: VNDocumentCameraViewController, didFinishWith scan: VNDocumentCameraScan) {
131137
currentScan = scan
132138

133139
fireEvent("success", with: ["count": scan.pageCount, "title": scan.title])
140+
141+
controller.dismiss(animated: true, completion: nil)
134142
dismissAndCleanup()
135143
}
136144
}

manifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# this is your module manifest and used by Titanium
33
# during compilation, packaging, distribution, etc.
44
#
5-
version: 3.0.0
5+
version: 3.0.1
66
apiversion: 2
77
architectures: arm64 x86_64
88
description: titanium-scanner

titanium.xcconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// OF YOUR TITANIUM SDK YOU'RE BUILDING FOR
55
//
66
//
7-
TITANIUM_SDK_VERSION = 10.1.0.GA
7+
TITANIUM_SDK_VERSION = 10.1.1.GA
88

99
//
1010
// THESE SHOULD BE OK GENERALLY AS-IS

0 commit comments

Comments
 (0)