Class “Composite”

Object > NativeObject > Widget > Composite

An empty widget that can contain other widgets.

Composite on Android
Android
Composite on iOS
iOS
Type: Composite<ChildType> extends Widget
Generics: ChildType: The common widget class of the children this composite can contain. Must be a subclass of Widget and defaults to Widget.
Constructor: public
Singleton: No
Namespace: tabris
Direct subclasses: Canvas, Cell, Page, RefreshComposite, Row, ScrollView, Stack, Tab
JSX Support: Element: <Composite/>
Parent Elements: <Canvas/>, <Cell/>, <Composite/>, <Page/>, <RefreshComposite/>, <Row/>, <ScrollView/>, <Stack/>, <Tab/>
Child Elements: Any standalone widget element

Examples

JavaScript

import {Composite, contentView} from 'tabris';

new Composite({left: 0, top: 0, width: 128, height: 256})
  .appendTo(contentView);

See also:

JSX Creating a simple Composite

Constructor

new Composite(properties?)

Parameter Type Description
properties Properties<Composite> Sets all key-value pairs in the properties object as widget properties. Optional.

Methods

append(…widgets)

Adds the given widgets to the composite.

Parameter Type Description
…widgets Widget[]  

Returns: this

append(widgets)

Adds all widgets in the given array to the composite.

Parameter Type Description
widgets Widget[]  

Returns: this

append(widgets)

Adds all widgets in the given collection to the composite.

Parameter Type Description
widgets WidgetCollection  

Returns: this

apply(properties)

Applies the given properties to all descendants that match the associated selector(s).

If you wish to always exclude specific “internal” children from this, overwrite the children method on their parent. See children for details.

Parameter Type Description
properties {[selector]: Properties<Widget>}  

Returns: this

children(selector?)

Returns a (possibly empty) collection of all children of this widget that match the given selector.

When writing custom UI components it may be useful to overwrite this method to prevent access to the internal children by external code. Doing so also affects find and apply, on this widget as well as on all parents, thereby preventing accidental clashes of widget id or class values. See also _children, _find and _apply.

Parameter Type Description
selector Selector A selector expression or a predicate function to filter the results. Optional.

Returns: WidgetCollection<ChildType>

find(selector?)

Returns a collection containing all descendants of all widgets in this collection that match the given selector.

If you wish to always exclude specific “internal” children from the result, overwrite the children method on their parent. See children for details.

Parameter Type Description
selector Selector A selector expression or a predicate function to filter the results. Optional.

Returns: WidgetCollection

Protected Methods

These methods are accessible only in classes extending Composite.

_acceptChild(child)

Called by the framework with each widget that is about to be added as a child of this composite. May be overwritten to reject some or all children by returning false.

Parameter Type Description
child Widget  

Returns: boolean

_addChild(child, index?)

Called by the framework with a child to be assigned to this composite. Triggers the ‘addChild’ event. May be overwritten to run any code prior or after the child is inserted.

Parameter Type Description
child Widget  
index number Optional.

Returns: undefined

_apply(properties)

Identical to the apply method, but intended to be used by subclasses in case the children method was overwritten . See children for details.

Parameter Type Description
properties {[selector]: Properties<Widget>}  

Returns: this

_checkLayout(value)

Called by the framework with the layout about to be assigned to this composite. May be overwritten to reject a layout by throwing an Error.

Parameter Type Description
value Layout  

Returns: undefined

_children(selector?)

Identical to the children method, but intended to be used by subclasses in case the children method was overwritten. See children for details.

Parameter Type Description
selector Selector A selector expression or a predicate function to filter the results. Optional.

Returns: WidgetCollection

_find(selector?)

Identical to the find method, but intended to be used by subclasses in case the children method was overwritten. See children for details.

Parameter Type Description
selector Selector A selector expression or a predicate function to filter the results. Optional.

Returns: WidgetCollection

_initLayout(props?)

Called with the constructor paramter (if any) to initialize the composite’s layout manager. May be overwritten to customize/replace the layout. The new implementation must make a super call to initialize the layout.

Parameter Type Description
props {
  layout: Layout // optional
}
Optional.

Returns: undefined

_removeChild(child)

Called by the framework with a child to be removed from this composite. Triggers the ‘removeChild’ event. May be overwritten to run any code prior or after the child is removed.

Parameter Type Description
child Widget  

Returns: undefined

Properties

layout

The layout manager responsible for interpreting the layoutData of the child widgets of this Composite.

Type: Layout | null
Default: Layout
Settable: By Constructor or JSX
Change Event: Not supported

This property can only be set via constructor or JSX. Once set, it cannot change anymore.

Events

addChild

Fired when a child is added to this widget.

EventObject Type: CompositeAddChildEvent<Composite>

Property Type Description
child Widget The widget that is added as a child.
index number Denotes the position in the children list at which the child widget is added.

removeChild

Fired when a child is removed from this widget.

EventObject Type: CompositeRemoveChildEvent<Composite>

Property Type Description
child Widget The widget that is removed.
index number The property index denotes the removed child widget’s position in the children list.`