A ListView providing a native AppScrollIndicator, an empty view and swipe gestures for its list delegates. More...
Import Statement: | import Felgo 4.0 |
Inherits: |
AppListView is an extension of the basic QML ListView with functionality for the Felgo AppSDK.
It adds capability for displaying a view when the list is empty, and for using SwipeOptionsContainer as ListView::delegate.
To use predefined components for often used list features, use a PullToRefreshHandler and/or VisibilityRefreshHandler together with the AppListView.
Thus we recommend using AppListView instead of ListView in your whole project.
Note: A default Flickable::bottomMargin equal to the bottom NativeUtils::safeAreaInsets value is applied to account for the translucent system navigation bar on Android and the bottom home gesture area on iOS. This margin is not added in case a parent Navigation with bottom tabs already handles the safe area inset. If you require a different behavior on your custom UI, configure the bottomMargin as required in your layout.
The easiest way to to use the AppListView is by choosing the SimpleRow type as the ListView::delegate. If the model is an array, the SimpleRow properties are automatically initialized with the matching array properties.
Note: If no specific width and height is set, the AppListView uses the parent's width and height by default.
AppListView { delegate: SimpleRow {} model: [ { text: "Widget test", detailText: "Some of the widgets available in Felgo AppSDK", iconType: IconType.tablet }, { text: "Shown are:", detailText: "ListPage, NavigationBar with different items, Switch", iconType: IconType.question } ] }
Using a model based on the ListModel type is also possible:
AppListView { model: ListModel { ListElement { name: "Banana" } ListElement { name: "Apple" } ListElement { name: "Potato" } } delegate: SimpleRow { text: name } }
Similar to the QML ListView type, sections are created by specifying a ListView::section.property and ListView::section.delegate. Just use the SimpleSection type as the delegate to get a default section look that matches the underlying platform style.
AppListView { model: ListModel { ListElement { type: "Fruits"; name: "Banana" } ListElement { type: "Fruits"; name: "Apple" } ListElement { type: "Vegetables"; name: "Potato" } } delegate: SimpleRow { text: name } section.property: "type" section.delegate: SimpleSection { } }
Note: Sections are only available if the ListView::model is based on the ListModel type. To create sections for an array model, use the AppListView::prepareArraySections function.
See the guide Use ScrollViews and ListViews in Your App for many more list view examples, for example how to customize the look of your list item delegates.
The SimpleRow::selected signal allows to handle click events on a list cell. For custom delegate items, you can add your own MouseArea for handling touch input.
import Felgo App { NavigationStack { AppPage { title: "Clickable List Example" AppListView { delegate: SimpleRow { onSelected: console.log("Clicked Item #"+index+": "+JSON.stringify(modelData)) } model: [ { text: "Apple", detailText: "A delicious fruit with round shape", iconType: IconType.apple }, { text: "Beer", detailText: "A delicous drink", iconType: IconType.beer } ] } } } }
The list view updates its UI automatically whenever the model changes - at least when you describe your model as a ListModel type.
For plain JSON-based models, the list is not notified when some data values within the JSON structure change. In this case, you can manually trigger a property-changed signal, which in turn updates the UI of the list:
import Felgo App { NavigationStack { AppPage { id: page title: "Append List Item Example" property var listData: [ { text: "Apple", detailText: "A delicious fruit with round shape", iconType: IconType.apple }, { text: "Beer", detailText: "A delicous drink", iconType: IconType.beer } ] AppListView { id: listView model: page.listData delegate: SimpleRow { onSelected: { page.listData.push(modelData) // add copy of clicked element at end of model page.listDataChanged() // signal change of data to update the list } } } } } }
Find more examples for frequently asked development questions and important concepts in the following guides:
[since Felgo 2.7.0] backgroundColor : color |
The background color of the list view. By default the color matches Theme::secondaryBackgroundColor on iOS and is transparent on all other platforms.
This property was introduced in Felgo 2.7.0.
desktopScrollEnabled : bool |
Enable improved vertical scrolling on desktop using mousewheels and touchpads. By default, true
on desktop platforms.
emptyText : AppText |
An Apptext that is visible when the AppListView contains no elements.
To display a text, change the Text::text property of emptyText:
AppListView { model: [] // no elements emptyText.text: "No items available" }
emptyView : Item |
A container that is visible when the AppListView contains no elements.
This container contains one AppText per default, accessible via emptyText property.
To add custom content, change the Item::children property of emptyView:
AppListView { model: [] // no elements emptyView.children: [ CustomEmptyView {} ] }
scrollIndicatorVisible : bool |
Whether an AppScrollIndicator should be visible when the user scrolls through the list or not.
scrollsToTop : bool |
By default, an AppListView component scrolls to the top of the list if a user taps the status bar on iOS. Set this property to false
to disable that behavior.
[since Felgo 3.3.0] showSearch : bool |
Adds a SearchBar component as ListView::header item of the list. Performed searches will trigger the search signal.
This property was introduced in Felgo 3.3.0.
See also search.
|
This signal is emitted if a user uses the integrated SearchBar which can be enabled with showSearch
Note: The corresponding handler is onSearch
.
This signal was introduced in Felgo 3.3.0.
See also showSearch.
getScrollPosition() |
Returns an object containing internal information about the current scroll position of the list.
This object can later be passed to restoreScrollPosition() to restore this exact position in the list.
This is useful, when the list's model gets updated with new items, to preserve the scroll position. Otherwise, the list jumps to the top when the model changes.
Example code:
AppListView { model: myModel function update() { var pos = getScrollPosition() //retrieve scroll position data loadMoreItems() //adds new items to list model restoreScrollPosition(pos) //scrolls to the previous position } }
|
Currently, only models of type ListModel support the ListView::section features. This function is a convenience function that allows sections for array models too.
Example code:
AppListView { delegate: SimpleRow { } model: prepareArraySections(myArrayModel) section.property: "category" section.delegate: SimpleSection { } }
This method was introduced in Felgo 2.6.2.
restoreScrollPosition(data, numNewItemsOnTop) |
Restores a previous scroll position retrieved with getScrollPosition().
If items have been added to the list's model on the top, the number of added items should be passed as the second parameter. If items have been added on the bottom, this parameter can be left out.
This is useful, when the list's model gets updated with new items, to preserve the scroll position. Otherwise, the list jumps to the top when the model changes.
Example code:
AppListView { model: myModel function update() { var pos = getScrollPosition() //retrieve scroll position data loadMoreItems() //adds new items to list model restoreScrollPosition(pos) //scrolls to the previous position } }