Skip to content

Commit dbee184

Browse files
committed
Merge branch 'release/2.2.0'
2 parents 72536f5 + 83034fc commit dbee184

6 files changed

Lines changed: 39 additions & 11 deletions

File tree

Binary file not shown.

ExampleProject/ExampleProject.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,8 @@
372372
isa = XCRemoteSwiftPackageReference;
373373
repositoryURL = "https://github.com/heart/CarBode-Barcode-Scanner-For-SwiftUI";
374374
requirement = {
375-
kind = upToNextMajorVersion;
376-
minimumVersion = 2.1.1;
375+
branch = develop;
376+
kind = branch;
377377
};
378378
};
379379
/* End XCRemoteSwiftPackageReference section */

ExampleProject/ExampleProject.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ExampleProject/ExampleProject/ModalBarcodeGenerator.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,28 @@ struct ModalBarcodeGenerator: View {
1414
@State var dataString = "Hello Carbode"
1515
@State var barcodeType = CBBarcodeView.BarcodeType.qrCode
1616
@State var rotate = CBBarcodeView.Orientation.up
17+
18+
@State var barcodeImage: UIImage?
1719

1820
var body: some View {
1921
VStack {
2022
CBBarcodeView(data: $dataString,
2123
barcodeType: $barcodeType,
2224
orientation: $rotate)
23-
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 400, maxHeight: 400, alignment: .topLeading)
24-
25+
{ image in
26+
self.barcodeImage = image
27+
}.frame(minWidth: 0, maxWidth: .infinity, minHeight: 400, maxHeight: 400, alignment: .topLeading)
28+
29+
Spacer()
30+
Button(action: {
31+
if let barcodeImage = self.barcodeImage {
32+
print("Image Size = \(barcodeImage.size.width) x \(barcodeImage.size.height)")
33+
}
34+
}) {
35+
Text("Print BarcodeSize to output")
36+
}
37+
Spacer()
38+
2539
HStack {
2640

2741
Spacer()

Sources/CarBode/CBBarcodeView.swift

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import SwiftUI
1212
public struct CBBarcodeView: UIViewRepresentable {
1313

1414
public typealias UIViewType = BarcodeView
15+
public typealias OnBarcodeGenerated = (UIImage)->Void
1516

1617
public enum BarcodeType: String {
1718
case qrCode = "CIQRCodeGenerator"
@@ -30,19 +31,25 @@ public struct CBBarcodeView: UIViewRepresentable {
3031
@Binding public var data: String
3132
@Binding public var barcodeType: BarcodeType
3233
@Binding public var orientation: Orientation
34+
35+
private var onGenerated: OnBarcodeGenerated?
3336

3437
public init(data: Binding<String>,
3538
barcodeType: Binding<BarcodeType>,
36-
orientation: Binding<Orientation>) {
39+
orientation: Binding<Orientation>,
40+
onGenerated: OnBarcodeGenerated?
41+
) {
3742

3843
self._data = data
3944
self._barcodeType = barcodeType
4045
self._orientation = orientation
41-
46+
self.onGenerated = onGenerated
4247
}
43-
48+
4449
public func makeUIView(context: UIViewRepresentableContext<CBBarcodeView>) -> CBBarcodeView.UIViewType {
45-
return BarcodeView()
50+
let view = BarcodeView()
51+
view.onGenerated = self.onGenerated
52+
return view
4653
}
4754

4855
public func updateUIView(_ uiView: BarcodeView, context: UIViewRepresentableContext<CBBarcodeView>) {
@@ -58,6 +65,7 @@ public class BarcodeView: UIImageView {
5865

5966
private var data:String?
6067
private var barcodeType: CBBarcodeView.BarcodeType?
68+
var onGenerated: CBBarcodeView.OnBarcodeGenerated?
6169

6270
func gen(data: String?, barcodeType: CBBarcodeView.BarcodeType) {
6371
guard let string = data, !string.isEmpty else {
@@ -81,6 +89,12 @@ public class BarcodeView: UIImageView {
8189

8290
let newImage = UIImage(ciImage: scaledImage!)
8391
self.image = newImage
92+
93+
if let img = self.image {
94+
DispatchQueue.main.async {
95+
self.onGenerated?(img)
96+
}
97+
}
8498
}
8599

86100
override public func layoutSubviews() {

0 commit comments

Comments
 (0)