Skip to content
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
36 changes: 36 additions & 0 deletions apps/automated/src/ui/list-view/list-view-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,42 @@ export class ListViewTest extends UITest<ListView> {
}
}

public test_stickyHeader_Android_padding_after_garbage_collection() {
if (!isAndroid) {
return;
}

this.setUp();

const listView = this.testView;
listView.sectioned = true;
listView.stickyHeader = true;
listView.stickyHeaderTemplate = "<Label id='headerLabel' text='{{ title }}' />";
listView.items = [
{ title: 'First', items: ['a', 'b', 'c'] },
{ title: 'Second', items: ['d', 'e'] },
];

this.waitUntilTestElementIsLoaded();
this.waitUntilTestElementLayoutIsValid();
TKUnit.waitUntilReady(() => !!(<any>listView)._stickyHeaderView);

const header = <android.view.View>(<any>listView)._stickyHeaderView.nativeViewProtected;
const nativeListView = <android.widget.ListView>listView.android;

// Registers a new layout listener, which has to survive the collections before it runs.
(<any>listView)._addListViewPadding();
for (let i = 0; i < 3; i++) {
Utils.GC();
java.lang.System.gc();
java.lang.System.runFinalization();
TKUnit.wait(0.05);
}
header.requestLayout();

TKUnit.waitUntilReady(() => nativeListView.getPaddingTop() === header.getMeasuredHeight() + 4);
}

private checkItemVisibleAtIndex(listView: ListView, index: number): boolean {
return listView.isItemAtIndexVisible(index);
}
Expand Down
23 changes: 16 additions & 7 deletions packages/core/ui/list-view/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,25 +460,34 @@ export class ListView extends ListViewBase {
// Then measure and adjust padding if needed using a layout listener for determinism
const stickyHeaderNativeView = this._stickyHeaderView && this._stickyHeaderView.nativeViewProtected;
if (stickyHeaderNativeView) {
// The listener reaches neither itself nor the list view strongly: the header's
// native view holds it, and both would be cycles through that native view.
const owner = new WeakRef<ListView>(this);
const layoutListener = new android.view.View.OnLayoutChangeListener({
onLayoutChange: (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) => {
onLayoutChange(v: android.view.View, left: number, top: number, right: number, bottom: number, oldLeft: number, oldTop: number, oldRight: number, oldBottom: number) {
const listView = owner.deref();
if (!listView) {
v.removeOnLayoutChangeListener(this);

return;
}
if (v.getMeasuredHeight() > 0) {
const measuredHeaderHeight = v.getMeasuredHeight();
let finalSearchHeight = searchViewHeight;
// Re-measure search view if needed
if (this.showSearch && this._searchView && (this._searchView as any)._wrapper) {
const searchWrapper = (this._searchView as any)._wrapper;
if (listView.showSearch && listView._searchView && (listView._searchView as any)._wrapper) {
const searchWrapper = (listView._searchView as any)._wrapper;
if (searchWrapper.nativeViewProtected && searchWrapper.nativeViewProtected.getMeasuredHeight() > 0) {
finalSearchHeight = searchWrapper.nativeViewProtected.getMeasuredHeight();
}
}
// Calculate final padding: search height + sticky header height + small buffer
const totalPaddingHeight = finalSearchHeight + measuredHeaderHeight + 4;
this._stickyHeaderHeight = measuredHeaderHeight;
this.nativeViewProtected.setPadding(0, totalPaddingHeight, 0, 0);
this.scrollToIndex(0);
listView._stickyHeaderHeight = measuredHeaderHeight;
listView.nativeViewProtected.setPadding(0, totalPaddingHeight, 0, 0);
listView.scrollToIndex(0);
// Remove the listener after first valid layout
v.removeOnLayoutChangeListener(layoutListener);
v.removeOnLayoutChangeListener(this);
}
},
});
Expand Down
Loading