diff --git a/.swiftpm/xcode/package.xcworkspace/xcuserdata/heart.xcuserdatad/UserInterfaceState.xcuserstate b/.swiftpm/xcode/package.xcworkspace/xcuserdata/heart.xcuserdatad/UserInterfaceState.xcuserstate index a640aa8..effd995 100644 Binary files a/.swiftpm/xcode/package.xcworkspace/xcuserdata/heart.xcuserdatad/UserInterfaceState.xcuserstate and b/.swiftpm/xcode/package.xcworkspace/xcuserdata/heart.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/ExampleProject/ExampleProject.xcodeproj/project.pbxproj b/ExampleProject/ExampleProject.xcodeproj/project.pbxproj index fbc35c2..940ce25 100644 --- a/ExampleProject/ExampleProject.xcodeproj/project.pbxproj +++ b/ExampleProject/ExampleProject.xcodeproj/project.pbxproj @@ -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 */ diff --git a/ExampleProject/ExampleProject.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/ExampleProject/ExampleProject.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index e786ae8..0a87ce2 100644 --- a/ExampleProject/ExampleProject.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/ExampleProject/ExampleProject.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -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 } } ] diff --git a/ExampleProject/ExampleProject.xcodeproj/project.xcworkspace/xcuserdata/heart.xcuserdatad/UserInterfaceState.xcuserstate b/ExampleProject/ExampleProject.xcodeproj/project.xcworkspace/xcuserdata/heart.xcuserdatad/UserInterfaceState.xcuserstate index d6961a1..75a0b65 100644 Binary files a/ExampleProject/ExampleProject.xcodeproj/project.xcworkspace/xcuserdata/heart.xcuserdatad/UserInterfaceState.xcuserstate and b/ExampleProject/ExampleProject.xcodeproj/project.xcworkspace/xcuserdata/heart.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/ExampleProject/ExampleProject/ModalBarcodeGenerator.swift b/ExampleProject/ExampleProject/ModalBarcodeGenerator.swift index e63823b..f8b5b8b 100644 --- a/ExampleProject/ExampleProject/ModalBarcodeGenerator.swift +++ b/ExampleProject/ExampleProject/ModalBarcodeGenerator.swift @@ -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() diff --git a/Sources/CarBode/CBBarcodeView.swift b/Sources/CarBode/CBBarcodeView.swift index edacc6c..3cb7a87 100644 --- a/Sources/CarBode/CBBarcodeView.swift +++ b/Sources/CarBode/CBBarcodeView.swift @@ -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" @@ -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, barcodeType: Binding, - orientation: Binding) { + orientation: Binding, + onGenerated: OnBarcodeGenerated? + ) { self._data = data self._barcodeType = barcodeType self._orientation = orientation - + self.onGenerated = onGenerated } - + public func makeUIView(context: UIViewRepresentableContext) -> CBBarcodeView.UIViewType { - return BarcodeView() + let view = BarcodeView() + view.onGenerated = self.onGenerated + return view } public func updateUIView(_ uiView: BarcodeView, context: UIViewRepresentableContext) { @@ -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 { @@ -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() {