Skip to content
Open
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
20 changes: 20 additions & 0 deletions apps/nativescript-demo-ng/src/tests/image-config.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { IMAGE_CONFIG } from '@angular/common';
import { TestBed } from '@angular/core/testing';
import { NativeScriptModule } from '@nativescript/angular';

describe('IMAGE_CONFIG', () => {
beforeEach(() => {
return TestBed.configureTestingModule({
imports: [NativeScriptModule],
}).compileComponents();
});

// Both flags are required: with either one unset, Angular reaches for `document` during
// bootstrap on any runtime that exposes a global PerformanceObserver.
it('disables both dev-mode image warnings', () => {
const config = TestBed.inject(IMAGE_CONFIG);

expect(config.disableImageSizeWarning).toBe(true);
expect(config.disableImageLazyLoadWarning).toBe(true);
});
});
10 changes: 8 additions & 2 deletions packages/angular/src/lib/nativescript.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ViewportScroller, XhrFactory, ɵNullViewportScroller as NullViewportScroller } from '@angular/common';
import { IMAGE_CONFIG, ViewportScroller, XhrFactory, ɵNullViewportScroller as NullViewportScroller } from '@angular/common';
import { ApplicationModule, ErrorHandler, Inject, NgModule, NO_ERRORS_SCHEMA, Optional, Provider, RendererFactory2, SkipSelf, StaticProvider, ɵINJECTOR_SCOPE as INJECTOR_SCOPE } from '@angular/core';
import { Color, Device, View } from '@nativescript/core';
import { AppHostView } from './app-host-view';
Expand Down Expand Up @@ -40,7 +40,13 @@ export const NATIVESCRIPT_MODULE_STATIC_PROVIDERS: StaticProvider[] = [
{ provide: DEVICE, useValue: Device },
{ provide: XhrFactory, useClass: NativescriptXhrFactory, deps: [] },
];
export const NATIVESCRIPT_MODULE_PROVIDERS: Provider[] = [{ provide: ViewportScroller, useClass: NullViewportScroller }];
export const NATIVESCRIPT_MODULE_PROVIDERS: Provider[] = [
{ provide: ViewportScroller, useClass: NullViewportScroller },
// Angular's dev-mode image warnings scan the DOM for <img> elements, which
// NativeScript has none of. Angular only skips them when both flags are set,
// and reaches for `document` as soon as a global PerformanceObserver exists.
{ provide: IMAGE_CONFIG, useValue: { disableImageSizeWarning: true, disableImageLazyLoadWarning: true } },
];

@NgModule({
imports: [ApplicationModule, DetachedLoader, NativeScriptCommonModule],
Expand Down
Loading