Skip to content

Commit

Permalink
Update latest code with Covve changes
Browse files Browse the repository at this point in the history
  • Loading branch information
masimplo committed Oct 4, 2023
1 parent 5eee784 commit 2b487f6
Show file tree
Hide file tree
Showing 9 changed files with 293 additions and 24 deletions.
20 changes: 20 additions & 0 deletions CovveWeScan.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Pod::Spec.new do |spec|
spec.name = 'CovveWeScan'
spec.version = '3.0.1000'
spec.summary = 'Document Scanning Made Easy for iOS'
spec.description = 'WeScan makes it easy to add scanning functionalities to your iOS app! It\'s modelled after UIImagePickerController, which makes it a breeze to use.'

spec.homepage = 'https://github.com/Covve/WeScan'
spec.license = { :type => 'MIT', :file => 'LICENSE' }
spec.authors = {
'Boris Emorine' => '[email protected]',
'Antoine van der Lee' => '[email protected]'
}
spec.source = { :git => 'https://github.com/Covve/WeScan.git', :tag => "v#{spec.version}" }


spec.swift_version = '5.0'
spec.ios.deployment_target = '10.0'
spec.source_files = 'Sources/WeScan/**/*.{h,m,swift}'
spec.resources = 'Sources/WeScan/**/*.{strings,png}'
end
16 changes: 10 additions & 6 deletions Sources/WeScan/ImageScannerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ public protocol ImageScannerControllerDelegate: NSObjectProtocol {
/// - Discussion: Your delegate's implementation of this method should dismiss the image scanner controller.
func imageScannerControllerDidCancel(_ scanner: ImageScannerController)

/// Tells the delegate that an error occurred during the user's scanning experience.
/// Go to Photos
func imageScannerControllerGoToPhotos(_ scanner: ImageScannerController)

/// Tells the delegate that an error occured during the user's scanning experience.
///
/// - Parameters:
/// - scanner: The scanner controller object managing the scanning interface.
Expand Down Expand Up @@ -65,7 +68,11 @@ public final class ImageScannerController: UINavigationController {

self.imageScannerDelegate = delegate

if #available(iOS 13.0, *) {
if #available(iOS 15.0, *) {
navigationBar.tintColor = .white
navigationBar.titleTextAttributes = [.foregroundColor: UIColor.white]
navigationBar.barStyle = .black
} else if #available(iOS 13.0, *) {
navigationBar.tintColor = .label
} else {
navigationBar.tintColor = .black
Expand Down Expand Up @@ -185,8 +192,7 @@ public struct ImageScannerResults {
/// The deskewed and cropped scan using the detected rectangle, without any filters.
public var croppedScan: ImageScannerScan

/// The enhanced scan, passed through an Adaptive Thresholding function.
/// This image will always be grayscale and may not always be available.
/// The enhanced scan, passed through an Adaptive Thresholding function. This image will always be grayscale and may not always be available.
public var enhancedScan: ImageScannerScan?

/// Whether the user selected the enhanced scan or not.
Expand All @@ -204,11 +210,9 @@ public struct ImageScannerResults {
doesUserPreferEnhancedScan: Bool = false
) {
self.detectedRectangle = detectedRectangle

self.originalScan = originalScan
self.croppedScan = croppedScan
self.enhancedScan = enhancedScan

self.doesUserPreferEnhancedScan = doesUserPreferEnhancedScan
}
}
3 changes: 1 addition & 2 deletions Sources/WeScan/Review/ReviewViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ final class ReviewViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

enhancedImageIsAvailable = results.enhancedScan != nil

enhancedImageIsAvailable = false
setupViews()
setupToolbar()
setupConstraints()
Expand Down
11 changes: 3 additions & 8 deletions Sources/WeScan/Scan/FocusRectangleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,10 @@ final class FocusRectangleView: UIView {
let finalSize: CGFloat = 80

// Here, we create the frame to be the `originalSize`, with it's center being the `touchPoint`.
self.init(
frame: CGRect(
x: touchPoint.x - (originalSize / 2),
y: touchPoint.y - (originalSize / 2),
width: originalSize,
height: originalSize
)
)
self.init(frame: CGRect(x: touchPoint.x - (originalSize / 2), y: touchPoint.y - (originalSize / 2), width: originalSize, height: originalSize))

// fix cancel button becoming unclickable when focus rectangle is drawn over it
self.isUserInteractionEnabled = false
backgroundColor = .clear
layer.borderWidth = 2.0
layer.cornerRadius = 6.0
Expand Down
12 changes: 6 additions & 6 deletions Sources/WeScan/Scan/RectangleFeaturesFunnel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ final class RectangleFeaturesFunnel {
/// Returns: The best rectangle to display given the current history.
private func bestRectangle(withCurrentlyDisplayedRectangle currentRectangle: Quadrilateral?) -> RectangleMatch? {
var bestMatch: RectangleMatch?
guard !rectangles.isEmpty else { return nil }
rectangles.reversed().forEach { rectangle in
guard !(rectangles ?? []).isEmpty else { return nil }
(rectangles ?? []).reversed().forEach { (rectangle) in
guard let best = bestMatch else {
bestMatch = rectangle
return
Expand Down Expand Up @@ -168,9 +168,9 @@ final class RectangleFeaturesFunnel {
/// Loops through all of the rectangles of the queue, and gives them a score depending on how many they match. @see `RectangleMatch.matchingScore`
private func updateRectangleMatches() {
resetMatchingScores()
guard !rectangles.isEmpty else { return }
for (i, currentRect) in rectangles.enumerated() {
for (j, rect) in rectangles.enumerated() {
guard !(rectangles ?? []).isEmpty else { return }
for (i, currentRect) in (rectangles ?? []).enumerated() {
for (j, rect) in (rectangles ?? []).enumerated() {
if j > i && currentRect.matches(rect.rectangleFeature, withThreshold: matchingThreshold) {
currentRect.matchingScore += 1
rect.matchingScore += 1
Expand All @@ -182,7 +182,7 @@ final class RectangleFeaturesFunnel {
/// Resets the matching score of all of the rectangles in the queue to 0
private func resetMatchingScores() {
guard !rectangles.isEmpty else { return }
for rectangle in rectangles {
for rectangle in rectangles ?? [] {
rectangle.matchingScore = 0
}
}
Expand Down
25 changes: 24 additions & 1 deletion Sources/WeScan/Scan/ScannerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ public final class ScannerViewController: UIViewController {
return button
}()

private lazy var photosButton: UIButton = {
let button = UIButton()
button.setTitle(NSLocalizedString("wescan.scanning.photos", tableName: nil, bundle: Bundle(for: ScannerViewController.self), value: "Photos", comment: "The photos button"), for: .normal)
button.translatesAutoresizingMaskIntoConstraints = false
button.addTarget(self, action: #selector(photosImageScannerController), for: .touchUpInside)
return button
}()

private lazy var cancelButton: UIButton = {
let button = UIButton()
button.setTitle(NSLocalizedString("wescan.scanning.cancel", tableName: nil, bundle: Bundle(for: ScannerViewController.self), value: "Cancel", comment: "The cancel button"), for: .normal)
Expand Down Expand Up @@ -126,6 +134,7 @@ public final class ScannerViewController: UIViewController {
view.addSubview(quadView)
view.addSubview(cancelButton)
view.addSubview(shutterButton)
view.addSubview(photosButton)
view.addSubview(activityIndicator)
}

Expand All @@ -144,6 +153,7 @@ public final class ScannerViewController: UIViewController {
var quadViewConstraints = [NSLayoutConstraint]()
var cancelButtonConstraints = [NSLayoutConstraint]()
var shutterButtonConstraints = [NSLayoutConstraint]()
var photosButtonConstraints = [NSLayoutConstraint]()
var activityIndicatorConstraints = [NSLayoutConstraint]()

quadViewConstraints = [
Expand All @@ -169,6 +179,10 @@ public final class ScannerViewController: UIViewController {
cancelButton.leftAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leftAnchor, constant: 24.0),
view.safeAreaLayoutGuide.bottomAnchor.constraint(equalTo: cancelButton.bottomAnchor, constant: (65.0 / 2) - 10.0)
]
photosButtonConstraints = [
photosButton.rightAnchor.constraint(equalTo: view.safeAreaLayoutGuide.rightAnchor, constant: -24.0),
view.safeAreaLayoutGuide.bottomAnchor.constraint(equalTo: photosButton.bottomAnchor, constant: (65.0 / 2) - 10.0)
]

let shutterButtonBottomConstraint = view.safeAreaLayoutGuide.bottomAnchor.constraint(equalTo: shutterButton.bottomAnchor, constant: 8.0)
shutterButtonConstraints.append(shutterButtonBottomConstraint)
Expand All @@ -177,12 +191,16 @@ public final class ScannerViewController: UIViewController {
cancelButton.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 24.0),
view.bottomAnchor.constraint(equalTo: cancelButton.bottomAnchor, constant: (65.0 / 2) - 10.0)
]
photosButtonConstraints = [
photosButton.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -24.0),
view.bottomAnchor.constraint(equalTo: photosButton.bottomAnchor, constant: (65.0 / 2) - 10.0)
]

let shutterButtonBottomConstraint = view.bottomAnchor.constraint(equalTo: shutterButton.bottomAnchor, constant: 8.0)
shutterButtonConstraints.append(shutterButtonBottomConstraint)
}

NSLayoutConstraint.activate(quadViewConstraints + cancelButtonConstraints + shutterButtonConstraints + activityIndicatorConstraints)
NSLayoutConstraint.activate(quadViewConstraints + cancelButtonConstraints + shutterButtonConstraints + photosButtonConstraints + activityIndicatorConstraints)
}

// MARK: - Tap to Focus
Expand Down Expand Up @@ -270,6 +288,11 @@ public final class ScannerViewController: UIViewController {
imageScannerController.imageScannerDelegate?.imageScannerControllerDidCancel(imageScannerController)
}

@objc private func photosImageScannerController() {
guard let imageScannerController = navigationController as? ImageScannerController else { return }
imageScannerController.imageScannerDelegate?.imageScannerControllerGoToPhotos(imageScannerController)
}

}

extension ScannerViewController: RectangleDetectionDelegateProtocol {
Expand Down
2 changes: 1 addition & 1 deletion Submodules/WeTransfer-iOS-CI
1 change: 1 addition & 0 deletions Submodules/ios-snapshot-test-case
Submodule ios-snapshot-test-case added at de1c71
Loading

0 comments on commit 2b487f6

Please sign in to comment.