Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to override ScanBaseViewController #74

Closed
PiotrPawlus opened this issue Sep 3, 2019 · 7 comments
Closed

Unable to override ScanBaseViewController #74

PiotrPawlus opened this issue Sep 3, 2019 · 7 comments

Comments

@PiotrPawlus
Copy link

Both methods of protocol ScanEvents are marked as public in ScanBaseViewController. Due to this fact, we're not able to override these methods.

Is the possibility to change these methods to open?

@objc open class ScanBaseViewController: UIViewController, AVCaptureVideoDataOutputSampleBufferDelegate, ScanEvents, AfterPermissions {
    
    public func onNumberRecognized(number: String, expiry: Expiry?, cardImage: CGImage, numberBoundingBox: CGRect, expiryBoundingBox: CGRect?) {
        // relay this data to our own delegate object
        self.scanEventsDelegate?.onNumberRecognized(number: number, expiry: expiry, cardImage: cardImage, numberBoundingBox: numberBoundingBox, expiryBoundingBox: expiryBoundingBox)
    }
    
    public func onScanComplete(scanStats: ScanStats) {
        // this shouldn't get called
    }
   ...
}
@kingst
Copy link
Collaborator

kingst commented Sep 3, 2019

Hi @PiotrPawlus can you explain what you're trying to do? Most common uses of CardScan don't need to create their own ViewController and even those that choose to do so don't need to implement the ScanEvents protocol. Once I understand what you're trying to do I can try to provide some guidance.

@PiotrPawlus
Copy link
Author

I need to set a custom color for corner view, custom torch button's image and also provide localized strings when the user hasn't granted access the camera.

@kingst
Copy link
Collaborator

kingst commented Sep 3, 2019

These are all pretty reasonable UI adjustments. If we were to put options to adjust all of these in our main ScanViewController would you use it instead of needing to subclass ScanBaseViewController?

@PiotrPawlus
Copy link
Author

Yes, sure. I also looked through requirements and we also need to handle no camera granted access by using our internal components.

@yaakovgamliel
Copy link

I was also trying to subclass ScanViewController I ended up making another class that sub-classes ScanBaseViewController, in my case I don't need to use delegates so overwriting:

// Child classes should override these three functions
    @objc open func onScannedCard(number: String, expiryYear: String?, expiryMonth: String?, scannedImage: UIImage?) { }
    @objc open func showCardNumber(_ number: String, expiry: String?) { }
    @objc open func onCameraPermissionDenied(showedPrompt: Bool) { }

Plus adding a CornerView, BlurView, PreviewView and passing a UILabel in order to satisfy the CGRect required for regionOfInterestLabel
A basic subclass from ScanBaseViewController looks like this in my case:

@objc public class CustomViewController: ScanBaseViewController {

    public weak var scanDelegate: ScanDelegate?
    var blurView: BlurView!
    var previewView: PreviewView!
    var cornerView: CornerView!
    var regionOfInterestLabel: UILabel!


    override public func viewDidLoad() {
        super.viewDidLoad()
        previewView = PreviewView()
        previewView.frame = CGRect.init(x: 30.0, y: 288.0, width:700.0, height: 450.0)
        view.addSubview(previewView)

        regionOfInterestLabel = UILabel()
        regionOfInterestLabel.frame = CGRect.init(x: 30.0, y: 200.0, width:700.0, height: 450.0)
        view.addSubview(regionOfInterestLabel)

        blurView = BlurView()
        blurView.frame = CGRect.init(x: 0.0, y: 0.0, width: view.bounds.size.width, height: view.bounds.size.height)
        view.addSubview(blurView)

        cornerView = CornerView()
        cornerView.frame = CGRect.init(x: 30.0, y: 200.0, width:700.0, height: 450.0)//CGRect.init(x: 0.0, y: 0.0, width: (view.bounds.size.width / 2), height: (view.bounds.size.height / 3))
        cornerView.center = view.center
        view.addSubview(cornerView)

        self.cornerView.layer.borderColor = UIColor.green.cgColor

        setupOnViewDidLoad(regionOfInterestLabel: regionOfInterestLabel, blurView: blurView, previewView: previewView, cornerView: cornerView, debugImageView: nil)

        self.startCameraPreview()
    }

    override public func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        cornerView.backgroundColor = .cyan
        cornerView.layer.borderColor = UIColor.red.cgColor
        regionOfInterestLabel.layer.borderColor = UIColor.red.cgColor
    }

    public override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
    }

    public override func onScannedCard(number: String, expiryYear: String?, expiryMonth: String?, scannedImage: UIImage?) {
        dump(number)
        let card = CreditCard(number: number)
        card.expiryMonth = expiryMonth
        card.expiryYear = expiryYear
        card.image = scannedImage

        dump(card.description)
    }
}

@kingst
Copy link
Collaborator

kingst commented Sep 17, 2019

Here's the first PR: #77

@kingst
Copy link
Collaborator

kingst commented Sep 17, 2019

And here's the second: #78

We'll do a deploy later today to bump the Cocoapod version, but I'm going to close this issue for now. Please re-open it if you have any changes you'd like for us to make.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants