Skip to content

feat(ios-list-view): introduce iosEstimatedRowHeight property. #5568

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

Merged
merged 2 commits into from
Mar 22, 2018
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
10 changes: 10 additions & 0 deletions apps/app/ui-tests-app/list-view/scrolling-and-sizing.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,15 @@
</ListView>
</StackLayout>

<StackLayout class="p-10" row="3">
<Label text="ios-estimated-row-height" class="body m-b-10" />
<ListView items="{{ $value }}" iosEstimatedRowHeight="0">
<ListView.itemTemplate>
<Label text="{{ $value }}" />
</ListView.itemTemplate>
</ListView>
<Label text="after-auto-estimated-height" class="body m-b-10" />
</StackLayout>

</StackLayout>
</Page>
6 changes: 6 additions & 0 deletions tns-core-modules/ui/list-view/list-view-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export abstract class ListViewBase extends View implements ListViewDefinition {
public _itemTemplatesInternal = new Array<KeyedTemplate>(this._defaultTemplate);
public _effectiveRowHeight: number = autoEffectiveRowHeight;
public rowHeight: Length;
public iosEstimatedRowHeight: Length;
public items: any[] | ItemsSource;
public itemTemplate: string | Template;
public itemTemplates: string | Array<KeyedTemplate>;
Expand Down Expand Up @@ -206,5 +207,10 @@ export const rowHeightProperty = new CoercibleProperty<ListViewBase, Length>({
});
rowHeightProperty.register(ListViewBase);

export const iosEstimatedRowHeightProperty = new Property<ListViewBase, Length>({
name: "iosEstimatedRowHeight", valueConverter: (v) => Length.parse(v)
});
iosEstimatedRowHeightProperty.register(ListViewBase);

export const separatorColorProperty = new CssProperty<Style, Color>({ name: "separatorColor", cssName: "separator-color", equalityComparer: Color.equals, valueConverter: (v) => new Color(v) });
separatorColorProperty.register(Style);
11 changes: 11 additions & 0 deletions tns-core-modules/ui/list-view/list-view.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ export class ListView extends View {
*/
rowHeight: Length;

/**
* Gets or set the estimated height of rows in the ListView.
* The default value is 44px.
*/
iosEstimatedRowHeight: Length;

/**
* Forces the ListView to reload all its items.
*/
Expand Down Expand Up @@ -173,6 +179,11 @@ export const separatorColor: Property<ListView, Color>;
*/
export const rowHeightProperty: Property<ListView, Length>;

/**
* Represents the observable property backing the iosEstimatedRowHeight property of each ListView instance.
*/
export const iosEstimatedRowHeightProperty: Property<ListView, Length>;

/**
* Backing property for separator color property.
*/
Expand Down
19 changes: 14 additions & 5 deletions tns-core-modules/ui/list-view/list-view.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { ItemEventData } from ".";
import {
ListViewBase, View, KeyedTemplate, Length, Observable, Color,
separatorColorProperty, itemTemplatesProperty, layout, EventData
separatorColorProperty, itemTemplatesProperty, iosEstimatedRowHeightProperty, layout, EventData
} from "./list-view-common";
import { StackLayout } from "../layouts/stack-layout";
import { ProxyViewContainer } from "../proxy-view-container";
Expand Down Expand Up @@ -138,7 +138,7 @@ class UITableViewDelegateImpl extends NSObject implements UITableViewDelegate {
public tableViewHeightForRowAtIndexPath(tableView: UITableView, indexPath: NSIndexPath): number {
const owner = this._owner.get();
if (!owner) {
return DEFAULT_HEIGHT;
return tableView.estimatedRowHeight;
}

let height: number;
Expand Down Expand Up @@ -188,7 +188,7 @@ class UITableViewRowHeightDelegateImpl extends NSObject implements UITableViewDe
}
return indexPath;
}

public tableViewDidSelectRowAtIndexPath(tableView: UITableView, indexPath: NSIndexPath): NSIndexPath {
tableView.deselectRowAtIndexPathAnimated(indexPath, true);

Expand All @@ -198,7 +198,7 @@ class UITableViewRowHeightDelegateImpl extends NSObject implements UITableViewDe
public tableViewHeightForRowAtIndexPath(tableView: UITableView, indexPath: NSIndexPath): number {
let owner = this._owner.get();
if (!owner) {
return DEFAULT_HEIGHT;
return tableView.estimatedRowHeight;
}

return owner._effectiveRowHeight;
Expand Down Expand Up @@ -340,7 +340,7 @@ export class ListView extends ListViewBase {
return height;
}

return DEFAULT_HEIGHT;
return this._ios.estimatedRowHeight;
}

public _prepareCell(cell: ListViewCell, indexPath: NSIndexPath): number {
Expand Down Expand Up @@ -423,4 +423,13 @@ export class ListView extends ListViewBase {

this.refresh();
}

[iosEstimatedRowHeightProperty.getDefault](): Length {
return DEFAULT_HEIGHT;
}
[iosEstimatedRowHeightProperty.setNative](value: Length) {
const nativeView = this._ios;
const estimatedHeight = Length.toDevicePixels(value, 0);
nativeView.estimatedRowHeight = estimatedHeight < 0 ? DEFAULT_HEIGHT : estimatedHeight;
}
}