@symbiote-native/angular 0.0.0-canary-20260724081123
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +157 -0
- package/babel-linker.cjs +7 -0
- package/babel-register-composed.cjs +127 -0
- package/bin/symbiote-angular-dev.cjs +93 -0
- package/build/angular/anchor-host-registry.d.ts +2 -0
- package/build/angular/anchor-host-registry.js +84 -0
- package/build/angular/anchor-host-registry.js.map +1 -0
- package/build/angular/bootstrap.d.ts +7 -0
- package/build/angular/bootstrap.js +15 -0
- package/build/angular/bootstrap.js.map +1 -0
- package/build/angular/components/activity-indicator/index.android.d.ts +12 -0
- package/build/angular/components/activity-indicator/index.android.js +21 -0
- package/build/angular/components/activity-indicator/index.android.js.map +1 -0
- package/build/angular/components/activity-indicator/index.d.ts +1 -0
- package/build/angular/components/activity-indicator/index.ios.d.ts +8 -0
- package/build/angular/components/activity-indicator/index.ios.js +21 -0
- package/build/angular/components/activity-indicator/index.ios.js.map +1 -0
- package/build/angular/components/activity-indicator/index.js +4 -0
- package/build/angular/components/activity-indicator/index.js.map +1 -0
- package/build/angular/components/activity-indicator/shared.d.ts +67 -0
- package/build/angular/components/activity-indicator/shared.js +260 -0
- package/build/angular/components/activity-indicator/shared.js.map +1 -0
- package/build/angular/components/button.d.ts +63 -0
- package/build/angular/components/button.js +332 -0
- package/build/angular/components/button.js.map +1 -0
- package/build/angular/components/flat-list/index.d.ts +122 -0
- package/build/angular/components/flat-list/index.js +688 -0
- package/build/angular/components/flat-list/index.js.map +1 -0
- package/build/angular/components/image/index.android.d.ts +10 -0
- package/build/angular/components/image/index.android.js +59 -0
- package/build/angular/components/image/index.android.js.map +1 -0
- package/build/angular/components/image/index.d.ts +1 -0
- package/build/angular/components/image/index.ios.d.ts +10 -0
- package/build/angular/components/image/index.ios.js +59 -0
- package/build/angular/components/image/index.ios.js.map +1 -0
- package/build/angular/components/image/index.js +3 -0
- package/build/angular/components/image/index.js.map +1 -0
- package/build/angular/components/image/shared.d.ts +101 -0
- package/build/angular/components/image/shared.js +406 -0
- package/build/angular/components/image/shared.js.map +1 -0
- package/build/angular/components/image-background.d.ts +81 -0
- package/build/angular/components/image-background.js +418 -0
- package/build/angular/components/image-background.js.map +1 -0
- package/build/angular/components/input-accessory-view/index.d.ts +60 -0
- package/build/angular/components/input-accessory-view/index.js +251 -0
- package/build/angular/components/input-accessory-view/index.js.map +1 -0
- package/build/angular/components/keyboard-avoiding-view/index.d.ts +82 -0
- package/build/angular/components/keyboard-avoiding-view/index.js +358 -0
- package/build/angular/components/keyboard-avoiding-view/index.js.map +1 -0
- package/build/angular/components/modal/index.d.ts +92 -0
- package/build/angular/components/modal/index.js +360 -0
- package/build/angular/components/modal/index.js.map +1 -0
- package/build/angular/components/pressable/index.d.ts +123 -0
- package/build/angular/components/pressable/index.js +420 -0
- package/build/angular/components/pressable/index.js.map +1 -0
- package/build/angular/components/refresh-control/index.d.ts +86 -0
- package/build/angular/components/refresh-control/index.js +342 -0
- package/build/angular/components/refresh-control/index.js.map +1 -0
- package/build/angular/components/safe-area-view/index.d.ts +57 -0
- package/build/angular/components/safe-area-view/index.js +248 -0
- package/build/angular/components/safe-area-view/index.js.map +1 -0
- package/build/angular/components/scroll-view/index.android.d.ts +21 -0
- package/build/angular/components/scroll-view/index.android.js +235 -0
- package/build/angular/components/scroll-view/index.android.js.map +1 -0
- package/build/angular/components/scroll-view/index.d.ts +3 -0
- package/build/angular/components/scroll-view/index.ios.d.ts +9 -0
- package/build/angular/components/scroll-view/index.ios.js +86 -0
- package/build/angular/components/scroll-view/index.ios.js.map +1 -0
- package/build/angular/components/scroll-view/index.js +6 -0
- package/build/angular/components/scroll-view/index.js.map +1 -0
- package/build/angular/components/scroll-view/projection.d.ts +32 -0
- package/build/angular/components/scroll-view/projection.js +334 -0
- package/build/angular/components/scroll-view/projection.js.map +1 -0
- package/build/angular/components/scroll-view/shared.d.ts +230 -0
- package/build/angular/components/scroll-view/shared.js +682 -0
- package/build/angular/components/scroll-view/shared.js.map +1 -0
- package/build/angular/components/scroll-view/sticky-header.d.ts +40 -0
- package/build/angular/components/scroll-view/sticky-header.js +225 -0
- package/build/angular/components/scroll-view/sticky-header.js.map +1 -0
- package/build/angular/components/section-list/index.d.ts +116 -0
- package/build/angular/components/section-list/index.js +641 -0
- package/build/angular/components/section-list/index.js.map +1 -0
- package/build/angular/components/switch/index.android.d.ts +20 -0
- package/build/angular/components/switch/index.android.js +70 -0
- package/build/angular/components/switch/index.android.js.map +1 -0
- package/build/angular/components/switch/index.d.ts +1 -0
- package/build/angular/components/switch/index.ios.d.ts +19 -0
- package/build/angular/components/switch/index.ios.js +69 -0
- package/build/angular/components/switch/index.ios.js.map +1 -0
- package/build/angular/components/switch/index.js +4 -0
- package/build/angular/components/switch/index.js.map +1 -0
- package/build/angular/components/switch/shared.d.ts +40 -0
- package/build/angular/components/switch/shared.js +127 -0
- package/build/angular/components/switch/shared.js.map +1 -0
- package/build/angular/components/text-input.d.ts +153 -0
- package/build/angular/components/text-input.js +599 -0
- package/build/angular/components/text-input.js.map +1 -0
- package/build/angular/components/touchable/index.d.ts +245 -0
- package/build/angular/components/touchable/index.js +1186 -0
- package/build/angular/components/touchable/index.js.map +1 -0
- package/build/angular/components/touchable-native-feedback/index.d.ts +83 -0
- package/build/angular/components/touchable-native-feedback/index.js +371 -0
- package/build/angular/components/touchable-native-feedback/index.js.map +1 -0
- package/build/angular/components/virtualized-list/directives.d.ts +54 -0
- package/build/angular/components/virtualized-list/directives.js +153 -0
- package/build/angular/components/virtualized-list/directives.js.map +1 -0
- package/build/angular/components/virtualized-list/index.d.ts +253 -0
- package/build/angular/components/virtualized-list/index.js +1031 -0
- package/build/angular/components/virtualized-list/index.js.map +1 -0
- package/build/angular/components/virtualized-section-list/directives.d.ts +37 -0
- package/build/angular/components/virtualized-section-list/directives.js +76 -0
- package/build/angular/components/virtualized-section-list/directives.js.map +1 -0
- package/build/angular/components/virtualized-section-list/index.d.ts +178 -0
- package/build/angular/components/virtualized-section-list/index.js +720 -0
- package/build/angular/components/virtualized-section-list/index.js.map +1 -0
- package/build/angular/components.d.ts +39 -0
- package/build/angular/components.js +38 -0
- package/build/angular/components.js.map +1 -0
- package/build/angular/create-portal/index.d.ts +22 -0
- package/build/angular/create-portal/index.js +74 -0
- package/build/angular/create-portal/index.js.map +1 -0
- package/build/angular/create-tunnel/index.d.ts +34 -0
- package/build/angular/create-tunnel/index.js +126 -0
- package/build/angular/create-tunnel/index.js.map +1 -0
- package/build/angular/descriptor-to-angular/index.d.ts +22 -0
- package/build/angular/descriptor-to-angular/index.js +142 -0
- package/build/angular/descriptor-to-angular/index.js.map +1 -0
- package/build/angular/host-instance/index.d.ts +2 -0
- package/build/angular/host-instance/index.js +37 -0
- package/build/angular/host-instance/index.js.map +1 -0
- package/build/angular/index.d.ts +22 -0
- package/build/angular/index.js +46 -0
- package/build/angular/index.js.map +1 -0
- package/build/angular/modules/animated/animated-leaf-binder/index.d.ts +14 -0
- package/build/angular/modules/animated/animated-leaf-binder/index.js +91 -0
- package/build/angular/modules/animated/animated-leaf-binder/index.js.map +1 -0
- package/build/angular/modules/animated/animated-leaf-binder.d.ts +14 -0
- package/build/angular/modules/animated/animated-leaf-binder.js +91 -0
- package/build/angular/modules/animated/animated-leaf-binder.js.map +1 -0
- package/build/angular/modules/animated/create-animated-component.d.ts +59 -0
- package/build/angular/modules/animated/create-animated-component.js +364 -0
- package/build/angular/modules/animated/create-animated-component.js.map +1 -0
- package/build/angular/modules/animated/index.d.ts +51 -0
- package/build/angular/modules/animated/index.js +59 -0
- package/build/angular/modules/animated/index.js.map +1 -0
- package/build/angular/modules/app-registry/index.d.ts +7 -0
- package/build/angular/modules/app-registry/index.js +23 -0
- package/build/angular/modules/app-registry/index.js.map +1 -0
- package/build/angular/modules/status-bar/index.d.ts +20 -0
- package/build/angular/modules/status-bar/index.js +59 -0
- package/build/angular/modules/status-bar/index.js.map +1 -0
- package/build/angular/primitives/index.d.ts +63 -0
- package/build/angular/primitives/index.js +189 -0
- package/build/angular/primitives/index.js.map +1 -0
- package/build/angular/primitives/shared.d.ts +88 -0
- package/build/angular/primitives/shared.js +171 -0
- package/build/angular/primitives/shared.js.map +1 -0
- package/build/angular/render/index.d.ts +11 -0
- package/build/angular/render/index.js +171 -0
- package/build/angular/render/index.js.map +1 -0
- package/build/angular/renderer/index.d.ts +37 -0
- package/build/angular/renderer/index.js +301 -0
- package/build/angular/renderer/index.js.map +1 -0
- package/build/angular/services/color-scheme.service.d.ts +16 -0
- package/build/angular/services/color-scheme.service.js +31 -0
- package/build/angular/services/color-scheme.service.js.map +1 -0
- package/build/angular/services/index.d.ts +2 -0
- package/build/angular/services/index.js +3 -0
- package/build/angular/services/index.js.map +1 -0
- package/build/angular/services/window-dimensions.service.d.ts +16 -0
- package/build/angular/services/window-dimensions.service.js +42 -0
- package/build/angular/services/window-dimensions.service.js.map +1 -0
- package/metro-config.cjs +48 -0
- package/metro-css-parser.cjs +13 -0
- package/package.json +80 -0
- package/src/__tests__/responder-change-detection.test.ts +102 -0
- package/src/__tests__/responder-nested-cd.test.ts +113 -0
- package/src/anchor-host-registry.ts +88 -0
- package/src/angular-gaps.test.ts +142 -0
- package/src/angular-imports.test.ts +100 -0
- package/src/bootstrap.ts +26 -0
- package/src/components/activity-indicator/activity-indicator-class-style.test.ts +44 -0
- package/src/components/activity-indicator/activity-indicator.test.ts +131 -0
- package/src/components/activity-indicator/index.android.ts +16 -0
- package/src/components/activity-indicator/index.ios.ts +17 -0
- package/src/components/activity-indicator/index.ts +4 -0
- package/src/components/activity-indicator/shared.ts +206 -0
- package/src/components/button.ts +193 -0
- package/src/components/flat-list/column-wrapper-style-class.test.ts +116 -0
- package/src/components/flat-list/flat-list-array-style.test.ts +131 -0
- package/src/components/flat-list/flat-list-class-style.test.ts +74 -0
- package/src/components/flat-list/flat-list-scroll-containment.test.ts +107 -0
- package/src/components/flat-list/flat-list.test.ts +99 -0
- package/src/components/flat-list/index.ts +574 -0
- package/src/components/image/image-class-style.test.ts +46 -0
- package/src/components/image/index.android.ts +48 -0
- package/src/components/image/index.ios.ts +48 -0
- package/src/components/image/index.ts +3 -0
- package/src/components/image/shared.ts +479 -0
- package/src/components/image-background-class-style.test.ts +48 -0
- package/src/components/image-background-style-class.test.ts +79 -0
- package/src/components/image-background.ts +270 -0
- package/src/components/input-accessory-view/index.ts +185 -0
- package/src/components/input-accessory-view/input-accessory-view.test.ts +43 -0
- package/src/components/keyboard-avoiding-view/index.ts +303 -0
- package/src/components/keyboard-avoiding-view/keyboard-avoiding-view.test.ts +54 -0
- package/src/components/modal/index.ts +299 -0
- package/src/components/modal/modal.test.ts +43 -0
- package/src/components/pressable/index.ts +373 -0
- package/src/components/pressable/pressable.test.ts +85 -0
- package/src/components/refresh-control/index.ts +284 -0
- package/src/components/refresh-control/refresh-control.test.ts +41 -0
- package/src/components/safe-area-view/index.ts +177 -0
- package/src/components/safe-area-view/safe-area-view.test.ts +43 -0
- package/src/components/scroll-view/android-scroll-view-axis-projection.test.ts +123 -0
- package/src/components/scroll-view/content-container-style-class.test.ts +75 -0
- package/src/components/scroll-view/index.android.ts +190 -0
- package/src/components/scroll-view/index.ios.ts +79 -0
- package/src/components/scroll-view/index.ts +7 -0
- package/src/components/scroll-view/projection.ts +414 -0
- package/src/components/scroll-view/scroll-view-class-style.test.ts +134 -0
- package/src/components/scroll-view/scroll-view-projection.test.ts +194 -0
- package/src/components/scroll-view/shared.ts +844 -0
- package/src/components/scroll-view/sticky-header.ts +255 -0
- package/src/components/section-list/index.ts +445 -0
- package/src/components/switch/android-switch-class.test.ts +42 -0
- package/src/components/switch/index.android.ts +61 -0
- package/src/components/switch/index.ios.ts +60 -0
- package/src/components/switch/index.ts +4 -0
- package/src/components/switch/shared.ts +197 -0
- package/src/components/switch/switch.test.ts +92 -0
- package/src/components/text-input-class-style.test.ts +54 -0
- package/src/components/text-input.ts +531 -0
- package/src/components/touchable/index.ts +629 -0
- package/src/components/touchable/touchable.test.ts +102 -0
- package/src/components/touchable-native-feedback/index.ts +254 -0
- package/src/components/touchable-native-feedback/touchable-native-feedback.test.ts +49 -0
- package/src/components/virtualized-list/directives.ts +168 -0
- package/src/components/virtualized-list/index.ts +992 -0
- package/src/components/virtualized-list/virtualized-list-class-style.test.ts +76 -0
- package/src/components/virtualized-section-list/directives.ts +90 -0
- package/src/components/virtualized-section-list/index.ts +601 -0
- package/src/components/virtualized-section-list/virtualized-section-list-class-style.test.ts +60 -0
- package/src/components.ts +149 -0
- package/src/create-portal/create-portal.test.ts +90 -0
- package/src/create-portal/index.ts +74 -0
- package/src/create-tunnel/create-tunnel.test.ts +120 -0
- package/src/create-tunnel/index.ts +136 -0
- package/src/descriptor-to-angular/descriptor-outlet.test.ts +94 -0
- package/src/descriptor-to-angular/index.ts +190 -0
- package/src/host-instance/host-instance.test.ts +49 -0
- package/src/host-instance/index.ts +36 -0
- package/src/index.ts +261 -0
- package/src/modules/animated/animated-leaf-binder/animated-leaf-binder.test.ts +116 -0
- package/src/modules/animated/animated-leaf-binder/index.ts +101 -0
- package/src/modules/animated/animated-leaf-binder.test.ts +116 -0
- package/src/modules/animated/animated-leaf-binder.ts +101 -0
- package/src/modules/animated/animated-scroll-view.test.ts +102 -0
- package/src/modules/animated/create-animated-component.ts +365 -0
- package/src/modules/animated/index.ts +105 -0
- package/src/modules/app-registry/app-registry.test.ts +106 -0
- package/src/modules/app-registry/index.ts +60 -0
- package/src/modules/status-bar/index.ts +57 -0
- package/src/modules/status-bar/status-bar.test.ts +50 -0
- package/src/primitives/index.ts +119 -0
- package/src/primitives/shared.ts +190 -0
- package/src/render/index.ts +235 -0
- package/src/render/render.test.ts +147 -0
- package/src/renderer/index.ts +347 -0
- package/src/renderer/renderer.test.ts +203 -0
- package/src/services/color-scheme.service.ts +27 -0
- package/src/services/index.ts +2 -0
- package/src/services/services.test.ts +163 -0
- package/src/services/window-dimensions.service.ts +41 -0
- package/tsconfig.angular.base.json +30 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import '@angular/compiler';
|
|
2
|
+
import { Component } from '@angular/core';
|
|
3
|
+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
4
|
+
import { installFabric } from '@symbiote-native/test-utils';
|
|
5
|
+
|
|
6
|
+
import { mount, unmount } from '../../render';
|
|
7
|
+
import { FlatList } from './index';
|
|
8
|
+
import {
|
|
9
|
+
VListEmptyDirective,
|
|
10
|
+
VListFooterDirective,
|
|
11
|
+
VListHeaderDirective,
|
|
12
|
+
VListItemDirective,
|
|
13
|
+
} from '../virtualized-list/directives';
|
|
14
|
+
|
|
15
|
+
const ROOT_TAG = 904;
|
|
16
|
+
const fabric = installFabric();
|
|
17
|
+
|
|
18
|
+
interface IRow {
|
|
19
|
+
id: string;
|
|
20
|
+
n: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const rows: IRow[] = Array.from({ length: 5 }, (_unused, index) => ({
|
|
24
|
+
id: `r-${index}`,
|
|
25
|
+
n: index,
|
|
26
|
+
}));
|
|
27
|
+
|
|
28
|
+
// Regression coverage for a real bug: FlatList's single-column path used to forward the app's
|
|
29
|
+
// <ng-template vListItem> to the inner VirtualizedList via a bare <ng-content></ng-content>
|
|
30
|
+
// passthrough. Angular's @ContentChild does NOT resolve a directive across that second projection
|
|
31
|
+
// hop (it only sees what was projected directly onto the querying component's own tag), so
|
|
32
|
+
// VirtualizedList's itemDir stayed undefined and every cell rendered empty — a real device symptom
|
|
33
|
+
// (a blank list) that headless testing never caught because no test existed for this component
|
|
34
|
+
// family. Fixed by having FlatList capture its own @ContentChild (a single, direct hop) and
|
|
35
|
+
// re-stamp explicit <ng-template>s onto <VirtualizedList>, mirroring VirtualizedSectionList's own
|
|
36
|
+
// (already-working) re-stamp pattern. SectionList had the identical bug, fixed the same way.
|
|
37
|
+
@Component({
|
|
38
|
+
selector: 'symbiote-flatlist-host',
|
|
39
|
+
standalone: true,
|
|
40
|
+
imports: [
|
|
41
|
+
FlatList,
|
|
42
|
+
VListItemDirective,
|
|
43
|
+
VListHeaderDirective,
|
|
44
|
+
VListFooterDirective,
|
|
45
|
+
VListEmptyDirective,
|
|
46
|
+
],
|
|
47
|
+
template: `
|
|
48
|
+
<FlatList
|
|
49
|
+
testID="rows-list"
|
|
50
|
+
[data]="rows"
|
|
51
|
+
[keyExtractor]="keyExtractor"
|
|
52
|
+
[getItemLayout]="getItemLayout"
|
|
53
|
+
[style]="{ height: 120 }"
|
|
54
|
+
>
|
|
55
|
+
<ng-template vListHeader>
|
|
56
|
+
<symbiote-text testID="header">header</symbiote-text>
|
|
57
|
+
</ng-template>
|
|
58
|
+
<ng-template vListItem let-item>
|
|
59
|
+
<symbiote-text [testID]="'row-' + item.n">{{ 'row ' + item.n }}</symbiote-text>
|
|
60
|
+
</ng-template>
|
|
61
|
+
<ng-template vListFooter>
|
|
62
|
+
<symbiote-text testID="footer">footer</symbiote-text>
|
|
63
|
+
</ng-template>
|
|
64
|
+
</FlatList>
|
|
65
|
+
`,
|
|
66
|
+
})
|
|
67
|
+
class FlatListHost {
|
|
68
|
+
rows = rows;
|
|
69
|
+
keyExtractor = (item: IRow): string => item.id;
|
|
70
|
+
getItemLayout = (
|
|
71
|
+
_data: unknown,
|
|
72
|
+
index: number,
|
|
73
|
+
): { length: number; offset: number; index: number } => ({
|
|
74
|
+
length: 30,
|
|
75
|
+
offset: 30 * index,
|
|
76
|
+
index,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
beforeEach(() => fabric.reset());
|
|
81
|
+
afterEach(() => unmount(ROOT_TAG));
|
|
82
|
+
|
|
83
|
+
describe('FlatList', () => {
|
|
84
|
+
it('stamps the header, every row, and the footer through the projected templates', async () => {
|
|
85
|
+
mount(ROOT_TAG, FlatListHost);
|
|
86
|
+
await new Promise<void>(resolve => setTimeout(resolve, 0));
|
|
87
|
+
await new Promise<void>(resolve => setTimeout(resolve, 0));
|
|
88
|
+
|
|
89
|
+
const texts = fabric.created
|
|
90
|
+
.filter(node => node.props.testID !== undefined)
|
|
91
|
+
.map(node => node.props.testID);
|
|
92
|
+
|
|
93
|
+
expect(texts).toContain('header');
|
|
94
|
+
expect(texts).toContain('footer');
|
|
95
|
+
for (let index = 0; index < rows.length; index += 1) {
|
|
96
|
+
expect(texts).toContain(`row-${index}`);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
});
|
|
@@ -0,0 +1,574 @@
|
|
|
1
|
+
// FlatList, the Angular convenience surface over VirtualizedList. It takes a plain `data` array
|
|
2
|
+
// and derives getItem/getItemCount; numColumns packs items into rows (each row a flex-row of N
|
|
3
|
+
// columns), so the virtualized stream is rows, not items (RN's FlatList). All windowing /
|
|
4
|
+
// viewability / batching / imperative scrolling are inherited from VirtualizedList; the data
|
|
5
|
+
// shaping (chunkIntoRows / rowKeyExtractor / expandRowViewability / row-separator unwrap) is shared
|
|
6
|
+
// verbatim from @symbiote-native/components, exactly as the React and Vue FlatLists reuse it. This is the
|
|
7
|
+
// Angular twin of adapters/vue/src/components/flat-list/index.ts.
|
|
8
|
+
//
|
|
9
|
+
// TEMPLATE FORWARDING — both paths RE-STAMP; neither uses a bare `<ng-content>` passthrough.
|
|
10
|
+
// Angular's @ContentChild does NOT resolve a directive across a SECOND `<ng-content>` re-projection
|
|
11
|
+
// hop (it only sees what was projected directly onto the querying component's own tag) — a bare
|
|
12
|
+
// `<VirtualizedList ...><ng-content></ng-content></VirtualizedList>` here left VirtualizedList's own
|
|
13
|
+
// itemDir/headerDir/etc. undefined, so every cell rendered empty (a real, confirmed device bug — see
|
|
14
|
+
// flat-list.test.ts). Fixed for both column modes the same way:
|
|
15
|
+
// * Single column (numColumns <= 1): FlatList captures the app's `<ng-template vListItem>` (and
|
|
16
|
+
// vListHeader/vListFooter/vListEmpty/vListSeparator) with its OWN @ContentChild — a single,
|
|
17
|
+
// direct projection hop, which always resolves — then re-authors equivalent `<ng-template>`s on
|
|
18
|
+
// `<VirtualizedList>`, each forwarding the captured templateRef + context through
|
|
19
|
+
// VListOutletDirective. Item/index/separators pass through 1:1 (no row wrapping).
|
|
20
|
+
// * Multi column (numColumns > 1): the same re-stamp, but the app's vListItem is typed for ItemT
|
|
21
|
+
// while the virtualized stream is rows (IRow<ItemT>), so a plain passthrough couldn't work even if
|
|
22
|
+
// the projection issue didn't exist. The row vListItem lays out the N columns side by side (each
|
|
23
|
+
// cell stamps the app's item template via VListOutletDirective with the per-item context {item,
|
|
24
|
+
// index: row.startIndex + column, separators}), the row vListSeparator unwraps the flanking rows
|
|
25
|
+
// to their last/first item, and onViewableItemsChanged is wrapped with expandRowViewability so the
|
|
26
|
+
// caller still sees per-item visibility. This mirrors exactly how Vue's FlatList intercepts
|
|
27
|
+
// renderItem with renderRow.
|
|
28
|
+
//
|
|
29
|
+
// The imperative handle (scrollToIndex / scrollToOffset / scrollToEnd / scrollToItem /
|
|
30
|
+
// recordInteraction / flashScrollIndicators / getScroll* / getNativeScrollRef) is RN's FlatList
|
|
31
|
+
// surface; FlatList re-exposes it by delegating to the inner VirtualizedList (@ViewChild). The
|
|
32
|
+
// element-returning props (renderItem / ItemSeparatorComponent / List{Header,Footer,Empty}Component)
|
|
33
|
+
// are templates in Angular, so they are absent from IFlatListProps, per the per-adapter
|
|
34
|
+
// children/render prop split; everything agnostic mirrors IVirtualizedListProps.
|
|
35
|
+
|
|
36
|
+
import {
|
|
37
|
+
CUSTOM_ELEMENTS_SCHEMA,
|
|
38
|
+
ChangeDetectionStrategy,
|
|
39
|
+
Component,
|
|
40
|
+
ContentChild,
|
|
41
|
+
ElementRef,
|
|
42
|
+
EventEmitter,
|
|
43
|
+
Input,
|
|
44
|
+
Output,
|
|
45
|
+
ViewChild,
|
|
46
|
+
inject,
|
|
47
|
+
type OnChanges,
|
|
48
|
+
type SimpleChanges,
|
|
49
|
+
} from '@angular/core';
|
|
50
|
+
import {
|
|
51
|
+
SINGLE_COLUMN,
|
|
52
|
+
chunkIntoRows,
|
|
53
|
+
expandRowViewability,
|
|
54
|
+
firstItemOfRow,
|
|
55
|
+
lastItemOfRow,
|
|
56
|
+
rowKeyExtractor,
|
|
57
|
+
type IRow,
|
|
58
|
+
type IScrollViewHandle,
|
|
59
|
+
type ISeparators,
|
|
60
|
+
type IViewabilityConfigCallbackPair,
|
|
61
|
+
type IViewableItemsChangedInfo,
|
|
62
|
+
type IVirtualizedListHandle,
|
|
63
|
+
} from '@symbiote-native/components';
|
|
64
|
+
import {
|
|
65
|
+
dlog,
|
|
66
|
+
flattenStyle,
|
|
67
|
+
resolveClassName,
|
|
68
|
+
type IStyleProp,
|
|
69
|
+
type ISymbioteNode,
|
|
70
|
+
type IViewStyle,
|
|
71
|
+
} from '@symbiote-native/engine';
|
|
72
|
+
import {
|
|
73
|
+
VirtualizedList,
|
|
74
|
+
VListEmptyDirective,
|
|
75
|
+
VListFooterDirective,
|
|
76
|
+
VListHeaderDirective,
|
|
77
|
+
VListItemDirective,
|
|
78
|
+
VListSeparatorDirective,
|
|
79
|
+
type IVirtualizedListProps,
|
|
80
|
+
type IVListItemContext,
|
|
81
|
+
type IVListSeparatorContext,
|
|
82
|
+
} from '../virtualized-list';
|
|
83
|
+
import { VListOutletDirective } from '../virtualized-list/directives';
|
|
84
|
+
import { stableAnchorStyle, ViewHost } from '../../primitives';
|
|
85
|
+
|
|
86
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
87
|
+
return typeof value === 'object' && value !== null;
|
|
88
|
+
}
|
|
89
|
+
function isRow<ItemT>(value: unknown): value is IRow<ItemT> {
|
|
90
|
+
return (
|
|
91
|
+
isRecord(value) && Array.isArray(value['items']) && typeof value['startIndex'] === 'number'
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
function isSeparators(value: unknown): value is ISeparators {
|
|
95
|
+
return (
|
|
96
|
+
isRecord(value) &&
|
|
97
|
+
typeof value['highlight'] === 'function' &&
|
|
98
|
+
typeof value['unhighlight'] === 'function'
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
// Used only as a type-safe fallback if a row's separators handle is ever absent; VirtualizedList
|
|
102
|
+
// always supplies a real one, so in practice the live handle flows through.
|
|
103
|
+
const NOOP_SEPARATORS: ISeparators = {
|
|
104
|
+
highlight: (): void => undefined,
|
|
105
|
+
unhighlight: (): void => undefined,
|
|
106
|
+
updateProps: (): void => undefined,
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// Angular cannot preserve VListSeparatorDirective<ItemT>'s type parameter across this re-stamp
|
|
110
|
+
// reuse (the directive is matched structurally in FlatList's own template with no explicit type
|
|
111
|
+
// argument to pin ItemT to, so `let-leadingItem`/`let-trailingItem` arrive typed `unknown`) — even
|
|
112
|
+
// though VirtualizedList's own buildSeparatorContext always supplies a real ItemT value. The
|
|
113
|
+
// narrowest possible I/O-boundary cast for that gap; not a general-purpose unknown-to-T narrowing.
|
|
114
|
+
function asItem<ItemT>(value: unknown): ItemT | undefined {
|
|
115
|
+
return value as ItemT | undefined;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Re-export the shared list types + the authoring directives so the app can import the cell/slot
|
|
119
|
+
// directives alongside FlatList (mirrors how virtualized-list/index re-exports them).
|
|
120
|
+
export type {
|
|
121
|
+
ISeparators,
|
|
122
|
+
IViewableItemsChangedInfo,
|
|
123
|
+
IViewabilityConfigCallbackPair,
|
|
124
|
+
IVirtualizedListHandle,
|
|
125
|
+
} from '@symbiote-native/components';
|
|
126
|
+
export {
|
|
127
|
+
VListEmptyDirective,
|
|
128
|
+
VListFooterDirective,
|
|
129
|
+
VListHeaderDirective,
|
|
130
|
+
VListItemDirective,
|
|
131
|
+
VListSeparatorDirective,
|
|
132
|
+
} from '../virtualized-list';
|
|
133
|
+
export type { IVListItemContext, IVListSeparatorContext } from '../virtualized-list';
|
|
134
|
+
|
|
135
|
+
// FlatList's imperative handle is exactly VirtualizedList's.
|
|
136
|
+
export type IFlatListHandle = IVirtualizedListHandle;
|
|
137
|
+
|
|
138
|
+
// The Angular FlatList prop surface. Mirrors React/Vue's IFlatListProps: every agnostic
|
|
139
|
+
// VirtualizedList prop EXCEPT data/getItem/getItemCount (FlatList derives those from a plain `data`
|
|
140
|
+
// array), PLUS numColumns + columnWrapperStyle. The element-returning props are templates in
|
|
141
|
+
// Angular, so they are absent here (they were already absent from IVirtualizedListProps).
|
|
142
|
+
export type IFlatListProps<ItemT> = Omit<
|
|
143
|
+
IVirtualizedListProps<ItemT>,
|
|
144
|
+
'data' | 'getItem' | 'getItemCount'
|
|
145
|
+
> & {
|
|
146
|
+
data: readonly ItemT[];
|
|
147
|
+
numColumns?: number;
|
|
148
|
+
// Style for the auto-generated row View when numColumns > 1 (RN's columnWrapperStyle). A bare
|
|
149
|
+
// string resolves through the shared style registry.
|
|
150
|
+
columnWrapperStyle?: IStyleProp<IViewStyle> | string;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
// What the FlatList component itself takes as plain @Input()s: the full surface minus the events
|
|
154
|
+
// it exposes as real @Output() EventEmitters instead (see the class below), mirroring how
|
|
155
|
+
// pressable/index.ts derives IAngularPressableInputs from IAngularPressableProps.
|
|
156
|
+
export type IFlatListInputs<ItemT> = Omit<
|
|
157
|
+
IFlatListProps<ItemT>,
|
|
158
|
+
| 'onEndReached'
|
|
159
|
+
| 'onStartReached'
|
|
160
|
+
| 'onRefresh'
|
|
161
|
+
| 'onViewableItemsChanged'
|
|
162
|
+
| 'onScrollToIndexFailed'
|
|
163
|
+
>;
|
|
164
|
+
|
|
165
|
+
@Component({
|
|
166
|
+
selector: 'FlatList',
|
|
167
|
+
standalone: true,
|
|
168
|
+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
|
169
|
+
imports: [
|
|
170
|
+
VirtualizedList,
|
|
171
|
+
VListItemDirective,
|
|
172
|
+
VListHeaderDirective,
|
|
173
|
+
VListFooterDirective,
|
|
174
|
+
VListEmptyDirective,
|
|
175
|
+
VListSeparatorDirective,
|
|
176
|
+
VListOutletDirective,
|
|
177
|
+
ViewHost,
|
|
178
|
+
],
|
|
179
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
180
|
+
template: `
|
|
181
|
+
@if (isMultiColumn) {
|
|
182
|
+
<VirtualizedList
|
|
183
|
+
[data]="rows"
|
|
184
|
+
[getItem]="getRow"
|
|
185
|
+
[getItemCount]="getRowCount"
|
|
186
|
+
[keyExtractor]="rowKey"
|
|
187
|
+
[getItemLayout]="getItemLayout"
|
|
188
|
+
[horizontal]="horizontal"
|
|
189
|
+
[inverted]="inverted"
|
|
190
|
+
[extraData]="extraData"
|
|
191
|
+
(endReached)="endReached.emit($event)"
|
|
192
|
+
[onEndReachedThreshold]="onEndReachedThreshold"
|
|
193
|
+
(startReached)="startReached.emit($event)"
|
|
194
|
+
[onStartReachedThreshold]="onStartReachedThreshold"
|
|
195
|
+
(refresh)="refresh.emit()"
|
|
196
|
+
[refreshRequested]="refresh.observed"
|
|
197
|
+
[refreshing]="refreshing"
|
|
198
|
+
[progressViewOffset]="progressViewOffset"
|
|
199
|
+
(viewableItemsChanged)="rowViewableItemsChanged($event)"
|
|
200
|
+
[viewabilityConfig]="viewabilityConfig"
|
|
201
|
+
[viewabilityConfigCallbackPairs]="rowViewabilityPairs"
|
|
202
|
+
(scrollToIndexFailed)="scrollToIndexFailed.emit($event)"
|
|
203
|
+
[initialNumToRender]="initialNumToRender"
|
|
204
|
+
[initialScrollIndex]="initialScrollIndex"
|
|
205
|
+
[maxToRenderPerBatch]="maxToRenderPerBatch"
|
|
206
|
+
[updateCellsBatchingPeriod]="updateCellsBatchingPeriod"
|
|
207
|
+
[windowSize]="windowSize"
|
|
208
|
+
[stickyHeaderIndices]="stickyHeaderIndices"
|
|
209
|
+
[maintainVisibleContentPosition]="maintainVisibleContentPosition"
|
|
210
|
+
[onScroll]="onScroll"
|
|
211
|
+
[onScrollBeginDrag]="onScrollBeginDrag"
|
|
212
|
+
[onScrollEndDrag]="onScrollEndDrag"
|
|
213
|
+
[onMomentumScrollBegin]="onMomentumScrollBegin"
|
|
214
|
+
[onMomentumScrollEnd]="onMomentumScrollEnd"
|
|
215
|
+
[scrollEventThrottle]="scrollEventThrottle"
|
|
216
|
+
[keyboardShouldPersistTaps]="keyboardShouldPersistTaps"
|
|
217
|
+
[keyboardDismissMode]="keyboardDismissMode"
|
|
218
|
+
[style]="resolvedStyle"
|
|
219
|
+
[contentContainerStyle]="contentContainerStyle"
|
|
220
|
+
>
|
|
221
|
+
<ng-template vListItem let-row let-separators="separators">
|
|
222
|
+
<symbiote-view [style]="rowStyle">
|
|
223
|
+
@for (cell of rowCells(row, separators); track cell.key) {
|
|
224
|
+
<symbiote-view [style]="columnCellStyle">
|
|
225
|
+
<ng-container
|
|
226
|
+
[vListOutlet]="itemDir?.templateRef"
|
|
227
|
+
[vListOutletContext]="cell.context"
|
|
228
|
+
></ng-container>
|
|
229
|
+
</symbiote-view>
|
|
230
|
+
}
|
|
231
|
+
</symbiote-view>
|
|
232
|
+
</ng-template>
|
|
233
|
+
@if (headerDir !== undefined) {
|
|
234
|
+
<ng-template vListHeader>
|
|
235
|
+
<ng-container [vListOutlet]="headerDir.templateRef"></ng-container>
|
|
236
|
+
</ng-template>
|
|
237
|
+
}
|
|
238
|
+
@if (footerDir !== undefined) {
|
|
239
|
+
<ng-template vListFooter>
|
|
240
|
+
<ng-container [vListOutlet]="footerDir.templateRef"></ng-container>
|
|
241
|
+
</ng-template>
|
|
242
|
+
}
|
|
243
|
+
@if (emptyDir !== undefined) {
|
|
244
|
+
<ng-template vListEmpty>
|
|
245
|
+
<ng-container [vListOutlet]="emptyDir.templateRef"></ng-container>
|
|
246
|
+
</ng-template>
|
|
247
|
+
}
|
|
248
|
+
@if (separatorDir !== undefined) {
|
|
249
|
+
<ng-template
|
|
250
|
+
vListSeparator
|
|
251
|
+
let-highlighted="highlighted"
|
|
252
|
+
let-leadingItem="leadingItem"
|
|
253
|
+
let-trailingItem="trailingItem"
|
|
254
|
+
>
|
|
255
|
+
<ng-container
|
|
256
|
+
[vListOutlet]="separatorDir.templateRef"
|
|
257
|
+
[vListOutletContext]="rowSeparatorContext(highlighted, leadingItem, trailingItem)"
|
|
258
|
+
></ng-container>
|
|
259
|
+
</ng-template>
|
|
260
|
+
}
|
|
261
|
+
</VirtualizedList>
|
|
262
|
+
} @else {
|
|
263
|
+
<VirtualizedList
|
|
264
|
+
[data]="data"
|
|
265
|
+
[getItem]="getFlatItem"
|
|
266
|
+
[getItemCount]="getFlatCount"
|
|
267
|
+
[keyExtractor]="keyExtractor"
|
|
268
|
+
[getItemLayout]="getItemLayout"
|
|
269
|
+
[horizontal]="horizontal"
|
|
270
|
+
[inverted]="inverted"
|
|
271
|
+
[extraData]="extraData"
|
|
272
|
+
(endReached)="endReached.emit($event)"
|
|
273
|
+
[onEndReachedThreshold]="onEndReachedThreshold"
|
|
274
|
+
(startReached)="startReached.emit($event)"
|
|
275
|
+
[onStartReachedThreshold]="onStartReachedThreshold"
|
|
276
|
+
(refresh)="refresh.emit()"
|
|
277
|
+
[refreshRequested]="refresh.observed"
|
|
278
|
+
[refreshing]="refreshing"
|
|
279
|
+
[progressViewOffset]="progressViewOffset"
|
|
280
|
+
(viewableItemsChanged)="viewableItemsChanged.emit($event)"
|
|
281
|
+
[viewabilityConfig]="viewabilityConfig"
|
|
282
|
+
[viewabilityConfigCallbackPairs]="viewabilityConfigCallbackPairs"
|
|
283
|
+
(scrollToIndexFailed)="scrollToIndexFailed.emit($event)"
|
|
284
|
+
[initialNumToRender]="initialNumToRender"
|
|
285
|
+
[initialScrollIndex]="initialScrollIndex"
|
|
286
|
+
[maxToRenderPerBatch]="maxToRenderPerBatch"
|
|
287
|
+
[updateCellsBatchingPeriod]="updateCellsBatchingPeriod"
|
|
288
|
+
[windowSize]="windowSize"
|
|
289
|
+
[stickyHeaderIndices]="stickyHeaderIndices"
|
|
290
|
+
[maintainVisibleContentPosition]="maintainVisibleContentPosition"
|
|
291
|
+
[onScroll]="onScroll"
|
|
292
|
+
[onScrollBeginDrag]="onScrollBeginDrag"
|
|
293
|
+
[onScrollEndDrag]="onScrollEndDrag"
|
|
294
|
+
[onMomentumScrollBegin]="onMomentumScrollBegin"
|
|
295
|
+
[onMomentumScrollEnd]="onMomentumScrollEnd"
|
|
296
|
+
[scrollEventThrottle]="scrollEventThrottle"
|
|
297
|
+
[keyboardShouldPersistTaps]="keyboardShouldPersistTaps"
|
|
298
|
+
[keyboardDismissMode]="keyboardDismissMode"
|
|
299
|
+
[style]="resolvedStyle"
|
|
300
|
+
[contentContainerStyle]="contentContainerStyle"
|
|
301
|
+
>
|
|
302
|
+
<ng-template vListItem let-item let-index="index" let-separators="separators">
|
|
303
|
+
<ng-container
|
|
304
|
+
[vListOutlet]="itemDir?.templateRef"
|
|
305
|
+
[vListOutletContext]="{ $implicit: item, index, separators }"
|
|
306
|
+
></ng-container>
|
|
307
|
+
</ng-template>
|
|
308
|
+
@if (headerDir !== undefined) {
|
|
309
|
+
<ng-template vListHeader>
|
|
310
|
+
<ng-container [vListOutlet]="headerDir.templateRef"></ng-container>
|
|
311
|
+
</ng-template>
|
|
312
|
+
}
|
|
313
|
+
@if (footerDir !== undefined) {
|
|
314
|
+
<ng-template vListFooter>
|
|
315
|
+
<ng-container [vListOutlet]="footerDir.templateRef"></ng-container>
|
|
316
|
+
</ng-template>
|
|
317
|
+
}
|
|
318
|
+
@if (emptyDir !== undefined) {
|
|
319
|
+
<ng-template vListEmpty>
|
|
320
|
+
<ng-container [vListOutlet]="emptyDir.templateRef"></ng-container>
|
|
321
|
+
</ng-template>
|
|
322
|
+
}
|
|
323
|
+
@if (separatorDir !== undefined) {
|
|
324
|
+
<ng-template
|
|
325
|
+
vListSeparator
|
|
326
|
+
let-highlighted="highlighted"
|
|
327
|
+
let-leadingItem="leadingItem"
|
|
328
|
+
let-trailingItem="trailingItem"
|
|
329
|
+
>
|
|
330
|
+
<ng-container
|
|
331
|
+
[vListOutlet]="separatorDir.templateRef"
|
|
332
|
+
[vListOutletContext]="itemSeparatorContext(highlighted, leadingItem, trailingItem)"
|
|
333
|
+
></ng-container>
|
|
334
|
+
</ng-template>
|
|
335
|
+
}
|
|
336
|
+
</VirtualizedList>
|
|
337
|
+
}
|
|
338
|
+
`,
|
|
339
|
+
})
|
|
340
|
+
export class FlatList<ItemT = unknown>
|
|
341
|
+
implements IFlatListInputs<ItemT>, IVirtualizedListHandle, OnChanges
|
|
342
|
+
{
|
|
343
|
+
// The list's edge/viewability/failure events as real Angular events: `(endReached)="…"`, not
|
|
344
|
+
// `[onEndReached]="…"` — re-emitted straight from the inner VirtualizedList's own @Output()s (see
|
|
345
|
+
// the template's `(endReached)="endReached.emit($event)"` style forwarding above).
|
|
346
|
+
@Output() readonly endReached = new EventEmitter<{ distanceFromEnd: number }>();
|
|
347
|
+
@Output() readonly startReached = new EventEmitter<{ distanceFromStart: number }>();
|
|
348
|
+
@Output() readonly refresh = new EventEmitter<void>();
|
|
349
|
+
@Output() readonly viewableItemsChanged = new EventEmitter<IViewableItemsChangedInfo<ItemT>>();
|
|
350
|
+
@Output() readonly scrollToIndexFailed = new EventEmitter<{
|
|
351
|
+
index: number;
|
|
352
|
+
highestMeasuredFrameIndex: number;
|
|
353
|
+
averageItemLength: number;
|
|
354
|
+
}>();
|
|
355
|
+
@Input({ required: true }) data!: readonly ItemT[];
|
|
356
|
+
@Input() numColumns?: number;
|
|
357
|
+
@Input() columnWrapperStyle?: IStyleProp<IViewStyle> | string;
|
|
358
|
+
@Input() keyExtractor?: (item: ItemT, index: number) => string;
|
|
359
|
+
@Input() getItemLayout?: (
|
|
360
|
+
data: unknown,
|
|
361
|
+
index: number,
|
|
362
|
+
) => { length: number; offset: number; index: number };
|
|
363
|
+
@Input() horizontal?: boolean;
|
|
364
|
+
@Input() inverted?: boolean;
|
|
365
|
+
@Input() extraData?: unknown;
|
|
366
|
+
@Input() onEndReachedThreshold?: number;
|
|
367
|
+
@Input() onStartReachedThreshold?: number;
|
|
368
|
+
@Input() refreshing?: boolean | null;
|
|
369
|
+
@Input() progressViewOffset?: number;
|
|
370
|
+
@Input() viewabilityConfig?: IVirtualizedListProps<ItemT>['viewabilityConfig'];
|
|
371
|
+
@Input() viewabilityConfigCallbackPairs?: IViewabilityConfigCallbackPair<ItemT>[];
|
|
372
|
+
@Input() initialNumToRender?: number;
|
|
373
|
+
@Input() initialScrollIndex?: number;
|
|
374
|
+
@Input() maxToRenderPerBatch?: number;
|
|
375
|
+
@Input() updateCellsBatchingPeriod?: number;
|
|
376
|
+
@Input() windowSize?: number;
|
|
377
|
+
@Input() stickyHeaderIndices?: number[];
|
|
378
|
+
@Input() maintainVisibleContentPosition?: {
|
|
379
|
+
minIndexForVisible: number;
|
|
380
|
+
autoscrollToTopThreshold?: number;
|
|
381
|
+
};
|
|
382
|
+
@Input() onScroll?: IVirtualizedListProps<ItemT>['onScroll'];
|
|
383
|
+
@Input() onScrollBeginDrag?: IVirtualizedListProps<ItemT>['onScrollBeginDrag'];
|
|
384
|
+
@Input() onScrollEndDrag?: IVirtualizedListProps<ItemT>['onScrollEndDrag'];
|
|
385
|
+
@Input() onMomentumScrollBegin?: IVirtualizedListProps<ItemT>['onMomentumScrollBegin'];
|
|
386
|
+
@Input() onMomentumScrollEnd?: IVirtualizedListProps<ItemT>['onMomentumScrollEnd'];
|
|
387
|
+
@Input() scrollEventThrottle?: number;
|
|
388
|
+
@Input() keyboardShouldPersistTaps?: boolean | 'always' | 'never' | 'handled';
|
|
389
|
+
@Input() keyboardDismissMode?: 'none' | 'on-drag' | 'interactive';
|
|
390
|
+
@Input() style?: IStyleProp<IViewStyle>;
|
|
391
|
+
@Input() contentContainerStyle?: IStyleProp<IViewStyle>;
|
|
392
|
+
|
|
393
|
+
// The app's cell + slot templates, captured for the multi-column re-stamp path. In the
|
|
394
|
+
// single-column path they are ALSO projected through <ng-content> to the inner list and these
|
|
395
|
+
// captures stay unused (the inner list's own @ContentChild resolves them across the projection).
|
|
396
|
+
@ContentChild(VListItemDirective) itemDir?: VListItemDirective<ItemT>;
|
|
397
|
+
@ContentChild(VListHeaderDirective) headerDir?: VListHeaderDirective;
|
|
398
|
+
@ContentChild(VListFooterDirective) footerDir?: VListFooterDirective;
|
|
399
|
+
@ContentChild(VListEmptyDirective) emptyDir?: VListEmptyDirective;
|
|
400
|
+
@ContentChild(VListSeparatorDirective) separatorDir?: VListSeparatorDirective<ItemT>;
|
|
401
|
+
|
|
402
|
+
// The composed inner list (whichever numColumns branch rendered). Its instance IS the
|
|
403
|
+
// IVirtualizedListHandle, so FlatList's handle delegates straight to it.
|
|
404
|
+
@ViewChild(VirtualizedList) private listRef?: VirtualizedList;
|
|
405
|
+
|
|
406
|
+
// This component's OWN host — the non-painting anchor `class="..."` at the use site resolves
|
|
407
|
+
// onto (see anchorHostStyle's doc comment) — NOT `listRef` above, which targets the real inner
|
|
408
|
+
// `<VirtualizedList>` one level down (itself its own separate anchor host).
|
|
409
|
+
private readonly elementRef = inject(ElementRef);
|
|
410
|
+
|
|
411
|
+
// --- derived view state (recomputed in ngOnChanges, stable identity across CD) ---
|
|
412
|
+
rows: IRow<ItemT>[] = [];
|
|
413
|
+
// Angular's [style]="…" binding compiles to the built-in ɵɵstyleMap instruction (NOT a
|
|
414
|
+
// regular @Input() property write), which only understands a flat object — an array (RN's
|
|
415
|
+
// own `style={[a, b]}` composition idiom) crashes deep inside Angular's styling engine. So
|
|
416
|
+
// every style value this component stamps onto a template `[style]=` binding is flattened
|
|
417
|
+
// via the engine's own flattenStyle first, here at the source rather than at each call site.
|
|
418
|
+
rowStyle: IViewStyle = flattenStyle([{ flexDirection: 'row' }]);
|
|
419
|
+
rowViewabilityPairs?: IViewabilityConfigCallbackPair<IRow<ItemT>>[];
|
|
420
|
+
readonly columnCellStyle: IViewStyle = { flex: 1 };
|
|
421
|
+
resolvedStyle: IViewStyle | undefined = undefined;
|
|
422
|
+
|
|
423
|
+
get columns(): number {
|
|
424
|
+
return this.numColumns ?? SINGLE_COLUMN;
|
|
425
|
+
}
|
|
426
|
+
get isMultiColumn(): boolean {
|
|
427
|
+
return this.columns > SINGLE_COLUMN;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
ngOnChanges(changes: SimpleChanges): void {
|
|
431
|
+
// Recomputed on EVERY ngOnChanges call, not gated on `changes['style']`: a class= on the
|
|
432
|
+
// FlatList use site (no matching [style] binding at all) never appears in `changes`, so a
|
|
433
|
+
// guard here would permanently skip picking up anchorHostStyle for that (the actual bug-report
|
|
434
|
+
// shape) — ngOnChanges still fires at least once at mount via the required `data` @Input(), and
|
|
435
|
+
// by then the anchor's class-derived style is already resolved synchronously (routeProp runs
|
|
436
|
+
// inline from Renderer2.addClass, before this component's own lifecycle hooks). stableAnchorStyle
|
|
437
|
+
// (not a bare flattenStyle) keeps `resolvedStyle`'s REFERENCE stable across ticks where nothing
|
|
438
|
+
// actually changed — `[style]="resolvedStyle"` binds onto VirtualizedList's own `@Input() style`,
|
|
439
|
+
// which feeds its `ngDoCheck` dedup gate; a fresh object every tick would defeat that gate and
|
|
440
|
+
// free-run change detection forever (see stableAnchorStyle's doc comment).
|
|
441
|
+
this.resolvedStyle = stableAnchorStyle(this.elementRef, this.style, this.resolvedStyle);
|
|
442
|
+
if (changes['columnWrapperStyle'] !== undefined) {
|
|
443
|
+
// A class-name string resolves through the shared registry before flattenStyle, which
|
|
444
|
+
// only understands style objects/arrays.
|
|
445
|
+
const resolvedColumnWrapperStyle =
|
|
446
|
+
typeof this.columnWrapperStyle === 'string'
|
|
447
|
+
? resolveClassName(this.columnWrapperStyle)
|
|
448
|
+
: this.columnWrapperStyle;
|
|
449
|
+
this.rowStyle = flattenStyle([{ flexDirection: 'row' }, resolvedColumnWrapperStyle]);
|
|
450
|
+
}
|
|
451
|
+
if (changes['data'] !== undefined || changes['numColumns'] !== undefined) {
|
|
452
|
+
this.rows = this.isMultiColumn ? chunkIntoRows(this.data, this.columns) : [];
|
|
453
|
+
dlog(`Angular FlatList over ${this.data?.length ?? 0} items, ${this.columns} column(s)`);
|
|
454
|
+
}
|
|
455
|
+
if (
|
|
456
|
+
changes['viewabilityConfigCallbackPairs'] !== undefined ||
|
|
457
|
+
changes['numColumns'] !== undefined
|
|
458
|
+
) {
|
|
459
|
+
this.rowViewabilityPairs = this.buildRowViewabilityPairs();
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// ---- single-column data adaptation (plain array -> getItem/getItemCount) ----
|
|
464
|
+
getFlatItem = (_data: unknown, index: number): ItemT => this.data[index];
|
|
465
|
+
getFlatCount = (_data: unknown): number => this.data.length;
|
|
466
|
+
|
|
467
|
+
// ---- multi-column data adaptation (the virtualized stream is rows) ----
|
|
468
|
+
getRow = (_data: unknown, index: number): IRow<ItemT> => this.rows[index];
|
|
469
|
+
getRowCount = (_data: unknown): number => this.rows.length;
|
|
470
|
+
rowKey = (row: IRow<ItemT>, _index: number): string => rowKeyExtractor(row);
|
|
471
|
+
|
|
472
|
+
// Viewability over rows expands back to per-item tokens, so the caller sees item-level
|
|
473
|
+
// visibility, not row-level (shared expandRowViewability), matching Vue.
|
|
474
|
+
rowViewableItemsChanged = (info: IViewableItemsChangedInfo<IRow<ItemT>>): void => {
|
|
475
|
+
this.viewableItemsChanged.emit(expandRowViewability(info, this.keyExtractor));
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
private buildRowViewabilityPairs(): IViewabilityConfigCallbackPair<IRow<ItemT>>[] | undefined {
|
|
479
|
+
return this.viewabilityConfigCallbackPairs?.map(pair => ({
|
|
480
|
+
viewabilityConfig: pair.viewabilityConfig,
|
|
481
|
+
onViewableItemsChanged: (rowInfo: IViewableItemsChangedInfo<IRow<ItemT>>): void => {
|
|
482
|
+
pair.onViewableItemsChanged?.(expandRowViewability(rowInfo, this.keyExtractor));
|
|
483
|
+
},
|
|
484
|
+
}));
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
// Lay out one row's N columns: every item shares the row's separators handle (the divider sits
|
|
488
|
+
// between rows, not columns) and carries its absolute index (row.startIndex + column), like RN's
|
|
489
|
+
// multi-column FlatList. Args arrive `unknown` from the template's `let` bindings (Angular cannot
|
|
490
|
+
// type a generic structural directive's context), narrowed here — no `as`.
|
|
491
|
+
rowCells(
|
|
492
|
+
row: unknown,
|
|
493
|
+
separators: unknown,
|
|
494
|
+
): { key: string; context: IVListItemContext<ItemT> }[] {
|
|
495
|
+
if (!isRow<ItemT>(row)) return [];
|
|
496
|
+
const handle = isSeparators(separators) ? separators : NOOP_SEPARATORS;
|
|
497
|
+
return row.items.map((item, column) => {
|
|
498
|
+
const index = row.startIndex + column;
|
|
499
|
+
const key = this.keyExtractor ? this.keyExtractor(item, index) : String(index);
|
|
500
|
+
return { key, context: { $implicit: item, index, separators: handle } };
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
// The divider between rows shows real items (last of the row above, first of the row below), so the
|
|
505
|
+
// app's separator template, typed on ItemT, sees items rather than the IRow wrapper. Args arrive
|
|
506
|
+
// `unknown` from the template's `let` bindings, narrowed here.
|
|
507
|
+
rowSeparatorContext(
|
|
508
|
+
highlighted: unknown,
|
|
509
|
+
leadingRow: unknown,
|
|
510
|
+
trailingRow: unknown,
|
|
511
|
+
): IVListSeparatorContext<ItemT> {
|
|
512
|
+
const isHighlighted = highlighted === true;
|
|
513
|
+
return {
|
|
514
|
+
$implicit: isHighlighted,
|
|
515
|
+
highlighted: isHighlighted,
|
|
516
|
+
leadingItem: isRow<ItemT>(leadingRow) ? lastItemOfRow(leadingRow) : undefined,
|
|
517
|
+
trailingItem: isRow<ItemT>(trailingRow) ? firstItemOfRow(trailingRow) : undefined,
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
// Single-column separator context: leadingItem/trailingItem are already real items (no row
|
|
522
|
+
// wrapper to narrow through — see the asItem boundary comment above).
|
|
523
|
+
itemSeparatorContext(
|
|
524
|
+
highlighted: unknown,
|
|
525
|
+
leadingItem: unknown,
|
|
526
|
+
trailingItem: unknown,
|
|
527
|
+
): IVListSeparatorContext<ItemT> {
|
|
528
|
+
const isHighlighted = highlighted === true;
|
|
529
|
+
return {
|
|
530
|
+
$implicit: isHighlighted,
|
|
531
|
+
highlighted: isHighlighted,
|
|
532
|
+
leadingItem: asItem<ItemT>(leadingItem),
|
|
533
|
+
trailingItem: asItem<ItemT>(trailingItem),
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
// ---- imperative handle (RN FlatList surface) — delegates to the inner VirtualizedList ----
|
|
538
|
+
|
|
539
|
+
scrollToOffset(params: { offset: number; animated?: boolean }): void {
|
|
540
|
+
this.listRef?.scrollToOffset(params);
|
|
541
|
+
}
|
|
542
|
+
scrollToIndex(params: {
|
|
543
|
+
index: number;
|
|
544
|
+
animated?: boolean;
|
|
545
|
+
viewOffset?: number;
|
|
546
|
+
viewPosition?: number;
|
|
547
|
+
}): void {
|
|
548
|
+
this.listRef?.scrollToIndex(params);
|
|
549
|
+
}
|
|
550
|
+
scrollToItem(params: { item: unknown; animated?: boolean; viewPosition?: number }): void {
|
|
551
|
+
this.listRef?.scrollToItem(params);
|
|
552
|
+
}
|
|
553
|
+
scrollToEnd(params?: { animated?: boolean }): void {
|
|
554
|
+
this.listRef?.scrollToEnd(params);
|
|
555
|
+
}
|
|
556
|
+
flashScrollIndicators(): void {
|
|
557
|
+
this.listRef?.flashScrollIndicators();
|
|
558
|
+
}
|
|
559
|
+
getNativeScrollRef(): IScrollViewHandle | null {
|
|
560
|
+
return this.listRef?.getNativeScrollRef() ?? null;
|
|
561
|
+
}
|
|
562
|
+
getScrollableNode(): IScrollViewHandle | null {
|
|
563
|
+
return this.listRef?.getScrollableNode() ?? null;
|
|
564
|
+
}
|
|
565
|
+
getScrollResponder(): IScrollViewHandle | null {
|
|
566
|
+
return this.listRef?.getScrollResponder() ?? null;
|
|
567
|
+
}
|
|
568
|
+
getScrollNode(): ISymbioteNode | null {
|
|
569
|
+
return this.listRef?.getScrollNode() ?? null;
|
|
570
|
+
}
|
|
571
|
+
recordInteraction(): void {
|
|
572
|
+
this.listRef?.recordInteraction();
|
|
573
|
+
}
|
|
574
|
+
}
|