MOBILE-3947 core: Stop using ComponentFactoryResolver

main
Pau Ferrer Ocaña 2023-11-15 17:02:43 +01:00 committed by Dani Palou
parent 33b0afd242
commit 22dbd6ad99
4 changed files with 8 additions and 18 deletions

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { Injectable, ViewContainerRef, ComponentFactoryResolver } from '@angular/core'; import { Injectable, ViewContainerRef } from '@angular/core';
import { CoreFilterDefaultHandler } from '@features/filter/services/handlers/default-filter'; import { CoreFilterDefaultHandler } from '@features/filter/services/handlers/default-filter';
import { CoreFilterFilter, CoreFilterFormatTextOptions } from '@features/filter/services/filter'; import { CoreFilterFilter, CoreFilterFormatTextOptions } from '@features/filter/services/filter';
@ -32,10 +32,6 @@ export class AddonFilterDisplayH5PHandlerService extends CoreFilterDefaultHandle
protected template = document.createElement('template'); // A template element to convert HTML to element. protected template = document.createElement('template'); // A template element to convert HTML to element.
constructor(protected factoryResolver: ComponentFactoryResolver) {
super();
}
/** /**
* @inheritdoc * @inheritdoc
*/ */
@ -95,8 +91,7 @@ export class AddonFilterDisplayH5PHandlerService extends CoreFilterDefaultHandle
const url = placeholder.getAttribute('data-player-src') || ''; const url = placeholder.getAttribute('data-player-src') || '';
// Create the component to display the player. // Create the component to display the player.
const factory = this.factoryResolver.resolveComponentFactory(CoreH5PPlayerComponent); const componentRef = viewContainerRef.createComponent<CoreH5PPlayerComponent>(CoreH5PPlayerComponent);
const componentRef = viewContainerRef.createComponent<CoreH5PPlayerComponent>(factory);
componentRef.instance.src = url; componentRef.instance.src = url;
componentRef.instance.component = component; componentRef.instance.component = component;

View File

@ -20,7 +20,6 @@ import {
OnChanges, OnChanges,
DoCheck, DoCheck,
ViewContainerRef, ViewContainerRef,
ComponentFactoryResolver,
ComponentRef, ComponentRef,
KeyValueDiffers, KeyValueDiffers,
SimpleChange, SimpleChange,
@ -85,7 +84,6 @@ export class CoreDynamicComponent<ComponentClass> implements OnChanges, DoCheck
protected lastComponent?: Type<unknown>; protected lastComponent?: Type<unknown>;
constructor( constructor(
protected factoryResolver: ComponentFactoryResolver,
differs: KeyValueDiffers, differs: KeyValueDiffers,
protected cdr: ChangeDetectorRef, protected cdr: ChangeDetectorRef,
protected element: ElementRef, protected element: ElementRef,
@ -172,8 +170,7 @@ export class CoreDynamicComponent<ComponentClass> implements OnChanges, DoCheck
} else { } else {
try { try {
// Create the component and add it to the container. // Create the component and add it to the container.
const factory = this.factoryResolver.resolveComponentFactory(this.component); const componentRef = this.container.createComponent(this.component);
const componentRef = this.container.createComponent(factory);
this.instance = componentRef.instance; this.instance = componentRef.instance;
} catch (ex) { } catch (ex) {

View File

@ -20,7 +20,6 @@ import {
ElementRef, ElementRef,
ViewContainerRef, ViewContainerRef,
ViewChild, ViewChild,
ComponentFactoryResolver,
} from '@angular/core'; } from '@angular/core';
import { CoreLogger } from '@singletons/logger'; import { CoreLogger } from '@singletons/logger';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
@ -78,7 +77,7 @@ export class CoreNavBarButtonsComponent implements OnInit, OnDestroy {
protected mergedContextMenu?: CoreContextMenuComponent; protected mergedContextMenu?: CoreContextMenuComponent;
protected createdMainContextMenuElement?: HTMLElement; protected createdMainContextMenuElement?: HTMLElement;
constructor(element: ElementRef, protected factoryResolver: ComponentFactoryResolver) { constructor(element: ElementRef) {
this.element = element.nativeElement; this.element = element.nativeElement;
this.logger = CoreLogger.getInstance('CoreNavBarButtonsComponent'); this.logger = CoreLogger.getInstance('CoreNavBarButtonsComponent');
@ -186,8 +185,7 @@ export class CoreNavBarButtonsComponent implements OnInit, OnDestroy {
* @returns Created component. * @returns Created component.
*/ */
protected createMainContextMenu(): CoreContextMenuComponent { protected createMainContextMenu(): CoreContextMenuComponent {
const factory = this.factoryResolver.resolveComponentFactory(CoreContextMenuComponent); const componentRef = this.container.createComponent(CoreContextMenuComponent);
const componentRef = this.container.createComponent<CoreContextMenuComponent>(factory);
this.createdMainContextMenuElement = componentRef.location.nativeElement; this.createdMainContextMenuElement = componentRef.location.nativeElement;

View File

@ -16,10 +16,10 @@ import {
AbstractType, AbstractType,
ApplicationInitStatus, ApplicationInitStatus,
ApplicationRef, ApplicationRef,
ComponentFactoryResolver as ComponentFactoryResolverService,
Injector, Injector,
NgZone as NgZoneService, NgZone as NgZoneService,
Type, Type,
EnvironmentInjector,
} from '@angular/core'; } from '@angular/core';
import { Router as RouterService } from '@angular/router'; import { Router as RouterService } from '@angular/router';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
@ -206,7 +206,6 @@ export const Http = makeSingleton(HttpClient);
export const ActionSheetController = makeSingleton(ActionSheetControllerService); export const ActionSheetController = makeSingleton(ActionSheetControllerService);
export const AngularDelegate = makeSingleton(AngularDelegateService); export const AngularDelegate = makeSingleton(AngularDelegateService);
export const AlertController = makeSingleton(AlertControllerService); export const AlertController = makeSingleton(AlertControllerService);
export const ComponentFactoryResolver = makeSingleton(ComponentFactoryResolverService);
export const LoadingController = makeSingleton(LoadingControllerService); export const LoadingController = makeSingleton(LoadingControllerService);
export const ModalController = makeSingleton(ModalControllerService); export const ModalController = makeSingleton(ModalControllerService);
export const PopoverController = makeSingleton(PopoverControllerService); export const PopoverController = makeSingleton(PopoverControllerService);
@ -227,6 +226,7 @@ export const Translate: Omit<CoreSingletonProxy<TranslateService>, 'instant'> &
// Async singletons. // Async singletons.
export const AngularFrameworkDelegate = asyncInstance(async () => { export const AngularFrameworkDelegate = asyncInstance(async () => {
const injector = await singletonsInjector; const injector = await singletonsInjector;
const environmentInjector = await injector.get(EnvironmentInjector);
return AngularDelegate.create(ComponentFactoryResolver.instance, injector); return AngularDelegate.create(environmentInjector, injector);
}); });