-
-
Notifications
You must be signed in to change notification settings - Fork 241
[Do Not Merge]fix(list-view): Recycle items for component children #740
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,8 @@ import { ListView } from "tns-core-modules/ui/list-view"; | |
import { View, KeyedTemplate } from "tns-core-modules/ui/core/view"; | ||
import { ObservableArray } from "tns-core-modules/data/observable-array"; | ||
import { LayoutBase } from "tns-core-modules/ui/layouts/layout-base"; | ||
import { StackLayout } from "tns-core-modules/ui/layouts/stack-layout"; | ||
import { ProxyViewContainer } from "tns-core-modules/ui/proxy-view-container"; | ||
import { listViewLog } from "../trace"; | ||
|
||
const NG_VIEW = "_ngViewRef"; | ||
|
@@ -160,6 +162,7 @@ export class ListViewComponent implements DoCheck, OnDestroy, AfterContentInit { | |
|
||
if (args.view && args.view[NG_VIEW]) { | ||
listViewLog("onItemLoading: " + index + " - Reusing existing view"); | ||
console.log("onItemLoading: " + index + " - Reusing existing view"); | ||
viewRef = args.view[NG_VIEW]; | ||
// getting angular view from original element (in cases when ProxyViewContainer | ||
// is used NativeScript internally wraps it in a StackLayout) | ||
|
@@ -169,6 +172,7 @@ export class ListViewComponent implements DoCheck, OnDestroy, AfterContentInit { | |
} | ||
} else { | ||
listViewLog("onItemLoading: " + index + " - Creating view from template"); | ||
console.log("onItemLoading: " + index + " - Creating view from template"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Debug console.log leftover? |
||
viewRef = this.loader.createEmbeddedView(this.itemTemplate, new ListItemContext(), 0); | ||
args.view = getItemViewRoot(viewRef); | ||
args.view[NG_VIEW] = viewRef; | ||
|
@@ -242,7 +246,12 @@ export interface ComponentView { | |
export type RootLocator = (nodes: Array<any>, nestLevel: number) => View; | ||
|
||
export function getItemViewRoot(viewRef: ComponentView, rootLocator: RootLocator = getSingleViewRecursive): View { | ||
const rootView = rootLocator(viewRef.rootNodes, 0); | ||
let rootView = rootLocator(viewRef.rootNodes, -1); | ||
if (rootView instanceof ProxyViewContainer) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think a more borad check should be used: |
||
const wrapperLayout = new StackLayout(); | ||
wrapperLayout.addChild(rootView); | ||
rootView = wrapperLayout; | ||
} | ||
return rootView; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug console.log leftover?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the code that should extract the view ref, event if the root view was "wrapped" in Stack layout