Compare commits
1 Commits
master
...
feature/su
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3efffb3a70 |
@ -46,6 +46,6 @@
|
||||
"protractor": "~5.1.2",
|
||||
"ts-node": "~3.2.0",
|
||||
"tslint": "~5.7.0",
|
||||
"typescript": "^3.1.1"
|
||||
"typescript": "3.6.4"
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ export type ContainerRef = Window | ElementRef | any;
|
||||
|
||||
export interface IInfiniteScrollEvent {
|
||||
currentScrollPosition: number;
|
||||
stats: IPositionStats;
|
||||
}
|
||||
|
||||
export interface IPositionElements {
|
||||
|
||||
@ -8,16 +8,19 @@ import {
|
||||
OnChanges,
|
||||
OnDestroy,
|
||||
Output,
|
||||
SimpleChanges
|
||||
SimpleChanges,
|
||||
} from '@angular/core';
|
||||
import {Subscription} from 'rxjs';
|
||||
import { Subscription } from 'rxjs';
|
||||
|
||||
import { IInfiniteScrollEvent, IInfiniteScrollAction } from '../models';
|
||||
import { hasWindowDefined, inputPropChanged } from '../services/ngx-ins-utils';
|
||||
import { createScroller, InfiniteScrollActions } from '../services/scroll-register';
|
||||
import {
|
||||
createScroller,
|
||||
InfiniteScrollActions,
|
||||
} from '../services/scroll-register';
|
||||
|
||||
@Directive({
|
||||
selector: '[infiniteScroll], [infinite-scroll], [data-infinite-scroll]'
|
||||
selector: '[infiniteScroll], [infinite-scroll], [data-infinite-scroll]',
|
||||
})
|
||||
export class InfiniteScrollDirective
|
||||
implements OnDestroy, OnChanges, AfterViewInit {
|
||||
@ -34,23 +37,33 @@ export class InfiniteScrollDirective
|
||||
@Input() horizontal: boolean = false;
|
||||
@Input() alwaysCallback: boolean = false;
|
||||
@Input() fromRoot: boolean = false;
|
||||
@Input() scrollPosition: number = 0;
|
||||
|
||||
private disposeScroller: Subscription;
|
||||
|
||||
constructor(private element: ElementRef, private zone: NgZone) { }
|
||||
constructor(private element: ElementRef, private zone: NgZone) {}
|
||||
|
||||
ngAfterViewInit() {
|
||||
if (!this.infiniteScrollDisabled) {
|
||||
this.setup();
|
||||
}
|
||||
if (this.scrollPosition > 0) {
|
||||
this.element.nativeElement.scrollTo(500);
|
||||
}
|
||||
}
|
||||
|
||||
ngOnChanges({ infiniteScrollContainer, infiniteScrollDisabled, infiniteScrollDistance }: SimpleChanges) {
|
||||
ngOnChanges({
|
||||
infiniteScrollContainer,
|
||||
infiniteScrollDisabled,
|
||||
infiniteScrollDistance,
|
||||
}: SimpleChanges) {
|
||||
const containerChanged = inputPropChanged(infiniteScrollContainer);
|
||||
const disabledChanged = inputPropChanged(infiniteScrollDisabled);
|
||||
const distanceChanged = inputPropChanged(infiniteScrollDistance);
|
||||
const shouldSetup = (!disabledChanged && !this.infiniteScrollDisabled) ||
|
||||
(disabledChanged && !infiniteScrollDisabled.currentValue) || distanceChanged;
|
||||
const shouldSetup =
|
||||
(!disabledChanged && !this.infiniteScrollDisabled) ||
|
||||
(disabledChanged && !infiniteScrollDisabled.currentValue) ||
|
||||
distanceChanged;
|
||||
|
||||
if (containerChanged || disabledChanged || distanceChanged) {
|
||||
this.destroyScroller();
|
||||
@ -73,8 +86,10 @@ export class InfiniteScrollDirective
|
||||
scrollContainer: this.infiniteScrollContainer,
|
||||
scrollWindow: this.scrollWindow,
|
||||
throttle: this.infiniteScrollThrottle,
|
||||
upDistance: this.infiniteScrollUpDistance
|
||||
}).subscribe((payload: any) => this.zone.run(() => this.handleOnScroll(payload)));
|
||||
upDistance: this.infiniteScrollUpDistance,
|
||||
}).subscribe((payload: any) =>
|
||||
this.zone.run(() => this.handleOnScroll(payload))
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,18 +18,18 @@ export function createScroller(config: Models.IScroller) {
|
||||
scrollWindow,
|
||||
element,
|
||||
fromRoot
|
||||
)
|
||||
),
|
||||
});
|
||||
const scrollState = new ScrollState({
|
||||
totalToScroll: calculatePoints(element, resolver)
|
||||
totalToScroll: calculatePoints(element, resolver),
|
||||
});
|
||||
const options: Models.IScrollRegisterConfig = {
|
||||
container: resolver.container,
|
||||
throttle: config.throttle
|
||||
throttle: config.throttle,
|
||||
};
|
||||
const distance = {
|
||||
up: config.upDistance,
|
||||
down: config.downDistance
|
||||
down: config.downDistance,
|
||||
};
|
||||
return attachScrollEvent(options).pipe(
|
||||
mergeMap(() => of(calculatePoints(element, resolver))),
|
||||
@ -84,13 +84,13 @@ export function toInfiniteScrollParams(
|
||||
return {
|
||||
scrollDown,
|
||||
fire,
|
||||
stats
|
||||
stats,
|
||||
};
|
||||
}
|
||||
|
||||
export const InfiniteScrollActions = {
|
||||
DOWN: '[NGX_ISE] DOWN',
|
||||
UP: '[NGX_ISE] UP'
|
||||
UP: '[NGX_ISE] UP',
|
||||
};
|
||||
|
||||
export function toInfiniteScrollAction(
|
||||
@ -98,12 +98,13 @@ export function toInfiniteScrollAction(
|
||||
): Models.IInfiniteScrollAction {
|
||||
const {
|
||||
scrollDown,
|
||||
stats: { scrolled: currentScrollPosition }
|
||||
stats: { scrolled: currentScrollPosition },
|
||||
} = response;
|
||||
return {
|
||||
type: scrollDown ? InfiniteScrollActions.DOWN : InfiniteScrollActions.UP,
|
||||
payload: {
|
||||
currentScrollPosition
|
||||
}
|
||||
currentScrollPosition,
|
||||
stats: response.stats,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user