Skip to content

Commit 41b487c

Browse files
committed
feat: apple filter to cover ios and visionos together
1 parent 02c218f commit 41b487c

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed

apps/nativescript-demo-ng/src/tests/platform-filter-components.spec.ts

+37-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// make sure you import mocha-config before @angular/core
22
import { Component, ElementRef, NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
33
import { TestBed } from '@angular/core/testing';
4-
import { AndroidFilterComponent, DEVICE, IOSFilterComponent, NativeScriptModule } from '@nativescript/angular';
4+
import { AndroidFilterComponent, DEVICE, IOSFilterComponent, AppleFilterComponent, NativeScriptModule } from '@nativescript/angular';
55
import { platformNames } from '@nativescript/core/platform';
66
import { createDevice, dumpView } from './test-utils.spec';
77
@Component({
@@ -15,6 +15,17 @@ export class IosSpecificComponent {
1515
constructor(public elementRef: ElementRef) {}
1616
}
1717

18+
@Component({
19+
template: ` <StackLayout>
20+
<apple><Label text="Apple"></Label></apple>
21+
</StackLayout>`,
22+
imports: [AppleFilterComponent],
23+
schemas: [NO_ERRORS_SCHEMA],
24+
})
25+
export class AppleSpecificComponent {
26+
constructor(public elementRef: ElementRef) {}
27+
}
28+
1829
@Component({
1930
template: ` <StackLayout>
2031
<android><Label text="ANDROID"></Label></android>
@@ -71,6 +82,31 @@ describe('Platform filter directives', () => {
7182
});
7283
});
7384

85+
describe('on Apple device', () => {
86+
beforeEach(() => {
87+
return TestBed.configureTestingModule({
88+
imports: DECLARATIONS,
89+
providers: [{ provide: DEVICE, useValue: createDevice(platformNames.ios) }],
90+
schemas: [NO_ERRORS_SCHEMA],
91+
}).compileComponents();
92+
});
93+
it('does render apple specific content', () => {
94+
const fixture = TestBed.createComponent(AppleSpecificComponent);
95+
fixture.detectChanges();
96+
const componentRef = fixture.componentRef;
97+
const componentRoot = componentRef.instance.elementRef.nativeElement;
98+
expect(dumpView(componentRoot, true).indexOf('(label[text=Apple])') >= 0).toBe(true);
99+
});
100+
it('does not render android specific content', () => {
101+
const fixture = TestBed.createComponent(AndroidSpecificComponent);
102+
fixture.detectChanges();
103+
const componentRef = fixture.componentRef;
104+
const componentRoot = componentRef.instance.elementRef.nativeElement;
105+
console.log(dumpView(componentRoot, true));
106+
expect(dumpView(componentRoot, true).indexOf('label') < 0).toBe(true);
107+
});
108+
});
109+
74110
describe('on Android device', () => {
75111
beforeEach(() => {
76112
return TestBed.configureTestingModule({
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* eslint-disable @angular-eslint/component-selector */
2+
import { Component } from '@angular/core';
3+
4+
@Component({
5+
selector: 'apple',
6+
template: `@if (show) {
7+
<ng-content></ng-content>
8+
}`,
9+
standalone: true,
10+
})
11+
export class AppleFilterComponent {
12+
public show = __APPLE__;
13+
}

packages/angular/src/lib/nativescript-common.module.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import { ModalDialogService } from './legacy/directives/dialogs';
88
import { TabViewDirective, TabViewItemDirective } from './cdk/tab-view';
99
import { AndroidFilterComponent } from './cdk/platform-filters/android-filter.component';
1010
import { IOSFilterComponent } from './cdk/platform-filters/ios-filter.component';
11+
import { AppleFilterComponent } from './cdk/platform-filters/apple-filter.component';
1112
import { VisionOSFilterComponent } from './cdk/platform-filters/vision-filter.component';
1213

13-
const CDK_COMPONENTS = [ActionBarComponent, ActionBarScope, ActionItemDirective, NavigationButtonDirective, ListViewComponent, TemplateKeyDirective, TabViewDirective, TabViewItemDirective, AndroidFilterComponent, IOSFilterComponent, VisionOSFilterComponent];
14+
const CDK_COMPONENTS = [ActionBarComponent, ActionBarScope, ActionItemDirective, NavigationButtonDirective, ListViewComponent, TemplateKeyDirective, TabViewDirective, TabViewItemDirective, AndroidFilterComponent, IOSFilterComponent, AppleFilterComponent, VisionOSFilterComponent];
1415

1516
registerNativeScriptViewComponents();
1617

packages/angular/src/lib/public_api.ts

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export * from './cdk/portal';
3232
export * from './cdk/dialog';
3333
export * from './cdk/tab-view';
3434
export * from './cdk/platform-filters/android-filter.component';
35+
export * from './cdk/platform-filters/apple-filter.component';
3536
export * from './cdk/platform-filters/ios-filter.component';
3637
export * from './cdk/platform-filters/vision-filter.component';
3738
export * from './file-system';

0 commit comments

Comments
 (0)