Skip to content

Commit

Permalink
Merge pull request #831 from navaronbracke/fix_scan_window_completion
Browse files Browse the repository at this point in the history
fix: fix updateScanWindow() not completing on Android and MacOS
  • Loading branch information
navaronbracke authored Oct 25, 2023
2 parents da34970 + 2938eda commit 30b037c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## NEXT
Bugs fixed:
* Fixed the `updateScanWindow()` function not completing on Android and MacOS. (thanks @navaronbracke !)

## 3.5.1
Improvements:
* The `type` of an `Address` is now non-null.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class MobileScannerHandler(
"analyzeImage" -> analyzeImage(call, result)
"setScale" -> setScale(call, result)
"resetScale" -> resetScale(result)
"updateScanWindow" -> updateScanWindow(call)
"updateScanWindow" -> updateScanWindow(call, result)
else -> result.notImplemented()
}
}
Expand Down Expand Up @@ -263,7 +263,9 @@ class MobileScannerHandler(
}
}

private fun updateScanWindow(call: MethodCall) {
private fun updateScanWindow(call: MethodCall, result: MethodChannel.Result) {
mobileScanner!!.scanWindow = call.argument<List<Float>?>("rect")

result.success(null)
}
}
6 changes: 4 additions & 2 deletions macos/Classes/MobileScannerPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler,
case "stop":
stop(result)
case "updateScanWindow":
updateScanWindow(call)
updateScanWindow(call, result)
default:
result(FlutterMethodNotImplemented)
}
Expand Down Expand Up @@ -187,11 +187,12 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler,
}
}

func updateScanWindow(_ call: FlutterMethodCall) {
func updateScanWindow(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) {
let argReader = MapArgumentReader(call.arguments as? [String: Any])
let scanWindowData: Array? = argReader.floatArray(key: "rect")

if (scanWindowData == nil) {
result(nil)
return
}

Expand All @@ -202,6 +203,7 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler,
let height = scanWindowData![3] - minY

scanWindow = CGRect(x: minX, y: minY, width: width, height: height)
result(nil)
}

func isBarCodeInScanWindow(_ scanWindow: CGRect, _ barcode: VNBarcodeObservation, _ inputImage: CGImage) -> Bool {
Expand Down

0 comments on commit 30b037c

Please sign in to comment.