Data flows through the section hierarchy before they are eventually represented on the UI by components. Section provides a set of functionalities to allow you to respond to the data and interact with the UI.
A method annotated with this annotation will be called when the the UI rendered by the section's hierarchy is requesting for a refresh of the content.
SectionTree#refresh() to propagate your refresh request to all the sections in the hierarchy. Then you can handle it in your section like this:
A method annotated with this annotation will be called when there is a change in the visible viewport.
SectionTree#viewPortChangedFromScrolling() to allow your sections to know that something on the viewport is now different.
firstVisiblePositionPosition of the first visible components in the viewport. Components are partially hidden from the visible viewport.
lastVisiblePositionPosition of the last visible components in the viewport. Components are partially hidden from the visible viewport.
totalCountTotal number of items in the section's hierarchy, with the section that contains the annotated method as its root.
firstFullyVisibleIndexPosition of the first fully visible components in the viewport.
lastFullyVisibleIndexPosition of the last fully visible components in the viewport.
A viewport change could occur due to any number of the following reasons:
- Components added to the visible viewport.
- Components removed from the visible viewport.
- Components in the visible viewport are updated.
- Components have moved in or out of the visible viewport.
Positions and total count returned are with respect to the number of components this section has. For example:
When the first item of Section C comes into the viewport due to scrolling,
Section C is 0 while the
Section B is 10.
Section A has a total of 20 items while Section B and C have 10 each.
A method annotated with this annotation will be called when the data changes corresponding to this
section's hierarchy is made available to the
Data changes could occur due to any number of the following:
Availability of these data changes do not mean they are visible on the viewport.
To detect visibility, use
Use this method to give focus to one of the components in a section. If the component is hidden from the visible viewport, the section will be scrolled to reveal it, thereby calling the
@OnViewportChanged annotated method.
The data that renders the component being requested for focus has to be available before the method can work. Hence, only use
requestFocus() after the
@OnDataBound annotated method has been called.
There a few variations of the
Calls focus by the index of the
Component in the
Section scoped by the given
@OnViewportChanged, the index is with respect to the number of components this section has.
Calls focus to the first index of the component in the section represented by the section's key you provided.
SectionLifecycle.requestFocus(SectionContext c, int index) but with an offset.
SectionLifecycle.requestFocus(SectionContext c, String sectionKey) but with an offset.
FocusType is either:
FocusType.STARTCalls focus to the first index of the component in the section
FocusType.ENDCalls focus to the last index of the component in the section
Use this variation if you need to specify a snapping mode.
SmoothScrollAlignmentType is either:
For the full list of methods available to request scroll to a position, check out the SectionLifecycle documentation.
Sections should use this annotation to declare a method to receive events about its children loading state.
INITIAL_LOADLoading has started
LOADINGLoading is still ongoing
SUCCEEDEDLoading is successful
FAILEDLoading has failed.
Returns true if the data set is empty after the loading event
Returns the reason for a
The loading event will be passed up the hierarchy until there is a section that has chosen to handle it. If your section handles the loading event, it has to dispatch the event up its hierarchy if there are parent sections looking to handle it as well.