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

fix: re-draw already loaded center images on change #71

Merged
merged 2 commits into from
Dec 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 8.0.1 - 2022-12-03
- Fix center image disappearing when other values are updated (#71)

# 8.0.0 - 2022-12-03
- Support Angular 15 (#70)

Expand Down
2 changes: 1 addition & 1 deletion projects/ng-qrcode/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ng-qrcode",
"description": "Simple AOT compatible QR code generator for your Angular project.",
"version": "8.0.0",
"version": "8.0.1",
"license": "MIT",
"author": {
"name": "Michael Nahkies",
Expand Down
21 changes: 14 additions & 7 deletions projects/ng-qrcode/src/lib/qr-code.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,27 +109,34 @@ export class QrCodeDirective implements OnChanges {
this.centerImage = new Image(centerImageWidth, centerImageHeight)
}

if (centerImageSrc !== this.centerImage?.src) {
this.centerImage.src = centerImageSrc
const centerImage = this.centerImage

if (centerImageSrc !== this.centerImage.src) {
centerImage.src = centerImageSrc
}

if (centerImageWidth !== this.centerImage.width) {
this.centerImage.width = centerImageWidth
centerImage.width = centerImageWidth
}

if (centerImageHeight !== this.centerImage.height) {
this.centerImage.height = centerImageHeight
centerImage.height = centerImageHeight
}

const centerImage = this.centerImage

centerImage.onload = () => {
const doDrawImage = () => {
context.drawImage(
centerImage,
canvas.width / 2 - centerImageWidth / 2,
canvas.height / 2 - centerImageHeight / 2, centerImageWidth, centerImageHeight,
)
}

centerImage.onload = doDrawImage

if (centerImage.complete) {
doDrawImage()
}

}

}
Expand Down