@nstudio/ui-collectionview 4.0.70
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 +201 -0
- package/README.md +396 -0
- package/angular/collectionview.component.d.ts +82 -0
- package/angular/esm2020/collectionview.component.mjs +394 -0
- package/angular/esm2020/index.mjs +19 -0
- package/angular/esm2020/nstudio-ui-collectionview-angular.mjs +5 -0
- package/angular/fesm2015/nstudio-ui-collectionview-angular.mjs +421 -0
- package/angular/fesm2015/nstudio-ui-collectionview-angular.mjs.map +1 -0
- package/angular/fesm2020/nstudio-ui-collectionview-angular.mjs +416 -0
- package/angular/fesm2020/nstudio-ui-collectionview-angular.mjs.map +1 -0
- package/angular/index.d.ts +8 -0
- package/angular/package.json +26 -0
- package/common.d.ts +191 -0
- package/common.js +610 -0
- package/common.js.map +1 -0
- package/index.android.d.ts +117 -0
- package/index.android.js +1097 -0
- package/index.android.js.map +1 -0
- package/index.d.ts +16 -0
- package/index.ios.d.ts +118 -0
- package/index.ios.js +1123 -0
- package/index.ios.js.map +1 -0
- package/package.json +57 -0
- package/platforms/android/AndroidManifest.xml +3 -0
- package/platforms/android/include.gradle +7 -0
- package/platforms/android/java/com/nativescript/collectionview/Adapter.java +66 -0
- package/platforms/android/java/com/nativescript/collectionview/AdapterInterface.java +19 -0
- package/platforms/android/java/com/nativescript/collectionview/CollectionViewCellHolder.java +12 -0
- package/platforms/android/java/com/nativescript/collectionview/GridLayoutManager.java +72 -0
- package/platforms/android/java/com/nativescript/collectionview/OnScrollListener.java +35 -0
- package/platforms/android/java/com/nativescript/collectionview/PreCachingGridLayoutManager.java +51 -0
- package/platforms/android/java/com/nativescript/collectionview/RecycledViewPool.java +85 -0
- package/platforms/android/java/com/nativescript/collectionview/RecyclerView.java +46 -0
- package/platforms/android/java/com/nativescript/collectionview/SizeChangedListener.java +6 -0
- package/platforms/android/java/com/nativescript/collectionview/SpanSizeLookup.java +26 -0
- package/platforms/android/native-api-usage.json +29 -0
- package/platforms/android/res/layout/collectionview.xml +5 -0
- package/platforms/android/ui_collectionview.aar +0 -0
- package/react/index.d.ts +119 -0
- package/react/index.js +148 -0
- package/react/index.js.map +1 -0
- package/svelte/index.d.ts +21 -0
- package/svelte/index.js +143 -0
- package/svelte/index.js.map +1 -0
- package/vue/component.d.ts +38 -0
- package/vue/component.js +104 -0
- package/vue/component.js.map +1 -0
- package/vue/index.d.ts +4 -0
- package/vue/index.js +12 -0
- package/vue/index.js.map +1 -0
package/react/index.d.ts
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
import * as React from 'react';
|
2
|
+
import { CoreTypes, ItemEventData, ItemsSource, View } from '@nativescript/core';
|
3
|
+
import { NSVElement, NativeScriptProps, ViewAttributes } from 'react-nativescript';
|
4
|
+
import { CollectionView as NativeScriptCollectionView } from '..';
|
5
|
+
export declare type CellViewContainer = View;
|
6
|
+
declare type CellFactory = (item: any) => React.ReactElement;
|
7
|
+
export declare function registerCollectionView(): void;
|
8
|
+
interface CollectionViewAttributes extends ViewAttributes {
|
9
|
+
colWidth?: CoreTypes.PercentLengthType | string;
|
10
|
+
horizontalSpacing?: CoreTypes.LengthType | string;
|
11
|
+
isBounceEnabled?: boolean;
|
12
|
+
isItemsSourceIn?: boolean;
|
13
|
+
isScrollEnabled?: boolean;
|
14
|
+
itemViewLoader?: any;
|
15
|
+
items?: any[] | ItemsSource;
|
16
|
+
itemTemplateSelector?: string | ((item: any, index: number, items: any) => string);
|
17
|
+
layoutStyle?: string;
|
18
|
+
loadMoreThreshold?: number;
|
19
|
+
onItemsChangedInternal?: (oldValue: any, newValue: any) => void;
|
20
|
+
onItemLoading?: (args: ItemEventData) => void;
|
21
|
+
onSpanSizeChangedInternal?: (oldValue: any, newValue: any) => void;
|
22
|
+
orientation?: 'horizontal' | 'vertical';
|
23
|
+
plugins?: string[];
|
24
|
+
reverseLayout?: boolean;
|
25
|
+
rowHeight?: CoreTypes.PercentLengthType | string;
|
26
|
+
spanSize?: (item: any, index: number) => number;
|
27
|
+
verticalSpacing?: CoreTypes.LengthType | string;
|
28
|
+
}
|
29
|
+
declare global {
|
30
|
+
namespace JSX {
|
31
|
+
interface IntrinsicElements {
|
32
|
+
collectionView: NativeScriptProps<CollectionViewAttributes, NativeScriptCollectionView>;
|
33
|
+
}
|
34
|
+
}
|
35
|
+
}
|
36
|
+
declare type OwnProps = {
|
37
|
+
items: ItemsSource | any[];
|
38
|
+
/** User may specify cellFactory for single-template or cellFactories for multi-template. */
|
39
|
+
cellFactory?: CellFactory;
|
40
|
+
cellFactories?: Map<string, {
|
41
|
+
placeholderItem: any;
|
42
|
+
cellFactory: CellFactory;
|
43
|
+
}>;
|
44
|
+
/** For now, we don't support custom onItemLoading event handlers. */
|
45
|
+
/**
|
46
|
+
* The event will be raised when the CollectionView is scrolled so that the last item is visible.
|
47
|
+
* This event is intended to be used to add additional data in the CollectionView.
|
48
|
+
*/
|
49
|
+
_debug?: {
|
50
|
+
logLevel: 'debug' | 'info';
|
51
|
+
onCellFirstLoad?: (container: CellViewContainer) => void;
|
52
|
+
onCellRecycle?: (container: CellViewContainer) => void;
|
53
|
+
};
|
54
|
+
} & Omit<CollectionViewAttributes, 'onItemLoading'>;
|
55
|
+
declare type Props = OwnProps & {
|
56
|
+
forwardedRef?: React.RefObject<NSVElement<NativeScriptCollectionView>>;
|
57
|
+
};
|
58
|
+
declare type NumberKey = number | string;
|
59
|
+
interface State {
|
60
|
+
nativeCells: Record<NumberKey, CellViewContainer>;
|
61
|
+
nativeCellToItemIndex: Map<CellViewContainer, NumberKey>;
|
62
|
+
itemIndexToNativeCell?: Map<NumberKey, CellViewContainer>;
|
63
|
+
}
|
64
|
+
/**
|
65
|
+
* A React wrapper around the NativeScript CollectionView component.
|
66
|
+
* @see https://docs.nativescript.org/ui/ns-ui-widgets/list-view
|
67
|
+
* @module ui/list-view/list-view
|
68
|
+
*/
|
69
|
+
export declare class _CollectionView extends React.Component<Props, State> {
|
70
|
+
static readonly defaultProps: {
|
71
|
+
_debug: {
|
72
|
+
logLevel: "info";
|
73
|
+
onCellFirstLoad: any;
|
74
|
+
onCellRecycle: any;
|
75
|
+
};
|
76
|
+
};
|
77
|
+
constructor(props: Props);
|
78
|
+
private readonly myRef;
|
79
|
+
private readonly argsViewToRootKeyAndRef;
|
80
|
+
private roots;
|
81
|
+
/**
|
82
|
+
* CollectionView code-behind:
|
83
|
+
* @see https://github.com/NativeScript/nativescript-sdk-examples-js/blob/master/app/ns-ui-widgets-category/list-view/code-behind/code-behind-ts-page.ts
|
84
|
+
* CollectionView item templates:
|
85
|
+
* @see https://medium.com/@alexander.vakrilov/faster-nativescript-CollectionView-with-multiple-item-templates-8f903a32e48f
|
86
|
+
* Cell state in CollectionView:
|
87
|
+
* @see https://medium.com/@alexander.vakrilov/managing-component-state-in-nativescript-CollectionView-b139e45d899b
|
88
|
+
* @see https://github.com/NativeScript/nativescript-angular/issues/1245#issuecomment-393465035
|
89
|
+
* loadMoreItems:
|
90
|
+
* @see https://github.com/NativeScript/nativescript-sdk-examples-js/blob/master/app/ns-ui-widgets-category/list-view/events/events-ts-page.ts
|
91
|
+
*/
|
92
|
+
private readonly defaultOnItemLoading;
|
93
|
+
protected getNativeView(): NativeScriptCollectionView | null;
|
94
|
+
private readonly renderNewRoot;
|
95
|
+
componentDidMount(): void;
|
96
|
+
componentWillUnmount(): void;
|
97
|
+
static isItemsSource(arr: any[] | ItemsSource): arr is ItemsSource;
|
98
|
+
render(): JSX.Element;
|
99
|
+
}
|
100
|
+
export declare const CollectionView: React.ForwardRefExoticComponent<{
|
101
|
+
items: ItemsSource | any[];
|
102
|
+
/** User may specify cellFactory for single-template or cellFactories for multi-template. */
|
103
|
+
cellFactory?: CellFactory;
|
104
|
+
cellFactories?: Map<string, {
|
105
|
+
placeholderItem: any;
|
106
|
+
cellFactory: CellFactory;
|
107
|
+
}>;
|
108
|
+
/** For now, we don't support custom onItemLoading event handlers. */
|
109
|
+
/**
|
110
|
+
* The event will be raised when the CollectionView is scrolled so that the last item is visible.
|
111
|
+
* This event is intended to be used to add additional data in the CollectionView.
|
112
|
+
*/
|
113
|
+
_debug?: {
|
114
|
+
logLevel: 'debug' | 'info';
|
115
|
+
onCellFirstLoad?: (container: CellViewContainer) => void;
|
116
|
+
onCellRecycle?: (container: CellViewContainer) => void;
|
117
|
+
};
|
118
|
+
} & Omit<CollectionViewAttributes, "onItemLoading"> & React.RefAttributes<NSVElement<NativeScriptCollectionView>>>;
|
119
|
+
export {};
|
package/react/index.js
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
import * as React from 'react';
|
2
|
+
import { NSVRoot, render as RNSRender, registerElement, unmountComponentAtNode } from 'react-nativescript';
|
3
|
+
export function registerCollectionView() {
|
4
|
+
registerElement('collectionView', () => require('..').CollectionView);
|
5
|
+
}
|
6
|
+
/**
|
7
|
+
* A React wrapper around the NativeScript CollectionView component.
|
8
|
+
* @see https://docs.nativescript.org/ui/ns-ui-widgets/list-view
|
9
|
+
* @module ui/list-view/list-view
|
10
|
+
*/
|
11
|
+
export class _CollectionView extends React.Component {
|
12
|
+
constructor(props) {
|
13
|
+
super(props);
|
14
|
+
this.myRef = React.createRef();
|
15
|
+
this.argsViewToRootKeyAndRef = new Map();
|
16
|
+
this.roots = new Set();
|
17
|
+
/**
|
18
|
+
* CollectionView code-behind:
|
19
|
+
* @see https://github.com/NativeScript/nativescript-sdk-examples-js/blob/master/app/ns-ui-widgets-category/list-view/code-behind/code-behind-ts-page.ts
|
20
|
+
* CollectionView item templates:
|
21
|
+
* @see https://medium.com/@alexander.vakrilov/faster-nativescript-CollectionView-with-multiple-item-templates-8f903a32e48f
|
22
|
+
* Cell state in CollectionView:
|
23
|
+
* @see https://medium.com/@alexander.vakrilov/managing-component-state-in-nativescript-CollectionView-b139e45d899b
|
24
|
+
* @see https://github.com/NativeScript/nativescript-angular/issues/1245#issuecomment-393465035
|
25
|
+
* loadMoreItems:
|
26
|
+
* @see https://github.com/NativeScript/nativescript-sdk-examples-js/blob/master/app/ns-ui-widgets-category/list-view/events/events-ts-page.ts
|
27
|
+
*/
|
28
|
+
this.defaultOnItemLoading = (args) => {
|
29
|
+
const { logLevel, onCellRecycle, onCellFirstLoad } = this.props._debug;
|
30
|
+
const { items, itemTemplateSelector } = this.props;
|
31
|
+
const item = _CollectionView.isItemsSource(items) ? items.getItem(args.index) : items[args.index];
|
32
|
+
const template = itemTemplateSelector
|
33
|
+
? typeof itemTemplateSelector === 'string'
|
34
|
+
? itemTemplateSelector
|
35
|
+
: itemTemplateSelector(item, args.index, items)
|
36
|
+
: null;
|
37
|
+
const cellFactory = template === null ? this.props.cellFactory : this.props.cellFactories ? this.props.cellFactories.get(template).cellFactory : this.props.cellFactory;
|
38
|
+
if (typeof cellFactory === 'undefined') {
|
39
|
+
console.warn(`CollectionView: No cell factory found, given template ${template}!`);
|
40
|
+
return;
|
41
|
+
}
|
42
|
+
const view = args.view;
|
43
|
+
if (!view) {
|
44
|
+
const rootKeyAndRef = this.renderNewRoot(item, cellFactory);
|
45
|
+
args.view = rootKeyAndRef.nativeView;
|
46
|
+
/* Here we're re-using the ref - I assume this is best practice. If not, we can make a new one on each update instead. */
|
47
|
+
this.argsViewToRootKeyAndRef.set(args.view, rootKeyAndRef);
|
48
|
+
if (onCellFirstLoad)
|
49
|
+
onCellFirstLoad(rootKeyAndRef.nativeView);
|
50
|
+
}
|
51
|
+
else {
|
52
|
+
if (onCellRecycle)
|
53
|
+
onCellRecycle(view);
|
54
|
+
const { rootKey, nativeView } = this.argsViewToRootKeyAndRef.get(view);
|
55
|
+
if (typeof rootKey === 'undefined') {
|
56
|
+
console.error('Unable to find root key that args.view corresponds to!', view);
|
57
|
+
return;
|
58
|
+
}
|
59
|
+
if (!nativeView) {
|
60
|
+
console.error('Unable to find ref that args.view corresponds to!', view);
|
61
|
+
return;
|
62
|
+
}
|
63
|
+
// args.view = null;
|
64
|
+
RNSRender(cellFactory(item), null, () => {
|
65
|
+
// console.log(`Rendered into cell! detachedRootRef:`);
|
66
|
+
}, rootKey);
|
67
|
+
}
|
68
|
+
};
|
69
|
+
this.renderNewRoot = (item, cellFactory) => {
|
70
|
+
const node = this.getNativeView();
|
71
|
+
if (!node) {
|
72
|
+
throw new Error('Unable to get ref to CollectionView');
|
73
|
+
}
|
74
|
+
const rootKey = `CollectionView-${node._domId}-${this.roots.size.toString()}`;
|
75
|
+
const root = new NSVRoot();
|
76
|
+
RNSRender(cellFactory(item), root, () => {
|
77
|
+
// console.log(`Rendered into cell! ref:`);
|
78
|
+
}, rootKey);
|
79
|
+
this.roots.add(rootKey);
|
80
|
+
return {
|
81
|
+
rootKey,
|
82
|
+
nativeView: root.baseRef.nativeView
|
83
|
+
};
|
84
|
+
};
|
85
|
+
this.state = {
|
86
|
+
nativeCells: {},
|
87
|
+
nativeCellToItemIndex: new Map(),
|
88
|
+
itemIndexToNativeCell: props._debug.logLevel === 'debug' ? new Map() : undefined
|
89
|
+
};
|
90
|
+
}
|
91
|
+
getNativeView() {
|
92
|
+
const ref = this.props.forwardedRef || this.myRef;
|
93
|
+
return ref.current ? ref.current.nativeView : null;
|
94
|
+
}
|
95
|
+
componentDidMount() {
|
96
|
+
const node = this.getNativeView();
|
97
|
+
if (!node) {
|
98
|
+
console.warn('React ref to NativeScript View lost, so unable to set item templates.');
|
99
|
+
return;
|
100
|
+
}
|
101
|
+
/* NOTE: does not support updating of this.props.cellFactories upon Props update. */
|
102
|
+
if (this.props.cellFactories) {
|
103
|
+
const itemTemplates = [];
|
104
|
+
this.props.cellFactories.forEach((info, key) => {
|
105
|
+
const { placeholderItem, cellFactory } = info;
|
106
|
+
itemTemplates.push({
|
107
|
+
key,
|
108
|
+
createView: () => {
|
109
|
+
const rootKeyAndRef = this.renderNewRoot(placeholderItem, cellFactory);
|
110
|
+
this.argsViewToRootKeyAndRef.set(rootKeyAndRef.nativeView, rootKeyAndRef);
|
111
|
+
return rootKeyAndRef.nativeView;
|
112
|
+
}
|
113
|
+
});
|
114
|
+
});
|
115
|
+
node.itemTemplates = itemTemplates;
|
116
|
+
}
|
117
|
+
}
|
118
|
+
componentWillUnmount() {
|
119
|
+
this.roots.forEach((root) => unmountComponentAtNode(root));
|
120
|
+
}
|
121
|
+
static isItemsSource(arr) {
|
122
|
+
/**
|
123
|
+
* Same implementation as used in official ListPicker component:
|
124
|
+
* @see https://github.com/NativeScript/NativeScript/blob/b436ecde3605b695a0ffa1757e38cc094e2fe311/tns-core-modules/ui/list-picker/list-picker-common.ts#L74
|
125
|
+
*/
|
126
|
+
return typeof arr.getItem === 'function';
|
127
|
+
}
|
128
|
+
render() {
|
129
|
+
const {
|
130
|
+
// Only used by the class component; not the JSX element.
|
131
|
+
forwardedRef,
|
132
|
+
//@ts-ignore
|
133
|
+
children, _debug, cellFactories, cellFactory, ...rest } = this.props;
|
134
|
+
if (children) {
|
135
|
+
console.warn("Ignoring 'children' prop on CollectionView; not supported.");
|
136
|
+
}
|
137
|
+
return React.createElement("collectionView", { ...rest, onItemLoading: this.defaultOnItemLoading, ref: forwardedRef || this.myRef });
|
138
|
+
}
|
139
|
+
}
|
140
|
+
_CollectionView.defaultProps = {
|
141
|
+
_debug: {
|
142
|
+
logLevel: 'info',
|
143
|
+
onCellFirstLoad: undefined,
|
144
|
+
onCellRecycle: undefined
|
145
|
+
}
|
146
|
+
};
|
147
|
+
export const CollectionView = React.forwardRef((props, ref) => (React.createElement(_CollectionView, { ...props, forwardedRef: ref })));
|
148
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/ui-collectionview/react/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAc,OAAO,EAAqB,MAAM,IAAI,SAAS,EAAkB,eAAe,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAM1J,MAAM,UAAU,sBAAsB;IAClC,eAAe,CAAC,gBAAgB,EAAE,GAAG,EAA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AC3B,MAAM,EAAE;QACJ,QAAQ,EAAE,MAAgB;QAC1B,eAAe,EAAE,SAAS;QAC1B,aAAa,EAAE,SAAS;KAC3B;CACJ,CAAC;AAyKN,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,CAAC,UAAU,CAAmD,CAAC,KAAe,EAAE,GAA4D,EAAE,EAAE,CAAC,CAChL,oBAAC,eAAe,OAAK,KAAK,EAAE,YAAY,EAAE,GAAG,GAAI,CACpD,CAAC,CAAC"}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
/// <reference types="svelte-native" />
|
2
|
+
import { NativeViewElementNode, ViewNode } from 'svelte-native/dom';
|
3
|
+
import { CollectionView } from '..';
|
4
|
+
declare module '@nativescript/core/ui/core/view-base' {
|
5
|
+
interface ViewBase {
|
6
|
+
__SvelteComponent__?: SvelteComponent;
|
7
|
+
__SvelteComponentBuilder__?: any;
|
8
|
+
__CollectionViewCurrentIndex__?: number;
|
9
|
+
}
|
10
|
+
}
|
11
|
+
export default class CollectionViewViewElement extends NativeViewElementNode<CollectionView> {
|
12
|
+
constructor();
|
13
|
+
private loadView;
|
14
|
+
setAttribute(fullkey: string, value: any): void;
|
15
|
+
private getComponentForView;
|
16
|
+
onInsertedChild(childNode: ViewNode, index: number): void;
|
17
|
+
onRemovedChild(childNode: ViewNode): void;
|
18
|
+
private disposeListItem;
|
19
|
+
private updateListItem;
|
20
|
+
static register(): void;
|
21
|
+
}
|
package/svelte/index.js
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
import { ContentView, profile } from '@nativescript/core';
|
2
|
+
import { NativeViewElementNode, TemplateElement, createElement, registerElement } from 'svelte-native/dom';
|
3
|
+
import { flush } from 'svelte/internal';
|
4
|
+
import { CollectionView } from '..';
|
5
|
+
const SVELTE_VIEW = '_svelteViewRef';
|
6
|
+
class SvelteKeyedTemplate {
|
7
|
+
constructor(key, templateEl) {
|
8
|
+
this._key = key;
|
9
|
+
this._templateEl = templateEl;
|
10
|
+
}
|
11
|
+
get component() {
|
12
|
+
return this._templateEl.component;
|
13
|
+
}
|
14
|
+
get key() {
|
15
|
+
return this._key;
|
16
|
+
}
|
17
|
+
createView() {
|
18
|
+
// create a proxy element to eventually contain our item (once we have one to render)
|
19
|
+
// TODO is StackLayout the best choice here?
|
20
|
+
// const wrapper = createElement('StackLayout') as NativeViewElementNode<View>;
|
21
|
+
const nativeEl = new ContentView();
|
22
|
+
// because of the way {N} works we cant use that wrapper as the target for the component
|
23
|
+
// it will trigger uncessary {N} component updates because the parent view is already attached
|
24
|
+
nativeEl.__SvelteComponentBuilder__ = (parentView, props) => {
|
25
|
+
profile('createView.__SvelteComponentBuilder__', () => {
|
26
|
+
nativeEl.__SvelteComponent__ = new this.component({
|
27
|
+
target: parentView,
|
28
|
+
props
|
29
|
+
});
|
30
|
+
})();
|
31
|
+
};
|
32
|
+
return nativeEl;
|
33
|
+
}
|
34
|
+
}
|
35
|
+
export default class CollectionViewViewElement extends NativeViewElementNode {
|
36
|
+
constructor() {
|
37
|
+
super('collectionview', CollectionView);
|
38
|
+
const nativeView = this.nativeView;
|
39
|
+
nativeView.itemViewLoader = (viewType) => this.loadView(viewType);
|
40
|
+
this.nativeView.on(CollectionView.itemLoadingEvent, this.updateListItem, this);
|
41
|
+
this.nativeView.on(CollectionView.itemDisposingEvent, this.disposeListItem, this);
|
42
|
+
}
|
43
|
+
loadView(viewType) {
|
44
|
+
if (Array.isArray(this.nativeElement.itemTemplates)) {
|
45
|
+
const keyedTemplate = this.nativeElement.itemTemplates.find((t) => t.key === 'default');
|
46
|
+
if (keyedTemplate) {
|
47
|
+
return keyedTemplate.createView();
|
48
|
+
}
|
49
|
+
}
|
50
|
+
const componentClass = this.getComponentForView(viewType);
|
51
|
+
if (!componentClass)
|
52
|
+
return null;
|
53
|
+
const nativeEl = new ContentView();
|
54
|
+
const builder = (parentView, props) => {
|
55
|
+
nativeEl.__SvelteComponent__ = new componentClass({
|
56
|
+
target: parentView,
|
57
|
+
props
|
58
|
+
});
|
59
|
+
};
|
60
|
+
// in svelte we want to add the wrapper as a child of the collectionview ourselves
|
61
|
+
nativeEl.__SvelteComponentBuilder__ = builder;
|
62
|
+
return nativeEl;
|
63
|
+
}
|
64
|
+
// For some reason itemTemplateSelector isn't defined as a "property" on radListView, so when we set the property, it is lowercase (due to svelte's forced downcasing)
|
65
|
+
// we intercept and fix the case here.
|
66
|
+
setAttribute(fullkey, value) {
|
67
|
+
if (fullkey.toLowerCase() === 'itemtemplateselector') {
|
68
|
+
fullkey = 'itemTemplateSelector';
|
69
|
+
}
|
70
|
+
super.setAttribute(fullkey, value);
|
71
|
+
}
|
72
|
+
getComponentForView(viewType) {
|
73
|
+
const normalizedViewType = viewType.toLowerCase();
|
74
|
+
const templateEl = this.childNodes.find((n) => n.tagName === 'template' && String(n.getAttribute('type')).toLowerCase() === normalizedViewType);
|
75
|
+
if (!templateEl)
|
76
|
+
return null;
|
77
|
+
return templateEl.component;
|
78
|
+
}
|
79
|
+
onInsertedChild(childNode, index) {
|
80
|
+
super.onInsertedChild(childNode, index);
|
81
|
+
if (childNode instanceof TemplateElement) {
|
82
|
+
const key = childNode.getAttribute('key') || 'default';
|
83
|
+
// const templates = !this.nativeView.itemTemplates || typeof this.nativeView.itemTemplates === 'string' ? [] : (this.nativeView.itemTemplates as any[]);
|
84
|
+
// we need to reassign or the update wont be seen
|
85
|
+
this.nativeView.addTemplate(key, new SvelteKeyedTemplate(key, childNode));
|
86
|
+
// = templates.concat([new SvelteKeyedTemplate(key, childNode)]);
|
87
|
+
}
|
88
|
+
}
|
89
|
+
onRemovedChild(childNode) {
|
90
|
+
super.onRemovedChild(childNode);
|
91
|
+
if (childNode instanceof TemplateElement) {
|
92
|
+
const key = childNode.getAttribute('key') || 'default';
|
93
|
+
this.nativeView.removeTemplate(key);
|
94
|
+
}
|
95
|
+
}
|
96
|
+
disposeListItem(args) {
|
97
|
+
const _view = args.view;
|
98
|
+
if (_view.__SvelteComponent__) {
|
99
|
+
_view.__SvelteComponent__.$destroy();
|
100
|
+
_view.__SvelteComponent__ = null;
|
101
|
+
}
|
102
|
+
}
|
103
|
+
updateListItem(args) {
|
104
|
+
const _view = args.view;
|
105
|
+
const props = { item: args.bindingContext, index: args.index };
|
106
|
+
const componentInstance = _view.__SvelteComponent__;
|
107
|
+
if (!componentInstance) {
|
108
|
+
if (_view.__SvelteComponentBuilder__) {
|
109
|
+
const dummy = createElement('fragment');
|
110
|
+
_view.__SvelteComponentBuilder__(dummy, props);
|
111
|
+
_view.__SvelteComponentBuilder__ = null;
|
112
|
+
_view.__CollectionViewCurrentIndex__ = args.index;
|
113
|
+
const nativeEl = dummy.firstElement().nativeView;
|
114
|
+
_view.content = nativeEl;
|
115
|
+
}
|
116
|
+
}
|
117
|
+
else {
|
118
|
+
// ensure we dont do unnecessary tasks if index did not change
|
119
|
+
// console.log('updateListItem', args.index, _view.__CollectionViewCurrentIndex__);
|
120
|
+
_view.__CollectionViewCurrentIndex__ = args.index;
|
121
|
+
_view._batchUpdate(() => {
|
122
|
+
componentInstance.$set(props);
|
123
|
+
flush(); // we need to flush to make sure update is applied right away
|
124
|
+
});
|
125
|
+
}
|
126
|
+
}
|
127
|
+
static register() {
|
128
|
+
registerElement('collectionview', () => new CollectionViewViewElement());
|
129
|
+
}
|
130
|
+
}
|
131
|
+
__decorate([
|
132
|
+
profile,
|
133
|
+
__metadata("design:type", Function),
|
134
|
+
__metadata("design:paramtypes", [Object]),
|
135
|
+
__metadata("design:returntype", void 0)
|
136
|
+
], CollectionViewViewElement.prototype, "disposeListItem", null);
|
137
|
+
__decorate([
|
138
|
+
profile,
|
139
|
+
__metadata("design:type", Function),
|
140
|
+
__metadata("design:paramtypes", [Object]),
|
141
|
+
__metadata("design:returntype", void 0)
|
142
|
+
], CollectionViewViewElement.prototype, "updateListItem", null);
|
143
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/ui-collectionview/svelte/index.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gEAOP;AACD;IAAC,OAAO;;;;+DAuBP"}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
declare const _default: {
|
2
|
+
props: {
|
3
|
+
items: {
|
4
|
+
validator: (val: any) => boolean;
|
5
|
+
required: boolean;
|
6
|
+
};
|
7
|
+
'+alias': {
|
8
|
+
type: StringConstructor;
|
9
|
+
default: string;
|
10
|
+
};
|
11
|
+
'+index': {
|
12
|
+
type: StringConstructor;
|
13
|
+
};
|
14
|
+
itemTemplateSelector: {
|
15
|
+
type: FunctionConstructor;
|
16
|
+
default: any;
|
17
|
+
};
|
18
|
+
};
|
19
|
+
template: string;
|
20
|
+
watch: {
|
21
|
+
items: {
|
22
|
+
handler(newVal: any, oldVal: any): void;
|
23
|
+
deep: boolean;
|
24
|
+
};
|
25
|
+
};
|
26
|
+
created(): void;
|
27
|
+
mounted(): void;
|
28
|
+
methods: {
|
29
|
+
getItem(index: any): any;
|
30
|
+
onItemTap(args: any): void;
|
31
|
+
updateViewTemplate(args: any): void;
|
32
|
+
onItemLoadingInternal(args: any): void;
|
33
|
+
onItemDisposingInternal(args: any): void;
|
34
|
+
refresh(): void;
|
35
|
+
scrollToIndex(index: any, animate?: boolean): void;
|
36
|
+
};
|
37
|
+
};
|
38
|
+
export default _default;
|
package/vue/component.js
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
import { Observable, ObservableArray } from '@nativescript/core';
|
2
|
+
const VUE_VIEW = '__vueVNodeRef__';
|
3
|
+
export default {
|
4
|
+
props: {
|
5
|
+
items: {
|
6
|
+
validator: (val) => !val || Array.isArray(val) || val instanceof ObservableArray,
|
7
|
+
required: true
|
8
|
+
},
|
9
|
+
'+alias': {
|
10
|
+
type: String,
|
11
|
+
default: 'item'
|
12
|
+
},
|
13
|
+
'+index': {
|
14
|
+
type: String
|
15
|
+
},
|
16
|
+
itemTemplateSelector: {
|
17
|
+
type: Function,
|
18
|
+
default: undefined
|
19
|
+
}
|
20
|
+
},
|
21
|
+
template: `<NativeCollectionView ref="listView" :items="items" v-bind="$attrs" v-on="listeners" @itemTap="onItemTap" @itemLoading="onItemLoadingInternal" @itemDisposing="onItemDisposingInternal"
|
22
|
+
>
|
23
|
+
<slot /></NativeCollectionView>`,
|
24
|
+
watch: {
|
25
|
+
items: {
|
26
|
+
handler(newVal, oldVal) {
|
27
|
+
if (!(oldVal instanceof Observable)) {
|
28
|
+
this.$refs.listView.setAttribute('items', newVal);
|
29
|
+
}
|
30
|
+
},
|
31
|
+
deep: true
|
32
|
+
}
|
33
|
+
},
|
34
|
+
created() {
|
35
|
+
// we need to remove the itemTap handler from a clone of the $listeners
|
36
|
+
// object because we are emitting the event ourselves with added data.
|
37
|
+
const listeners = Object.assign({}, this.$listeners);
|
38
|
+
delete listeners.itemTap;
|
39
|
+
this.listeners = listeners;
|
40
|
+
this.getItemContext = getItemContext.bind(this);
|
41
|
+
},
|
42
|
+
mounted() {
|
43
|
+
const listView = this.$refs.listView;
|
44
|
+
this.listView = listView.nativeView;
|
45
|
+
listView.setAttribute('itemTemplates', this.$templates.getKeyedTemplates());
|
46
|
+
const itemTemplateSelector = this.itemTemplateSelector
|
47
|
+
? this.itemTemplateSelector // custom template selector if any
|
48
|
+
: (item, index, items) => this.$templates.selectorFn(this.getItemContext(item, index));
|
49
|
+
listView.setAttribute('itemTemplateSelector', itemTemplateSelector);
|
50
|
+
},
|
51
|
+
methods: {
|
52
|
+
getItem(index) {
|
53
|
+
return this.listView.getItemAtIndex(index);
|
54
|
+
},
|
55
|
+
onItemTap(args) {
|
56
|
+
this.$emit('itemTap', { item: this.getItem(args.index), ...args });
|
57
|
+
},
|
58
|
+
updateViewTemplate(args) {
|
59
|
+
const listView = args.object;
|
60
|
+
const index = args.index;
|
61
|
+
const items = args.object.items;
|
62
|
+
const currentItem = args.bindingContext;
|
63
|
+
const name = listView._itemTemplateSelector(currentItem, index, items);
|
64
|
+
const context = this.getItemContext(currentItem, index);
|
65
|
+
const oldVnode = args.view && args.view[VUE_VIEW];
|
66
|
+
if (args.view) {
|
67
|
+
args.view._batchUpdate(() => {
|
68
|
+
args.view = this.$templates.patchTemplate(name, context, oldVnode);
|
69
|
+
});
|
70
|
+
}
|
71
|
+
else {
|
72
|
+
args.view = this.$templates.patchTemplate(name, context, oldVnode);
|
73
|
+
}
|
74
|
+
},
|
75
|
+
onItemLoadingInternal(args) {
|
76
|
+
this.updateViewTemplate(args);
|
77
|
+
},
|
78
|
+
onItemDisposingInternal(args) {
|
79
|
+
const oldVnode = args.view && args.view[VUE_VIEW];
|
80
|
+
if (oldVnode && oldVnode.context) {
|
81
|
+
oldVnode.context.$destroy();
|
82
|
+
args.view[VUE_VIEW] = null;
|
83
|
+
}
|
84
|
+
},
|
85
|
+
refresh() {
|
86
|
+
this.listView.refresh();
|
87
|
+
},
|
88
|
+
scrollToIndex(index, animate = false) {
|
89
|
+
this.listView.scrollToIndex(index, animate);
|
90
|
+
}
|
91
|
+
// getSelectedItems() {
|
92
|
+
// return (this.listView as CollectionView).getSelectedItems();
|
93
|
+
// }
|
94
|
+
}
|
95
|
+
};
|
96
|
+
function getItemContext(item, index = -1, alias = this.$props['+alias'], index_alias = this.$props['+index']) {
|
97
|
+
return {
|
98
|
+
[alias]: item,
|
99
|
+
[index_alias || '$index']: index,
|
100
|
+
$even: index % 2 === 0,
|
101
|
+
$odd: index % 2 !== 0
|
102
|
+
};
|
103
|
+
}
|
104
|
+
//# sourceMappingURL=component.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"component.js","sourceRoot":"","sources":["../../../../packages/ui-collectionview/vue/component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGjE,MAAM,QAAQ,GAAG,iBAAiB,CAAC;AACnC,eAAe;IACX,KAAK,EAAE;QACH,KAAK,EAAE;YACH,SAAS,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CA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..';
|
2
|
+
const CollectionViewPlugin = {
|
3
|
+
install(Vue, options) {
|
4
|
+
Vue.registerElement('CollectionView', function () {
|
5
|
+
return CollectionView;
|
6
|
+
}, {
|
7
|
+
component: require('./component').default
|
8
|
+
});
|
9
|
+
}
|
10
|
+
};
|
11
|
+
export default CollectionViewPlugin;
|
12
|
+
//# sourceMappingURL=index.js.map
|
package/vue/index.js.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/ui-collectionview/vue/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,IAAI,CAAC;AAEpC,MAAM,oBAAoB,GAAG;IACzB,OAAO,CAAC,GAAG,EAAE,OAAO;QAChB,GAAG,CAAC,eAAe,CACf,gBAAgB,EAChB;YACI,OAAO,cAAc,CAAC;QAC1B,CAAC,EACD;YACI,SAAS,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC,OAAO;SAC5C,CACJ,CAAC;IACN,CAAC;CACJ,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
|