MListView

MListView ⇐ Trait

The ListView is a trait that adds the capabilities to a View to manage a list of children (named items).

Kind: global mixin
Extends: Trait
Mixes: MFocus
Properties

NameTypeDefaultDescription
isListViewboolean

flag

indexnumber0

The index of the currently focused item, default is 0

lastItemViewItemView

last item of a listView

dataListModel.<Object>

the data model of the items

cyclicbooleanfalse

if true the list is cyclic, default is false

prefixstring

The item name

dataItem*

Currently selected data

itemViewClassItemView

Item view class to use (default View)

unselectedStateNamestring

name of the item unselected state, 'default' by default

resetStateOnSelectboolean

when set selected state, reset all other states. Default is true.

Example

// Full declarative ListView
$View.declare("FullDeclarativeListView", {
  traits: [$MListView],

  properties: {
     prefix: "myItem",
     "myItem#<i>": {
         class: $FullDeclarativeListViewItem, // should inherit from MListViewItem to have access to its index and previous item reference
         width: ({parent}) => parent.width,
         height: ({parent}) => parent.height,
         x: ({index}) => index * 100
     }
  },

  states: {
     "myItem#<i>": {
         translateX: ({index}) => -index * 100
     }
  },

  transitions: {
     "myItem#<i>": {
         translateX: {duration: 250}
     }
  }
});

// Item factory ListView
$View.declare("ItemFactoryListView", {
  traits: [$MListView],
  statics: {
     declare: function(classPath, definition) {
         var parameterizedDefinition = $MListView.$$methods.declare(definition);
         var TheClass = $View.declare.apply(this, arguments);
         Object.assign(TheClass.prototype, parameterizedDefinition);
         return TheClass;
     }
  },
  methods: {
     itemFactory: function (itemData, index, dataCollection, options) {
         return {
             properties: {
                 class: $ItemFactoryListViewItem, // should inherits from MListViewItem to have access to its index and previous item reference
                 width: ({parent}) => parent.width,
                 height: ({parent}) => parent.height,
                 x: ({index}) => index * 100
             },
             states: {
                 translateX: () => -index * 100
             },
             transitions: {
                 translateX: {duration: 250}
             }
         };
      }
    }
});

declare(definition) ⇒ Object

Function to call before view declaration to avoid parametrized data to be computed by real children property declaration (see example in Trait description)

Kind: instance method of MListView
Returns: Object - Object containing parametrized children definition (if exist) to merge to prototype

ParamTypeDescription
definitionObject

Definition of the view to declare

_buildAfterRenderingContext()

Keep the definition of the parametrized definitions into separates variables

Kind: instance method of MListView

setData(data, [options])

Set the data

IMPORTANT setItems remove previously created items, as well as their states & transitions

Kind: instance method of MListView

ParamTypeDescription
dataListModel.<object>

the data model of the items

[options]Object

additional options

[options.index]number

the item index to focus

[options.redraw]boolean

flag to force all items redraw

[options.skipNotify]boolean

If true do not fire the MListView#selectionChange event

itemFactory(itemData, index, dataCollection, options) ⇒ * | Object

Build the child view description from item data You must implement this method.

Kind: instance method of MListView
Returns: * | Object - Object definition for child view

ParamTypeDescription
itemDataObject

Data to fill item view

indexNumber

Index of current item in data collection

dataCollectionObject

Full data collection

optionsObject

Options to path through

itemDestructor(index)

Extension point to allow to remove all custom things done about a specified item /!\ No need to remove child view or states managed by MListView

Kind: instance method of MListView

ParamTypeDescription
indexNumber

Index of the item view deleted

selectItem(index, [options]) ⇒ boolean

Select the item by it’s index Will focus related item view if parent is focused, if not states selected will be added to item view

Kind: instance method of MListView
Returns: boolean - Returns true if the item has been focused, false else ; If the item is already focused, return false
Emits: MListView.event:selectionChange

ParamTypeDescription
indexnumber

The index of the item to focus

[options]Object
[options.skipNotify]boolean

If true do not fire the MListView#selectionChange event

[options.skipTransitions]boolean

If true do not play the transitions

[options.force]boolean

If true force the selectItem even if the index to set is already the current index

unselectItem(index, [options])

Allows to unselect current item

Kind: instance method of MListView

ParamTypeDescription
indexNumber

Index of item to unselect

[options]Object
[options.skipNotify]boolean

If true do not fire the MListView#selectionChange event

[options.skipTransitions]boolean

If true do not play the transitions

[options.force]boolean

If true force the selectItem even if the index to set is already the current index

getItem(index) ⇒ Item

Get the item at the given index. Return the current focused item if no index is given.

Kind: instance method of MListView
Returns: Item - Returns the item at the given index

ParamTypeDescription
indexnumber

The index of the item you want

getItemView(index) ⇒ View

Get the item view at the given index. Return the current focused item view if no index is given.

Kind: instance method of MListView
Returns: View - Returns the item view at the given index

ParamTypeDescription
indexnumber

The index of the view you want

getNextItem() ⇒ *

Allows to retrieve next data item

Kind: instance method of MListView
Returns: * - Next data item or null if current is the last and list is not cyclic

next(options) ⇒ boolean

Focus the next item.

Kind: instance method of MListView
Returns: boolean - Returns true if the next item is focused, false else (out of bound)

ParamTypeDescription
optionsobject

the additional options

[options.isLong]boolean

true if long key press

[options.skipNotify]boolean

If true do not fire the MListView#selectionChange event

[options.skipTransitions]boolean

If true do not play the transitions

getPreviousItem() ⇒ *

Allows to retrieve previous data item

Kind: instance method of MListView
Returns: * - Previous data item or null if current is the first and list is not cyclic

previous(options) ⇒ boolean

Focus the previous item.

Kind: instance method of MListView
Returns: boolean - Returns true if the previous item is focused, false else (out of bound)

ParamTypeDescription
optionsobject

the additional options

[options.isLong]boolean

true if long key press

[options.skipNotify]boolean

If true do not fire the MListView#selectionChange event

[options.skipTransitions]boolean

If true do not play the transitions

getNbOfItems() ⇒ number

Get the number of items.

Kind: instance method of MListView
Returns: number - Returns the number of items.

getItemIdFromIndex(itemIndex) ⇒ String

Helper to retrieve a children item id from its index RQ: no test is made to verify if children item really exists

Kind: instance method of MListView
Returns: String - Corresponding item id

ParamTypeDescription
itemIndexNumber

Index of the item

_getChildToFocus()

When the list is focused, the child that is tied to the current item is focused

Kind: instance method of MListView

_onFocusChanged()

When a child of the list is focused, the item that is tied to the child becomes the current item

Kind: instance method of MListView

_callFactory(options, itemData, index, dataCollection)

Kind: instance method of MListView
Access: protected

ParamTypeDescription
optionsObject

Options to path through

itemDataObject

Data to fill item view

indexNumber

Index of current item in data collection

dataCollectionObject

Full data collection