Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ describe('FixedCardLayoutComponent', () => {
}
} as any;

component.fixedCardLayout.updateLayout();
component.fixedCardLayout._onDragDropped(event);
fixture.detectChanges();

Expand Down
37 changes: 22 additions & 15 deletions libs/core/src/lib/fixed-card-layout/fixed-card-layout.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
import { FocusKeyManager } from '@angular/cdk/a11y';
import { CdkDrag, CdkDragDrop, CdkDragEnter, CdkDragStart } from '@angular/cdk/drag-drop';
import { Subject, Subscription } from 'rxjs';
import { debounceTime, distinct, filter, takeUntil } from 'rxjs/operators';
import { debounceTime, filter, skip, takeUntil } from 'rxjs/operators';

import { resizeObservable, RtlService, getDocumentFontSize } from '@fundamental-ngx/core/utils';
import { Nullable } from '@fundamental-ngx/core/shared';
Expand Down Expand Up @@ -146,7 +146,7 @@ export class FixedCardLayoutComponent implements OnInit, AfterViewInit, OnChange

/** @hidden */
@ViewChild('layout')
_layout: ElementRef;
_layout: ElementRef<HTMLElement>;

/** @hidden */
_cardsArray: CardDefinitionDirective[];
Expand All @@ -158,7 +158,7 @@ export class FixedCardLayoutComponent implements OnInit, AfterViewInit, OnChange
_cardColumns: CardColumn[];

/** @hidden*/
_containerHeight: number;
_containerHeight = 0;

/** @hidden handles rtl service */
_dir = 'ltr';
Expand All @@ -184,7 +184,7 @@ export class FixedCardLayoutComponent implements OnInit, AfterViewInit, OnChange
_placeholderMargin: boolean;

/** @hidden */
_listenResize = false;
_listenResize = true;

/** @hidden */
_hiddenCard: Nullable<CardDefinitionDirective>;
Expand Down Expand Up @@ -408,25 +408,28 @@ export class FixedCardLayoutComponent implements OnInit, AfterViewInit, OnChange
private _listenOnResize(): void {
resizeObservable(this._layout.nativeElement)
.pipe(
filter(() => this._listenResize),
debounceTime(50),
debounceTime(20),
filter(
(entries) => this._listenResize && !!(entries[0].contentRect.height || entries[0].contentRect.width)
),
takeUntil(this._onDestroy$)
)
.subscribe(() => this.updateLayout());
}

/** @hidden Listen card change and distribute cards on column change */
private _listenOnCardsChange(): void {
this._cards.changes.subscribe(() => this._processCards());
this._cards.changes.subscribe(() => {
this._processCards();
this.updateLayout();
});
}

/** @hidden */
private _processCards(): void {
this._cardsArray = this._cards
.toArray()
.sort((firstCard, secondCard) => firstCard.fdCardDef - secondCard.fdCardDef);

this.updateLayout();
}

/** @hidden Distribute cards among columns to arrange them in "Z" flow */
Expand Down Expand Up @@ -455,7 +458,7 @@ export class FixedCardLayoutComponent implements OnInit, AfterViewInit, OnChange
}
});

this._listenOnCardsSizeChange();
this._listenOnCardsHeightChange();
}

/** @hidden */
Expand Down Expand Up @@ -507,14 +510,18 @@ export class FixedCardLayoutComponent implements OnInit, AfterViewInit, OnChange
(columnIndex === columnIndexToAddSpace ? spaceToAdd : 0)
);

const prevContainerHeight = this._containerHeight;

// +4px because it's the top & bottom borders of card placeholder
this._containerHeight = Math.ceil(Math.max(...columnsHeights) + 4);

this._changeDetector.detectChanges();
if (this._containerHeight !== prevContainerHeight) {
this._changeDetector.detectChanges();
}
}

/** @hidden */
private _listenOnCardsSizeChange(): void {
private _listenOnCardsHeightChange(): void {
this._cardsSizeChangeSubscription.unsubscribe();
this._cardsSizeChangeSubscription = new Subscription();

Expand All @@ -528,9 +535,9 @@ export class FixedCardLayoutComponent implements OnInit, AfterViewInit, OnChange
this._cardsSizeChangeSubscription.add(
resizeObservable(card.nativeElement)
.pipe(
filter(() => this._listenResize),
distinct((resizeEntry) => resizeEntry[0].contentRect.height),
debounceTime(50)
skip(1),
debounceTime(20),
filter(() => this._listenResize && !!this._layout.nativeElement.clientHeight)
)
.subscribe(() => this._setContainerHeight())
);
Expand Down