@capgo/camera-preview 8.14.1 → 8.14.2
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.
- package/ios/Sources/CapgoCameraPreviewPlugin/CameraController.swift +3 -1
- package/ios/Sources/CapgoCameraPreviewPlugin/CaptureLifecycleCoordination.swift +12 -13
- package/ios/Sources/CapgoCameraPreviewPlugin/Plugin.swift +6 -5
- package/ios/Tests/CameraPreviewPluginTests/CaptureLifecycleCoordinationTests.swift +46 -7
- package/package.json +1 -1
|
@@ -542,7 +542,9 @@ class CameraController: NSObject, CXCallObserverDelegate {
|
|
|
542
542
|
func finishPhotoCaptureLifecycle() {
|
|
543
543
|
let work = { [weak self] in
|
|
544
544
|
guard let self = self else { return }
|
|
545
|
-
CaptureLifecycleCoordination.finishCapture(state: &self.captureLifecycle
|
|
545
|
+
if CaptureLifecycleCoordination.finishCapture(state: &self.captureLifecycle) {
|
|
546
|
+
self.cleanup()
|
|
547
|
+
}
|
|
546
548
|
}
|
|
547
549
|
if Thread.isMainThread {
|
|
548
550
|
work()
|
|
@@ -51,30 +51,29 @@ enum CaptureLifecycleCoordination {
|
|
|
51
51
|
return true
|
|
52
52
|
}
|
|
53
53
|
/// Handles `stop()` when a capture may be in flight. Call on the main thread only.
|
|
54
|
+
/// Returns whether the caller should run teardown cleanup after this call returns (avoids `inout` overlap).
|
|
55
|
+
@discardableResult
|
|
54
56
|
static func handleStop(
|
|
55
57
|
state: inout CaptureLifecycleState,
|
|
56
|
-
force: Bool
|
|
57
|
-
|
|
58
|
-
) {
|
|
58
|
+
force: Bool
|
|
59
|
+
) -> Bool {
|
|
59
60
|
if state.isCapturingPhoto && !force {
|
|
60
61
|
state.stopRequestedAfterCapture = true
|
|
61
|
-
return
|
|
62
|
+
return false
|
|
62
63
|
}
|
|
63
64
|
if force {
|
|
64
65
|
state.stopRequestedAfterCapture = false
|
|
65
66
|
}
|
|
66
|
-
|
|
67
|
+
return true
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
/// Ends the capture lifecycle after processing completes. Call on the main thread only.
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
) {
|
|
71
|
+
/// Returns whether the caller should run teardown cleanup after this call returns (avoids `inout` overlap).
|
|
72
|
+
@discardableResult
|
|
73
|
+
static func finishCapture(state: inout CaptureLifecycleState) -> Bool {
|
|
74
74
|
state.isCapturingPhoto = false
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
75
|
+
guard state.stopRequestedAfterCapture else { return false }
|
|
76
|
+
state.stopRequestedAfterCapture = false
|
|
77
|
+
return true
|
|
79
78
|
}
|
|
80
79
|
}
|
|
@@ -35,7 +35,7 @@ extension UIWindow {
|
|
|
35
35
|
*/
|
|
36
36
|
@objc(CameraPreview)
|
|
37
37
|
public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelegate {
|
|
38
|
-
private let pluginVersion: String = "8.14.
|
|
38
|
+
private let pluginVersion: String = "8.14.2"
|
|
39
39
|
public let identifier = "CameraPreviewPlugin"
|
|
40
40
|
public let jsName = "CameraPreview"
|
|
41
41
|
public let pluginMethods: [CAPPluginMethod] = [
|
|
@@ -1182,11 +1182,12 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
|
|
|
1182
1182
|
|
|
1183
1183
|
self.cameraController.cancelPendingSampleCapture()
|
|
1184
1184
|
|
|
1185
|
-
CaptureLifecycleCoordination.handleStop(
|
|
1185
|
+
if CaptureLifecycleCoordination.handleStop(
|
|
1186
1186
|
state: &self.cameraController.captureLifecycle,
|
|
1187
|
-
force: force
|
|
1188
|
-
|
|
1189
|
-
|
|
1187
|
+
force: force
|
|
1188
|
+
) {
|
|
1189
|
+
self.cameraController.cleanup()
|
|
1190
|
+
}
|
|
1190
1191
|
|
|
1191
1192
|
call.resolve()
|
|
1192
1193
|
}
|
|
@@ -69,13 +69,15 @@ final class CaptureLifecycleCoordinationTests: XCTestCase {
|
|
|
69
69
|
state.isCapturingPhoto = true
|
|
70
70
|
var cleanupCount = 0
|
|
71
71
|
|
|
72
|
-
CaptureLifecycleCoordination.handleStop(state: &state, force: false
|
|
72
|
+
XCTAssertFalse(CaptureLifecycleCoordination.handleStop(state: &state, force: false))
|
|
73
73
|
|
|
74
74
|
XCTAssertTrue(state.stopRequestedAfterCapture)
|
|
75
75
|
XCTAssertTrue(state.isCapturingPhoto)
|
|
76
76
|
XCTAssertEqual(cleanupCount, 0)
|
|
77
77
|
|
|
78
|
-
CaptureLifecycleCoordination.finishCapture(state: &state
|
|
78
|
+
if CaptureLifecycleCoordination.finishCapture(state: &state) {
|
|
79
|
+
cleanupCount += 1
|
|
80
|
+
}
|
|
79
81
|
|
|
80
82
|
XCTAssertFalse(state.isCapturingPhoto)
|
|
81
83
|
XCTAssertFalse(state.stopRequestedAfterCapture)
|
|
@@ -87,7 +89,9 @@ final class CaptureLifecycleCoordinationTests: XCTestCase {
|
|
|
87
89
|
state.isCapturingPhoto = true
|
|
88
90
|
var cleanupCount = 0
|
|
89
91
|
|
|
90
|
-
CaptureLifecycleCoordination.handleStop(state: &state, force: true
|
|
92
|
+
if CaptureLifecycleCoordination.handleStop(state: &state, force: true) {
|
|
93
|
+
cleanupCount += 1
|
|
94
|
+
}
|
|
91
95
|
|
|
92
96
|
XCTAssertFalse(state.stopRequestedAfterCapture)
|
|
93
97
|
XCTAssertEqual(cleanupCount, 1)
|
|
@@ -98,7 +102,9 @@ final class CaptureLifecycleCoordinationTests: XCTestCase {
|
|
|
98
102
|
state.isCapturingPhoto = true
|
|
99
103
|
var cleanupCount = 0
|
|
100
104
|
|
|
101
|
-
CaptureLifecycleCoordination.finishCapture(state: &state
|
|
105
|
+
if CaptureLifecycleCoordination.finishCapture(state: &state) {
|
|
106
|
+
cleanupCount += 1
|
|
107
|
+
}
|
|
102
108
|
|
|
103
109
|
XCTAssertFalse(state.isCapturingPhoto)
|
|
104
110
|
XCTAssertFalse(state.stopRequestedAfterCapture)
|
|
@@ -110,7 +116,9 @@ final class CaptureLifecycleCoordinationTests: XCTestCase {
|
|
|
110
116
|
state.isCapturingPhoto = false
|
|
111
117
|
var cleanupCount = 0
|
|
112
118
|
|
|
113
|
-
CaptureLifecycleCoordination.handleStop(state: &state, force: false
|
|
119
|
+
if CaptureLifecycleCoordination.handleStop(state: &state, force: false) {
|
|
120
|
+
cleanupCount += 1
|
|
121
|
+
}
|
|
114
122
|
|
|
115
123
|
XCTAssertFalse(state.stopRequestedAfterCapture)
|
|
116
124
|
XCTAssertEqual(cleanupCount, 1)
|
|
@@ -123,8 +131,12 @@ final class CaptureLifecycleCoordinationTests: XCTestCase {
|
|
|
123
131
|
let finishExpectation = expectation(description: "finish on main")
|
|
124
132
|
|
|
125
133
|
DispatchQueue.main.async {
|
|
126
|
-
CaptureLifecycleCoordination.handleStop(state: &state, force: false
|
|
127
|
-
|
|
134
|
+
if CaptureLifecycleCoordination.handleStop(state: &state, force: false) {
|
|
135
|
+
cleanupCount += 1
|
|
136
|
+
}
|
|
137
|
+
if CaptureLifecycleCoordination.finishCapture(state: &state) {
|
|
138
|
+
cleanupCount += 1
|
|
139
|
+
}
|
|
128
140
|
finishExpectation.fulfill()
|
|
129
141
|
}
|
|
130
142
|
|
|
@@ -132,4 +144,31 @@ final class CaptureLifecycleCoordinationTests: XCTestCase {
|
|
|
132
144
|
XCTAssertEqual(cleanupCount, 1)
|
|
133
145
|
XCTAssertFalse(state.stopRequestedAfterCapture)
|
|
134
146
|
}
|
|
147
|
+
|
|
148
|
+
/// Mirrors `stop()` -> `cleanup()` -> `cancelPendingSampleCapture()` reading `captureLifecycle` after coordination returns.
|
|
149
|
+
func testStopCoordinationReleasesStateBeforeCleanupReadsLifecycle() {
|
|
150
|
+
final class LifecycleHost {
|
|
151
|
+
var captureLifecycle = CaptureLifecycleState()
|
|
152
|
+
var cleanupInvocationCount = 0
|
|
153
|
+
|
|
154
|
+
func runStop(force: Bool) {
|
|
155
|
+
if CaptureLifecycleCoordination.handleStop(state: &captureLifecycle, force: force) {
|
|
156
|
+
performCleanup()
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private func performCleanup() {
|
|
161
|
+
cleanupInvocationCount += 1
|
|
162
|
+
CaptureLifecycleCoordination.cancelAwaitingSampleCaptureIfNeeded(
|
|
163
|
+
isAwaiting: captureLifecycle.isAwaitingSampleCapture
|
|
164
|
+
) {}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
let host = LifecycleHost()
|
|
169
|
+
host.captureLifecycle.isAwaitingSampleCapture = true
|
|
170
|
+
host.runStop(force: false)
|
|
171
|
+
XCTAssertEqual(host.cleanupInvocationCount, 1)
|
|
172
|
+
XCTAssertTrue(host.captureLifecycle.isAwaitingSampleCapture)
|
|
173
|
+
}
|
|
135
174
|
}
|