Skip to content

Commit

Permalink
Merge branch 'release/2.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
heart committed Oct 25, 2020
2 parents 72536f5 + 83034fc commit dbee184
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 11 deletions.
Binary file not shown.
4 changes: 2 additions & 2 deletions ExampleProject/ExampleProject.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/heart/CarBode-Barcode-Scanner-For-SwiftUI";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 2.1.1;
branch = develop;
kind = branch;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"package": "CarBode",
"repositoryURL": "https://github.com/heart/CarBode-Barcode-Scanner-For-SwiftUI",
"state": {
"branch": null,
"revision": "20af50e8a6dacbb11022148ead812348e6ee51c2",
"version": "2.1.1"
"branch": "develop",
"revision": "195c4eeeb702dbd9d72a913dd2719735b1a59027",
"version": null
}
}
]
Expand Down
Binary file not shown.
18 changes: 16 additions & 2 deletions ExampleProject/ExampleProject/ModalBarcodeGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,28 @@ struct ModalBarcodeGenerator: View {
@State var dataString = "Hello Carbode"
@State var barcodeType = CBBarcodeView.BarcodeType.qrCode
@State var rotate = CBBarcodeView.Orientation.up

@State var barcodeImage: UIImage?

var body: some View {
VStack {
CBBarcodeView(data: $dataString,
barcodeType: $barcodeType,
orientation: $rotate)
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 400, maxHeight: 400, alignment: .topLeading)

{ image in
self.barcodeImage = image
}.frame(minWidth: 0, maxWidth: .infinity, minHeight: 400, maxHeight: 400, alignment: .topLeading)

Spacer()
Button(action: {
if let barcodeImage = self.barcodeImage {
print("Image Size = \(barcodeImage.size.width) x \(barcodeImage.size.height)")
}
}) {
Text("Print BarcodeSize to output")
}
Spacer()

HStack {

Spacer()
Expand Down
22 changes: 18 additions & 4 deletions Sources/CarBode/CBBarcodeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import SwiftUI
public struct CBBarcodeView: UIViewRepresentable {

public typealias UIViewType = BarcodeView
public typealias OnBarcodeGenerated = (UIImage)->Void

public enum BarcodeType: String {
case qrCode = "CIQRCodeGenerator"
Expand All @@ -30,19 +31,25 @@ public struct CBBarcodeView: UIViewRepresentable {
@Binding public var data: String
@Binding public var barcodeType: BarcodeType
@Binding public var orientation: Orientation

private var onGenerated: OnBarcodeGenerated?

public init(data: Binding<String>,
barcodeType: Binding<BarcodeType>,
orientation: Binding<Orientation>) {
orientation: Binding<Orientation>,
onGenerated: OnBarcodeGenerated?
) {

self._data = data
self._barcodeType = barcodeType
self._orientation = orientation

self.onGenerated = onGenerated
}

public func makeUIView(context: UIViewRepresentableContext<CBBarcodeView>) -> CBBarcodeView.UIViewType {
return BarcodeView()
let view = BarcodeView()
view.onGenerated = self.onGenerated
return view
}

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

private var data:String?
private var barcodeType: CBBarcodeView.BarcodeType?
var onGenerated: CBBarcodeView.OnBarcodeGenerated?

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

let newImage = UIImage(ciImage: scaledImage!)
self.image = newImage

if let img = self.image {
DispatchQueue.main.async {
self.onGenerated?(img)
}
}
}

override public func layoutSubviews() {
Expand Down

0 comments on commit dbee184

Please sign in to comment.