Skip to content

Commit

Permalink
Changed stuff for performance optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
xSentry committed Aug 27, 2024
1 parent 515d41e commit 12737ff
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
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-globe",
"description": "A simple component library to create a container with an animated and interactive globe.",
"version": "1.0.1",
"version": "1.0.2",
"peerDependencies": {
"@angular/common": "^18.2.0",
"@angular/core": "^18.2.0",
Expand Down
20 changes: 20 additions & 0 deletions src/lib/ngx-globe.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,16 @@ export class NgxGlobeComponent implements AfterViewInit, OnDestroy {
pointerInteractionMovement = 0;
private globeRotation = 0;

private intersectionObserver?: IntersectionObserver;
private isAnimating = false;

ngAfterViewInit(): void {
this.initGlobe();

this.intersectionObserver = new IntersectionObserver(([entry]) => {
this.renderContents(entry.isIntersecting)
})
this.intersectionObserver.observe(this.globeCanvas.nativeElement);
}

ngOnDestroy(): void {
Expand All @@ -105,6 +113,18 @@ export class NgxGlobeComponent implements AfterViewInit, OnDestroy {
this.globeCanvas.nativeElement.height = this.globeSize;
}

renderContents(isIntersecting: boolean) {
if (isIntersecting && !this.isAnimating) {
this.isAnimating = true;

this.globe?.toggle(true);
} else if (!isIntersecting && this.isAnimating) {
this.isAnimating = false;

this.globe?.toggle(false);
}
}

initGlobe(): void {
let phi = this.cobeOptions.phi;
let cobeOptions = {
Expand Down

0 comments on commit 12737ff

Please sign in to comment.