mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
chore: cleanup
This commit is contained in:
@@ -370,9 +370,9 @@ export class ListViewTest extends UITest<ListView> {
|
|||||||
|
|
||||||
public test_loadMoreItems_raised_when_showing_few_items() {
|
public test_loadMoreItems_raised_when_showing_few_items() {
|
||||||
this.setUp();
|
this.setUp();
|
||||||
var listView = this.testView;
|
const listView = this.testView;
|
||||||
|
|
||||||
var loadMoreItemsCount = 0;
|
let loadMoreItemsCount = 0;
|
||||||
listView.items = FEW_ITEMS;
|
listView.items = FEW_ITEMS;
|
||||||
listView.on(ListView.itemLoadingEvent, this.loadViewWithItemNumber);
|
listView.on(ListView.itemLoadingEvent, this.loadViewWithItemNumber);
|
||||||
// >> article-loadmoreitems-event
|
// >> article-loadmoreitems-event
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" actionBarHidden="false">
|
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" actionBarHidden="false" androidOverflowEdge="bottom">
|
||||||
<Page.actionBar>
|
<Page.actionBar>
|
||||||
<ActionBar>
|
<ActionBar>
|
||||||
<Label text="Components" class="header"/>
|
<Label text="Components" class="header"/>
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import { StackLayout } from '../layouts/stack-layout';
|
|||||||
import { ProxyViewContainer } from '../proxy-view-container';
|
import { ProxyViewContainer } from '../proxy-view-container';
|
||||||
import { LayoutBase } from '../layouts/layout-base';
|
import { LayoutBase } from '../layouts/layout-base';
|
||||||
import { profile } from '../../profiling';
|
import { profile } from '../../profiling';
|
||||||
|
import { Trace } from '../../trace';
|
||||||
import { Builder } from '../builder';
|
import { Builder } from '../builder';
|
||||||
import { Template } from '../core/view';
|
|
||||||
import { Label } from '../label';
|
import { Label } from '../label';
|
||||||
|
|
||||||
export * from './list-view-common';
|
export * from './list-view-common';
|
||||||
@@ -19,6 +19,8 @@ const ITEMLOADING = ListViewBase.itemLoadingEvent;
|
|||||||
const LOADMOREITEMS = ListViewBase.loadMoreItemsEvent;
|
const LOADMOREITEMS = ListViewBase.loadMoreItemsEvent;
|
||||||
const ITEMTAP = ListViewBase.itemTapEvent;
|
const ITEMTAP = ListViewBase.itemTapEvent;
|
||||||
const SEARCHCHANGE = ListViewBase.searchChangeEvent;
|
const SEARCHCHANGE = ListViewBase.searchChangeEvent;
|
||||||
|
const STICKY_HEADER_Z_INDEX = 1000;
|
||||||
|
const SEARCH_VIEW_Z_INDEX = 2000;
|
||||||
|
|
||||||
// View type constants for sectioned lists
|
// View type constants for sectioned lists
|
||||||
const ITEM_VIEW_TYPE = 0;
|
const ITEM_VIEW_TYPE = 0;
|
||||||
@@ -248,7 +250,9 @@ export class ListView extends ListViewBase {
|
|||||||
try {
|
try {
|
||||||
adapter.notifyDataSetChanged();
|
adapter.notifyDataSetChanged();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('Error refreshing adapter, recreating:', error);
|
if (Trace.isEnabled()) {
|
||||||
|
Trace.error('Error refreshing adapter, recreating: ' + error);
|
||||||
|
}
|
||||||
nativeView.setAdapter(new ListViewAdapterClass(this));
|
nativeView.setAdapter(new ListViewAdapterClass(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -401,7 +405,7 @@ export class ListView extends ListViewBase {
|
|||||||
|
|
||||||
// Position sticky header with proper offset using native positioning
|
// Position sticky header with proper offset using native positioning
|
||||||
if (this._stickyHeaderView.nativeViewProtected) {
|
if (this._stickyHeaderView.nativeViewProtected) {
|
||||||
this._stickyHeaderView.nativeViewProtected.setZ(1000);
|
this._stickyHeaderView.nativeViewProtected.setZ(STICKY_HEADER_Z_INDEX);
|
||||||
|
|
||||||
// Use a timeout to ensure search view is measured first
|
// Use a timeout to ensure search view is measured first
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -421,7 +425,7 @@ export class ListView extends ListViewBase {
|
|||||||
} else {
|
} else {
|
||||||
// No search view - position at top
|
// No search view - position at top
|
||||||
if (this._stickyHeaderView.nativeViewProtected) {
|
if (this._stickyHeaderView.nativeViewProtected) {
|
||||||
this._stickyHeaderView.nativeViewProtected.setZ(1000);
|
this._stickyHeaderView.nativeViewProtected.setZ(STICKY_HEADER_Z_INDEX);
|
||||||
this._stickyHeaderView.nativeViewProtected.setTranslationY(0);
|
this._stickyHeaderView.nativeViewProtected.setTranslationY(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -452,32 +456,33 @@ export class ListView extends ListViewBase {
|
|||||||
// Request layout to ensure proper measurement
|
// Request layout to ensure proper measurement
|
||||||
this._stickyHeaderView.requestLayout();
|
this._stickyHeaderView.requestLayout();
|
||||||
|
|
||||||
// Then measure and adjust padding if needed
|
// Then measure and adjust padding if needed using a layout listener for determinism
|
||||||
setTimeout(() => {
|
const stickyHeaderNativeView = this._stickyHeaderView && this._stickyHeaderView.nativeViewProtected;
|
||||||
if (this._stickyHeaderView) {
|
if (stickyHeaderNativeView) {
|
||||||
// Get the actual measured height from the native view
|
const layoutListener = new android.view.View.OnLayoutChangeListener({
|
||||||
const nativeView = this._stickyHeaderView.nativeViewProtected;
|
onLayoutChange: (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) => {
|
||||||
if (nativeView && nativeView.getMeasuredHeight() > 0) {
|
if (v.getMeasuredHeight() > 0) {
|
||||||
const measuredHeaderHeight = nativeView.getMeasuredHeight();
|
const measuredHeaderHeight = v.getMeasuredHeight();
|
||||||
let finalSearchHeight = searchViewHeight;
|
let finalSearchHeight = searchViewHeight;
|
||||||
|
// Re-measure search view if needed
|
||||||
// Re-measure search view if needed
|
if (this.showSearch && this._searchView && (this._searchView as any)._wrapper) {
|
||||||
if (this.showSearch && this._searchView && (this._searchView as any)._wrapper) {
|
const searchWrapper = (this._searchView as any)._wrapper;
|
||||||
const searchWrapper = (this._searchView as any)._wrapper;
|
if (searchWrapper.nativeViewProtected && searchWrapper.nativeViewProtected.getMeasuredHeight() > 0) {
|
||||||
if (searchWrapper.nativeViewProtected && searchWrapper.nativeViewProtected.getMeasuredHeight() > 0) {
|
finalSearchHeight = searchWrapper.nativeViewProtected.getMeasuredHeight();
|
||||||
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);
|
||||||
|
// Remove the listener after first valid layout
|
||||||
|
v.removeOnLayoutChangeListener(layoutListener);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
// Calculate final padding: search height + sticky header height + small buffer
|
});
|
||||||
const totalPaddingHeight = finalSearchHeight + measuredHeaderHeight + 4;
|
stickyHeaderNativeView.addOnLayoutChangeListener(layoutListener);
|
||||||
this._stickyHeaderHeight = measuredHeaderHeight;
|
}
|
||||||
this.nativeViewProtected.setPadding(0, totalPaddingHeight, 0, 0);
|
|
||||||
|
|
||||||
this.scrollToIndex(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 150); // Slightly longer delay for more reliable measurement after positioning
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _setupScrollListener() {
|
private _setupScrollListener() {
|
||||||
@@ -754,7 +759,7 @@ export class ListView extends ListViewBase {
|
|||||||
|
|
||||||
// Ensure search view appears above everything else
|
// Ensure search view appears above everything else
|
||||||
if (searchViewWrapper.nativeViewProtected) {
|
if (searchViewWrapper.nativeViewProtected) {
|
||||||
searchViewWrapper.nativeViewProtected.setZ(2000); // Higher than sticky header (1000)
|
searchViewWrapper.nativeViewProtected.setZ(SEARCH_VIEW_Z_INDEX);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store reference for cleanup
|
// Store reference for cleanup
|
||||||
|
|||||||
Reference in New Issue
Block a user