Skip to content

Commit

Permalink
fix: 🐛 use animation frame
Browse files Browse the repository at this point in the history
  • Loading branch information
NetanelBasal committed Nov 11, 2020
1 parent 71d8c84 commit d1cb240
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
11 changes: 10 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions projects/ngneat/helipopper/src/lib/helipopper.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
Type
} from '@angular/core';
import tippy, { Instance, Props } from 'tippy.js';
import { forkJoin, fromEvent, Subject } from 'rxjs';
import { fromEvent, Subject } from 'rxjs';
import { Options as PopperOptions } from '@popperjs/core';
import {
addClass,
Expand All @@ -24,8 +24,7 @@ import {
dimensionsChanges,
inView,
isString,
TemplatePortal,
zoneStable
TemplatePortal
} from './utils';
import { takeUntil } from 'rxjs/operators';
import { HELIPOPPER_CONFIG, HelipopperConfig, InstanceWithClose, Variation } from './helipopper.types';
Expand Down Expand Up @@ -111,9 +110,11 @@ export class HelipopperDirective implements OnDestroy {
if (this.instance) {
this.checkOverflow();
} else {
forkJoin([inView(this.host.nativeElement), zoneStable(this.zone)])
.pipe(takeUntil(this._destroy))
.subscribe(() => this.create());
requestAnimationFrame(() => {
inView(this.host.nativeElement)
.pipe(takeUntil(this._destroy))
.subscribe(() => this.create());
});
}
}

Expand Down Expand Up @@ -308,7 +309,7 @@ export class HelipopperDirective implements OnDestroy {

private checkOverflow() {
if (this.showOnlyOnTextOverflow) {
zoneStable(this.zone).subscribe(() => this.markDisabled(this.isElementOverflow() === false));
requestAnimationFrame(() => this.markDisabled(this.isElementOverflow() === false));
}
}

Expand Down
6 changes: 1 addition & 5 deletions projects/ngneat/helipopper/src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fromEvent, Observable } from 'rxjs';
import { auditTime, distinctUntilChanged, map, take } from 'rxjs/operators';
import { ElementRef, EmbeddedViewRef, NgZone, TemplateRef } from '@angular/core';
import { ElementRef, EmbeddedViewRef, TemplateRef } from '@angular/core';

const hasSupport = 'IntersectionObserver' in window;

Expand Down Expand Up @@ -120,10 +120,6 @@ export function coerceElement<T>(elementOrRef: ElementRef<T> | T): T {
return elementOrRef instanceof ElementRef ? elementOrRef.nativeElement : elementOrRef;
}

export function zoneStable(zone: NgZone) {
return zone.onStable.pipe(take(1));
}

export function isString(value: any): value is string {
return typeof value === 'string';
}
Expand Down

0 comments on commit d1cb240

Please sign in to comment.