Skip to content

fix: readd platform filters #11

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 2 commits into from
Jun 30, 2021
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
3 changes: 2 additions & 1 deletion apps/nativescript-demo-ng/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"devDependencies": {
"@nativescript/android": "8.0.0",
"@nativescript/ios": "8.0.0"
"@nativescript/ios": "8.0.0",
"@nativescript/unit-test-runner": "^2.0.5"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class PlatformSpecificAttributeComponent {
const DECLARATIONS = [PlatformSpecificAttributeComponent, AndroidSpecificComponent, IosSpecificComponent];
@NgModule({
declarations: DECLARATIONS,
imports: [NativeScriptModule],
schemas: [NO_ERRORS_SCHEMA],
})
export class PlatformModule {}
Expand All @@ -61,7 +62,8 @@ describe('Platform filter directives', () => {
fixture.detectChanges();
const componentRef = fixture.componentRef;
const componentRoot = componentRef.instance.elementRef.nativeElement;
expect(dumpView(componentRoot, true).indexOf('Label') < 0).toBe(true);
console.log(dumpView(componentRoot, true));
expect(dumpView(componentRoot, true).indexOf('label') < 0).toBe(true);
});
it('applies iOS specific attribute', () => {
const fixture = TestBed.createComponent(PlatformSpecificAttributeComponent);
Expand Down Expand Up @@ -94,7 +96,7 @@ describe('Platform filter directives', () => {
fixture.detectChanges();
const componentRef = fixture.componentRef;
const componentRoot = componentRef.instance.elementRef.nativeElement;
expect(dumpView(componentRoot, true).indexOf('Label') < 0).toBe(true);
expect(dumpView(componentRoot, true).indexOf('label') < 0).toBe(true);
});
it('applies Android specific attribute', () => {
const fixture = TestBed.createComponent(PlatformSpecificAttributeComponent);
Expand Down
4 changes: 3 additions & 1 deletion apps/nativescript-demo-ng/tools/xplat-postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ try {
}

// Helpful to trigger ngcc after an install to ensure all has processed properly
const child = childProcess.spawn(/^win/.test(process.platform) ? '..\\..\\node_modules\\.bin\\ngcc' : '../../node_modules/.bin/ngcc', ['--tsconfig', 'tsconfig.app.json', '--properties', 'es2015', 'module', 'main', '--first-only'], {
const ngccPath = path.join('..', '..', 'node_modules', '.bin', 'ngcc');
const child = childProcess.spawn(ngccPath, ['--tsconfig', 'tsconfig.app.json', '--properties', 'es2015', 'module', 'main', '--first-only'], {
cwd: process.cwd(),
stdio: 'inherit',
shell: process.platform == 'win32'
});
child.on('close', (code) => {

Expand Down
28 changes: 28 additions & 0 deletions packages/angular/src/lib/cdk/platform-filters/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* eslint-disable @angular-eslint/component-selector */
import { Component, Inject } from '@angular/core';
import { Device, platformNames } from '@nativescript/core';
import { DEVICE } from '../../tokens';

@Component({
selector: 'android',
template: `<ng-content *ngIf="show"></ng-content>`,
})
export class AndroidFilterComponent {
public show: boolean;

constructor(@Inject(DEVICE) device: typeof Device) {
this.show = device.os === platformNames.android;
}
}

@Component({
selector: 'ios',
template: `<ng-content *ngIf="show"></ng-content>`,
})
export class IosFilterComponent {
public show: boolean;
constructor(@Inject(DEVICE) device: typeof Device) {
console.log(device.os, platformNames.ios);
this.show = device.os === platformNames.ios;
}
}
3 changes: 2 additions & 1 deletion packages/angular/src/lib/nativescript-common.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import { ListViewComponent, TemplateKeyDirective } from './cdk/list-view/list-vi
import { registerNativeScriptViewComponents } from './element-registry';
import { ModalDialogService } from './legacy/directives/dialogs';
import { TabViewDirective, TabViewItemDirective } from './cdk/tab-view';
import { AndroidFilterComponent, IosFilterComponent } from './cdk/platform-filters';

const CDK_COMPONENTS = [ActionBarComponent, ActionBarScope, ActionItemDirective, NavigationButtonDirective, ListViewComponent, TemplateKeyDirective, TabViewDirective, TabViewItemDirective];
const CDK_COMPONENTS = [ActionBarComponent, ActionBarScope, ActionItemDirective, NavigationButtonDirective, ListViewComponent, TemplateKeyDirective, TabViewDirective, TabViewItemDirective, AndroidFilterComponent, IosFilterComponent];

registerNativeScriptViewComponents();

Expand Down
1 change: 1 addition & 0 deletions packages/angular/src/lib/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export * from './cdk/list-view';
export * from './cdk/portal';
export * from './cdk/dialog';
export * from './cdk/tab-view';
export * from './cdk/platform-filters';
export * from './file-system';
export * from './nativescript-common.module';
export * from './loading.service';
Expand Down