Skip to content

Commit

Permalink
Merge branch 'release/2.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
heart committed Sep 23, 2020
2 parents a447782 + a72186f commit 76f3d0e
Show file tree
Hide file tree
Showing 6 changed files with 429 additions and 280 deletions.
14 changes: 7 additions & 7 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 */; };
4F6DC1B2251B504C001F8285 /* CarBode in Frameworks */ = {isa = PBXBuildFile; productRef = 4F6DC1B1251B504C001F8285 /* CarBode */; };
4FF401D4251BBE5200C3F227 /* CarBode in Frameworks */ = {isa = PBXBuildFile; productRef = 4FF401D3251BBE5200C3F227 /* CarBode */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -36,7 +36,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
4F6DC1B2251B504C001F8285 /* CarBode in Frameworks */,
4FF401D4251BBE5200C3F227 /* CarBode in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -100,7 +100,7 @@
);
name = ExampleProject;
packageProductDependencies = (
4F6DC1B1251B504C001F8285 /* CarBode */,
4FF401D3251BBE5200C3F227 /* CarBode */,
);
productName = ExampleProject;
productReference = 3EC5EF7823C447EA0063A687 /* ExampleProject.app */;
Expand Down Expand Up @@ -131,7 +131,7 @@
);
mainGroup = 3EC5EF6F23C447EA0063A687;
packageReferences = (
4F6DC1B0251B504C001F8285 /* XCRemoteSwiftPackageReference "CarBode-Barcode-Scanner-For-SwiftUI" */,
4FF401D2251BBE5200C3F227 /* XCRemoteSwiftPackageReference "CarBode-Barcode-Scanner-For-SwiftUI" */,
);
productRefGroup = 3EC5EF7923C447EA0063A687 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -360,7 +360,7 @@
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
4F6DC1B0251B504C001F8285 /* XCRemoteSwiftPackageReference "CarBode-Barcode-Scanner-For-SwiftUI" */ = {
4FF401D2251BBE5200C3F227 /* XCRemoteSwiftPackageReference "CarBode-Barcode-Scanner-For-SwiftUI" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/heart/CarBode-Barcode-Scanner-For-SwiftUI";
requirement = {
Expand All @@ -371,9 +371,9 @@
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
4F6DC1B1251B504C001F8285 /* CarBode */ = {
4FF401D3251BBE5200C3F227 /* CarBode */ = {
isa = XCSwiftPackageProductDependency;
package = 4F6DC1B0251B504C001F8285 /* XCRemoteSwiftPackageReference "CarBode-Barcode-Scanner-For-SwiftUI" */;
package = 4FF401D2251BBE5200C3F227 /* XCRemoteSwiftPackageReference "CarBode-Barcode-Scanner-For-SwiftUI" */;
productName = CarBode;
};
/* End XCSwiftPackageProductDependency section */
Expand Down
47 changes: 33 additions & 14 deletions ExampleProject/ExampleProject/ModalScannerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,57 @@

import SwiftUI
import CarBode
import AVFoundation

struct ModalScannerView: View {
@State var barcodeValue = ""
@State var torchIsOn = false
@State var showingAlert = false
@State var cameraPosition = AVCaptureDevice.Position.back

var body: some View {
VStack {
Text("QRCode Scanner")

Spacer()


if cameraPosition == .back{
Text("Using back camera")
}else{
Text("Using front camera")
}

Button(action: {
if cameraPosition == .back {
cameraPosition = .front
}else{
cameraPosition = .back
}
}) {
if cameraPosition == .back{
Text("Swicth Camera to Front")
}else{
Text("Swicth Camera to Back")
}
}


Button(action: {
self.torchIsOn.toggle()
}) {
Text("Toggle Torch Light")
}

Spacer()

CBScanner(supportBarcode: [.qr, .code128])
.interval(delay: 1.0)
.found {
print("Value=\($0.value) Type=\($0.type.rawValue)")
self.barcodeValue = $0.value
self.showingAlert = true

}
.simulator(mockBarCode: BarcodeData(value: "MOCK BARCODE DATA 1234567890", type: .qr))
.torchLight(isOn: self.torchIsOn)
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 400, maxHeight: 400, alignment: .topLeading)


CBScanner(
supportBarcode: .constant([.qr, .code128]),
torchLightIsOn: $torchIsOn,
cameraPosition: $cameraPosition
){
print($0)
}.frame(minWidth: 0, maxWidth: .infinity, minHeight: 400, maxHeight: 400, alignment: .topLeading)

Spacer()

Text(barcodeValue)
Expand Down
125 changes: 93 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,22 @@ CarBode-Barcode-Scanner-For-SwiftUI/ExampleProject/ExampleProject.xcodeproj
```Swift
import SwiftUI
import CarBode
import AVFoundation //import to access barcode types you want to scan

struct ContentView: View {

var body: some View {
VStack{
CBScanner(supportBarcode: [.qr, .code128]) //Set type of barcode you want to scan
.interval(delay: 5.0) //Event will trigger every 5 seconds
.found{
//Your..Code..Here
print($0.value)
print("Barcode Type is", $0.type.rawValue)
}
}

CBScanner(
supportBarcode: .constant([.qr, .code128]), //Set type of barcode you want to scan
scanInterval: .constant(5.0) //Event will trigger every 5 seconds
){
//When the scanner found a barcode
print($0.value)
print("Barcode Type is", $0.type.rawValue)
}

}
}
```
Expand All @@ -69,6 +73,7 @@ struct ContentView: View {
```Swift
import SwiftUI
import CarBode
import AVFoundation //import to access barcode types you want to scan

@State var torchIsOn = false

Expand All @@ -77,24 +82,72 @@ struct ContentView: View {
VStack{

Button(action: {
self.torchIsOn.toggle()
self.torchIsOn.toggle() //Toggle On/Off
}) {
Text("Toggle Torch Light")
}

Spacer()

CBScanner(supportBarcode: [.qr, .code128]) //Set type of barcode you want to scan
.torchLight(isOn: self.torchIsOn) // Turn torch light on/off
.interval(delay: 5.0) //Event will trigger every 5 seconds
.found{
//Your..Code..Here
print($0.value)
print("Barcode Type is", $0.type.rawValue)
}
CBScanner(
supportBarcode: .constant([.qr, .code128]), //Set type of barcode you want to scan
scanInterval: .constant(5.0), //Event will trigger every 5 seconds
torchLightIsOn: $torchIsOn // Bind a Bool to enable/disable torch light
){
//When the scanner found a barcode
print($0.value)
print("Barcode Type is", $0.type.rawValue)
}
}
}
}
```

# Switch to front camera
```swift
import SwiftUI
import CarBode
import AVFoundation //import to access barcode types you want to scan

@State var torchIsOn = false

struct ContentView: View {
var body: some View {
VStack{

@State var cameraPosition = AVCaptureDevice.Position.back

// Click to Toggle camera
Button(action: {
if cameraPosition == .back {
cameraPosition = .front
}else{
cameraPosition = .back
}
}) {
if cameraPosition == .back{
Text("Swicth Camera to Front")
}else{
Text("Swicth Camera to Back")
}
}

Spacer()

CBScanner(
supportBarcode: .constant([.qr, .code128]), //Set type of barcode you want to scan
scanInterval: .constant(5.0), //Event will trigger every 5 seconds

cameraPosition: $cameraPosition //Bind to switch front/back camera
){
//When the scanner found a barcode
print($0.value)
print("Barcode Type is", $0.type.rawValue)
}
}
}
}

```

# Test on iOS simulator
Expand All @@ -104,19 +157,23 @@ but you can set a mock barcode for iOS simulator.

No need to remove the mock barcode from the production app it will only use for iOS simulator.
```Swift
CBScanner(supportBarcode: [.qr, .code128])
.interval(delay: 1.0)
.found{
print($0.value)
print("Barcode Type is", $0.type.rawValue)
}
.simulator(mockBarCode: "MOCK BARCODE DATA 1234567890")
CBScanner(
supportBarcode: .constant([.qr, .code128]), //Set type of barcode you want to scan
scanInterval: .constant(5.0), //Event will trigger every 5 seconds
mockBarCode: BarcodeData(value:"Mocking data", type: .qr)
){
//When you click the button on screen mock data will appear here
print($0.value)
print("Barcode Type is", $0.type.rawValue)
}
```

## Barcode Types Support
Read here [https://developer.apple.com/documentation/avfoundation/avmetadataobject/objecttype](https://developer.apple.com/documentation/avfoundation/avmetadataobject/objecttype)




# How to use barcode generator view
![SwiftUI QRCode Scanner](https://raw.githubusercontent.com/heart/CarBode-Barcode-Scanner-For-SwiftUI/master/logo/generator.png)

Expand All @@ -132,10 +189,13 @@ struct ModalBarcodeGenerator: View {
var body: some View {
var body: some View {
VStack {
CBBarcodeView(data: $dataString,
barcodeType: $barcodeType,
orientation: $rotate)
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 400, maxHeight: 400, alignment: .topLeading)
CBScanner(
supportBarcode: .constant([.qr, .code128]),
torchLightIsOn: $torchIsOn,
cameraPosition: $cameraPosition
){
print($0)
}.frame(minWidth: 0, maxWidth: .infinity, minHeight: 400, maxHeight: 400, alignment: .topLeading)
}
}
}
Expand Down Expand Up @@ -177,8 +237,9 @@ CBBarcodeView(data: ..... ,
CarBode welcomes contributions in the form of GitHub issues and pull-requests.

## Changelog
- 1.0.1 Fixed bug camera delay 10 seconds when use on modal.
- 1.2.0 Add feature allows to turn torch light on or off.
- 1.3.0 You can set a mock barcode when running with an iOS simulator.
- 1.4.0 Rename component and add new barcode generator view component
- 2.0.0 I learned many more things about SwiftUI then I decide to restructure the scanner I hope you will like it. And this version you can switch front and back camera.
- 1.5.0 Fixed bugs and you can read the barcode type when scanner found it
- 1.4.0 Rename component and add new barcode generator view component
- 1.3.0 You can set a mock barcode when running with an iOS simulator.
- 1.2.0 Add feature allows to turn torch light on or off.
- 1.0.1 Fixed bug camera delay 10 seconds when use on modal.
6 changes: 0 additions & 6 deletions Sources/CarBode/CBBarcodeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,3 @@ private extension UIImage {
return nil
}
}

struct CBBarcodeView_Previews: PreviewProvider {
static var previews: some View {
/*@START_MENU_TOKEN@*/Text("Hello, World!")/*@END_MENU_TOKEN@*/
}
}
Loading

0 comments on commit 76f3d0e

Please sign in to comment.