Skip to content

Commit

Permalink
Added resize handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Block committed Aug 27, 2024
1 parent 496fbf7 commit 228a258
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@omnedia/ngx-starry-sky",
"description": "A simple component library to create a container with an animated background.",
"version": "1.0.2",
"version": "1.0.3",
"peerDependencies": {
"@angular/common": "^18.2.0",
"@angular/core": "^18.2.0"
Expand Down
9 changes: 8 additions & 1 deletion src/lib/ngx-starry-sky.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Component,
ElementRef,
Input,
OnDestroy,
ViewChild,
} from "@angular/core";
import {
Expand All @@ -20,7 +21,7 @@ import {
templateUrl: "./ngx-starry-sky.component.html",
styleUrl: "./ngx-starry-sky.component.scss",
})
export class NgxStarrySkyComponent implements AfterViewInit {
export class NgxStarrySkyComponent implements AfterViewInit, OnDestroy {
@ViewChild("OmStarrySkyCanvas")
canvasRef!: ElementRef<HTMLCanvasElement>;

Expand Down Expand Up @@ -81,7 +82,13 @@ export class NgxStarrySkyComponent implements AfterViewInit {
this.initShootingStars();
}

ngOnDestroy(): void {
window.removeEventListener("resize", () => this.setCanvasSize());
}

private initStarSky(): void {
window.addEventListener("resize", () => this.setCanvasSize());

this.setCanvasSize();
this.updateStars();
this.renderStarSky();
Expand Down

0 comments on commit 228a258

Please sign in to comment.