Skip to content

fix: use inject in ListViewComponent #102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 14, 2022
Merged
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
29 changes: 25 additions & 4 deletions packages/angular/src/lib/cdk/list-view/list-view.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AfterContentInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, ContentChild, Directive, DoCheck, ElementRef, EmbeddedViewRef, EventEmitter, forwardRef, Host, HostListener, Inject, InjectionToken, Input, IterableDiffer, IterableDiffers, OnDestroy, Output, TemplateRef, ViewChild, ViewContainerRef, ɵisListLikeIterable as isListLikeIterable } from '@angular/core';
import { AfterContentInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, ContentChild, Directive, DoCheck, ElementRef, EmbeddedViewRef, EventEmitter, forwardRef, Host, HostListener, inject, Inject, InjectionToken, Input, IterableDiffer, IterableDiffers, NgZone, OnDestroy, Output, TemplateRef, ViewChild, ViewContainerRef, ɵisListLikeIterable as isListLikeIterable } from '@angular/core';
import { ItemEventData, KeyedTemplate, LayoutBase, ListView, ObservableArray, profile, View } from '@nativescript/core';

import { extractSingleViewRecursive } from '../../element-registry/registry';
Expand Down Expand Up @@ -96,7 +96,12 @@ export class ListViewComponent<T = any> implements DoCheck, OnDestroy, AfterCont
return this.templatedItemsView;
}

protected templatedItemsView: ListView;
private readonly _iterableDiffers: IterableDiffers = inject(IterableDiffers);
private readonly _changeDetectorRef: ChangeDetectorRef = inject(ChangeDetectorRef);
private readonly _elementRef: ElementRef = inject(ElementRef);

// I believe this only exists so this can be inherited and people can override it.
protected templatedItemsView: ListView = this._elementRef.nativeElement;
protected _items: T[] | ObservableArray<T>;
protected _differ: IterableDiffer<T>;
protected _templateMap: Map<string, NsTemplatedItem<T>>;
Expand Down Expand Up @@ -130,8 +135,24 @@ export class ListViewComponent<T = any> implements DoCheck, OnDestroy, AfterCont
this.templatedItemsView.items = this._items;
}

constructor(_elementRef: ElementRef, private readonly _iterableDiffers: IterableDiffers, private readonly _changeDetectorRef: ChangeDetectorRef) {
this.templatedItemsView = _elementRef.nativeElement;
/**
* @deprecated
*/
constructor(_elementRef: ElementRef);
/**
* @deprecated
*/
constructor(_elementRef: ElementRef, _iterableDiffers: IterableDiffers, _changeDetectorRef: ChangeDetectorRef);
/**
* @deprecated
*/
constructor(_elementRef: ElementRef, _iterableDiffers: IterableDiffers, _ngZone: NgZone);
constructor();
// this elementRef is only here for backwards compatibility reasons
constructor(_elementRef?: ElementRef) {
if (_elementRef) {
this.templatedItemsView = _elementRef.nativeElement;
}
}

ngAfterContentInit() {
Expand Down