Skip to content

Commit

Permalink
Merge branch 'release/2.1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
heart committed Oct 16, 2020
2 parents 20af50e + 195c4ee commit 72536f5
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 19 deletions.
20 changes: 10 additions & 10 deletions ExampleProject/ExampleProject.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
3EC5EF8523C447EE0063A687 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3EC5EF8423C447EE0063A687 /* Preview Assets.xcassets */; };
3EC5EF8823C447EE0063A687 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3EC5EF8623C447EE0063A687 /* LaunchScreen.storyboard */; };
3EC5EF9223C448A20063A687 /* ModalScannerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EC5EF9123C448A20063A687 /* ModalScannerView.swift */; };
4F737D9E2521C39F002E36F3 /* CarBode in Frameworks */ = {isa = PBXBuildFile; productRef = 4F737D9D2521C39F002E36F3 /* CarBode */; };
4F818A3825392854008491B6 /* CarBode in Frameworks */ = {isa = PBXBuildFile; productRef = 4F818A3725392854008491B6 /* CarBode */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -36,7 +36,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
4F737D9E2521C39F002E36F3 /* CarBode in Frameworks */,
4F818A3825392854008491B6 /* CarBode in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -108,7 +108,7 @@
);
name = ExampleProject;
packageProductDependencies = (
4F737D9D2521C39F002E36F3 /* CarBode */,
4F818A3725392854008491B6 /* CarBode */,
);
productName = ExampleProject;
productReference = 3EC5EF7823C447EA0063A687 /* ExampleProject.app */;
Expand Down Expand Up @@ -139,7 +139,7 @@
);
mainGroup = 3EC5EF6F23C447EA0063A687;
packageReferences = (
4F737D9C2521C39F002E36F3 /* XCRemoteSwiftPackageReference "CarBode-Barcode-Scanner-For-SwiftUI" */,
4F818A3625392854008491B6 /* XCRemoteSwiftPackageReference "CarBode-Barcode-Scanner-For-SwiftUI" */,
);
productRefGroup = 3EC5EF7923C447EA0063A687 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -368,20 +368,20 @@
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
4F737D9C2521C39F002E36F3 /* XCRemoteSwiftPackageReference "CarBode-Barcode-Scanner-For-SwiftUI" */ = {
4F818A3625392854008491B6 /* XCRemoteSwiftPackageReference "CarBode-Barcode-Scanner-For-SwiftUI" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/heart/CarBode-Barcode-Scanner-For-SwiftUI/";
repositoryURL = "https://github.com/heart/CarBode-Barcode-Scanner-For-SwiftUI";
requirement = {
branch = master;
kind = branch;
kind = upToNextMajorVersion;
minimumVersion = 2.1.1;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
4F737D9D2521C39F002E36F3 /* CarBode */ = {
4F818A3725392854008491B6 /* CarBode */ = {
isa = XCSwiftPackageProductDependency;
package = 4F737D9C2521C39F002E36F3 /* XCRemoteSwiftPackageReference "CarBode-Barcode-Scanner-For-SwiftUI" */;
package = 4F818A3625392854008491B6 /* XCRemoteSwiftPackageReference "CarBode-Barcode-Scanner-For-SwiftUI" */;
productName = CarBode;
};
/* End XCSwiftPackageProductDependency section */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"pins": [
{
"package": "CarBode",
"repositoryURL": "https://github.com/heart/CarBode-Barcode-Scanner-For-SwiftUI/",
"repositoryURL": "https://github.com/heart/CarBode-Barcode-Scanner-For-SwiftUI",
"state": {
"branch": "master",
"revision": "ec65f4ac61e7a929eb86b3590b4e4c25c254e927",
"version": null
"branch": null,
"revision": "20af50e8a6dacbb11022148ead812348e6ee51c2",
"version": "2.1.1"
}
}
]
Expand Down
51 changes: 48 additions & 3 deletions ExampleProject/ExampleProject/ModalScannerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,45 @@ import SwiftUI
import CarBode
import AVFoundation

struct cameraFrame: Shape {
func path(in rect: CGRect) -> Path {
Path { path in
let width = rect.width
let height = rect.height

path.addLines( [

CGPoint(x: 0, y: height * 0.25),
CGPoint(x: 0, y: 0),
CGPoint(x:width * 0.25, y:0)
])

path.addLines( [

CGPoint(x: width * 0.75, y: 0),
CGPoint(x: width, y: 0),
CGPoint(x:width, y:height * 0.25)
])

path.addLines( [

CGPoint(x: width, y: height * 0.75),
CGPoint(x: width, y: height),
CGPoint(x:width * 0.75, y: height)
])

path.addLines( [

CGPoint(x:width * 0.25, y: height),
CGPoint(x:0, y: height),
CGPoint(x:0, y:height * 0.75)

])

}
}
}

struct ModalScannerView: View {
@State var barcodeValue = ""
@State var torchIsOn = false
Expand All @@ -36,9 +75,9 @@ struct ModalScannerView: View {
}
}) {
if cameraPosition == .back{
Text("Swicth Camera to Front")
Text("Switch Camera to Front")
}else{
Text("Swicth Camera to Back")
Text("Switch Camera to Back")
}
}

Expand All @@ -58,22 +97,28 @@ struct ModalScannerView: View {
mockBarCode: .constant(BarcodeData(value:"My Test Data", type: .qr))
){
print("BarCodeType =",$0.type.rawValue, "Value =",$0.value)
barcodeValue = $0.value
}
onDraw: {
print("Preview View Size = \($0.cameraPreviewView.bounds)")
print("Barcode Corners = \($0.corners)")

let lineColor = UIColor.green
let fillColor = UIColor(red: 0, green: 1, blue: 0.2, alpha: 0.4)

//Draw Barcode corner
$0.draw(lineWidth: 1, lineColor: lineColor, fillColor: fillColor)

}.frame(minWidth: 0, maxWidth: .infinity, minHeight: 400, maxHeight: 400, alignment: .topLeading)
.overlay(cameraFrame()
.stroke(lineWidth: 5)
.frame(width: 500, height: 250)
.foregroundColor(.blue))

Spacer()

Text(barcodeValue)

Spacer()

}.alert(isPresented: $showingAlert) {
Alert(title: Text("Found Barcode"), message: Text("\(barcodeValue)"), dismissButton: .default(Text("Close")))
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ The preferred way of installing SwiftUIX is via the [Swift Package Manager](http
1. In Xcode, open your project and navigate to **File****Swift Packages****Add Package Dependency...**
2. Paste the repository URL (`https://github.com/heart/CarBode-Barcode-Scanner-For-SwiftUI`) and click **Next**.
3. For **Rules**, select **Branch** (with branch set to `2.1.1` ).
3. For **Rules**, select **Branch** (with branch set to `2.1.2` ).
4. Click **Finish**.

# Example project
Expand Down Expand Up @@ -280,6 +280,7 @@ CBBarcodeView(data: ..... ,
CarBode welcomes contributions in the form of GitHub issues and pull-requests.

## Changelog
- 2.1.2 When scan on difference barcode scanner will ignore the delay time
- 2.1.1 Fixed bugs
- 2.1.0 You can draw a box around the barcode
- 2.0.1 Fixed bugs
Expand Down
11 changes: 10 additions & 1 deletion Sources/CarBode/CameraPreview.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class CameraPreview: UIView {
var torchLightIsOn: Bool = false

var removeFrameTimer: Timer?

var lastScannedBarcode: BarcodeData?

init() {
super.init(frame: .zero)
Expand Down Expand Up @@ -256,9 +258,16 @@ extension CameraPreview: AVCaptureMetadataOutputObjectsDelegate {

func foundBarcode(_ barcode: BarcodeData) {
let now = Date()
if now.timeIntervalSince(lastTime) >= scanInterval {

//When scan on difference barcode scanner will ignore the delay time
if lastScannedBarcode?.value != barcode.value {
lastTime = now
onFound?(barcode)
lastScannedBarcode = barcode
}else if now.timeIntervalSince(lastTime) >= scanInterval {
lastTime = now
onFound?(barcode)
lastScannedBarcode = barcode
}
}
}
Expand Down

0 comments on commit 72536f5

Please sign in to comment.