-
Notifications
You must be signed in to change notification settings - Fork 121
[Scan to Pay]Add logo to the Scan to Pay QR Code #9823
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
Conversation
You can test the changes from this Pull Request by:
|
iamgabrielma
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests well! I left a suggestion to refactor UIImage+Background for readability.
As a side note, I found an "issue" when scanning the barcode: As the initial site I used is a private site, I could scan it but it redirected me to the "coming soon" page rather than the payment page.
Perhaps we should hide the button if the site is private? Or add some sort of notice. We can check this by reaching the SessionManager's defaultSite.isPublic property.
🚢
| func withBackground(color: UIColor, opaque: Bool = true) -> UIImage { | ||
| UIGraphicsBeginImageContextWithOptions(size, opaque, scale) | ||
|
|
||
| guard let ctx = UIGraphicsGetCurrentContext(), | ||
| let image = cgImage else { | ||
| return self | ||
| } | ||
|
|
||
| defer { UIGraphicsEndImageContext() } | ||
|
|
||
| let rect = CGRect(origin: .zero, size: size) | ||
| ctx.setFillColor(color.cgColor) | ||
| ctx.fill(rect) | ||
| ctx.concatenate(CGAffineTransform(a: 1, b: 0, c: 0, d: -1, tx: 0, ty: size.height)) | ||
| ctx.draw(image, in: rect) | ||
|
|
||
| return UIGraphicsGetImageFromCurrentImageContext() ?? self | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a lot happening here, so I think we could improve it by:
- Renaming
ctxtocurrentGraphicsContext - Adding internal comments
- Changing:
- ctx.concatenate(CGAffineTransform(a: 1, b: 0, c: 0, d: -1, tx: 0, ty: size.height))
+ // Flips the context vertically, then translates it vertically
+ // By default, the coordinate system in Core Graphics is different from that of UIKit
+ currentGraphicsContext.scaleBy(x: 1, y: -1)
+ currentGraphicsContext.translateBy(x: 0, y: -size.height)| func withBackground(color: UIColor, opaque: Bool = true) -> UIImage { | |
| UIGraphicsBeginImageContextWithOptions(size, opaque, scale) | |
| guard let ctx = UIGraphicsGetCurrentContext(), | |
| let image = cgImage else { | |
| return self | |
| } | |
| defer { UIGraphicsEndImageContext() } | |
| let rect = CGRect(origin: .zero, size: size) | |
| ctx.setFillColor(color.cgColor) | |
| ctx.fill(rect) | |
| ctx.concatenate(CGAffineTransform(a: 1, b: 0, c: 0, d: -1, tx: 0, ty: size.height)) | |
| ctx.draw(image, in: rect) | |
| return UIGraphicsGetImageFromCurrentImageContext() ?? self | |
| } | |
| func withBackground(color: UIColor, opaque: Bool = true) -> UIImage { | |
| UIGraphicsBeginImageContextWithOptions(size, opaque, scale) | |
| // Checks if there is a current graphics context, and the UIImage has a CGImage, | |
| // return the original image otherwise | |
| guard let currentGraphicsContext = UIGraphicsGetCurrentContext(), | |
| let image = cgImage else { | |
| return self | |
| } | |
| // Ensure removal of custom currentGraphicsContext on deallocation | |
| defer { UIGraphicsEndImageContext() } | |
| let rect = CGRect(origin: .zero, size: size) | |
| currentGraphicsContext.setFillColor(color.cgColor) | |
| currentGraphicsContext.fill(rect) | |
| // Flips the context vertically, then translates it vertically | |
| // By default, the coordinate system in Core Graphics is different from that of UIKit | |
| currentGraphicsContext.scaleBy(x: 1, y: -1) | |
| currentGraphicsContext.translateBy(x: 0, y: -size.height) | |
| currentGraphicsContext.draw(image, in: rect) | |
| // Return the UIImage from the current context, | |
| // of the original image if happens to fail. | |
| return UIGraphicsGetImageFromCurrentImageContext() ?? self | |
| } |
What do you think? I tested the changes to CGAfflineTransform and we get the same result , unless there's any other concern I've missed it seems that, from Apple docs, we shouldn't access this property directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the comment! I added some of the suggestions here in 0d17ba5 Some parts of the code were self-explanatory and didn't need comments, but some others were indeed abstruse
Thanks for the comments @iamgabrielma ! I will start a discussion about this 👍 |
Generated by 🚫 dangerJS |
Closes: #9748
Description
With this PR we add the Woo logo to the Scan to Pay QR code, and also refactor the code to extract the logic to its own extensions. That way it both the main logic and its helper parts can be reused in other parts of the code.
Testing instructions
Screenshots
RELEASE-NOTES.txtif necessary.