<viewpager> XElement
<viewpager> is a horizontally swipeable paging component. It is commonly used to build tabbed paging experiences.
Usage
Use <viewpager> together with <viewpager-item> to create horizontally paged content.
Recommended Usage
- Explicitly set the width of
<viewpager>:width: 100%; - Explicitly set the layout direction of
<viewpager>:display: flex; flex-direction: row; - Explicitly constrain the size and shrinking behavior of
<viewpager-item>:width: 100%; flex-shrink: 0; - The direct children of
<viewpager>must be<viewpager-item>.
Attributes
android-always-overscroll
Android
On Android, this attribute is used to control the interaction behavior when scrolling to the edges. Setting it to true enables the default bounce effect, while setting it to false disables the bounce effect. The default value is false.
android-force-can-scroll
Android
3.0
On Android, when this attribute is set to true, gestures are not passed to the parent container when the viewpager is already at the beginning or end.
bounces
iOS
Clay
Harmony
Whether to enable the bounce effect. Note that this effect is not available on Android. On PC, only macOS supports this feature.
enable-scroll
Android
iOS
Clay
Harmony
2.17
Enables horizontal swipe gestures.
initial-select-index
Android
iOS
Clay
Harmony
2.17
Selects the specified page during initialization, specifically when child nodes are first available.
ios-gesture-direction
iOS
When enabled, horizontal swipe events from the outer container (a horizontal UIScrollView) can be recognized when the viewpager is already at the beginning or end.
ios-gesture-offset
iOS
When the finger touches within [0, value] from the left edge of the screen, the horizontal swipe gesture is ignored so the native iOS swipe-back gesture can respond directly. This is not available on Android.
ios-recognized-gesture-class
iOS
The class name of the UIGestureRecognizer that may be recognized simultaneously with the viewpager. This property is designed to let a UIPanGesture work together with the viewpager.
ios-recognized-view-tag
iOS
The UIView tag used to identify the view associated with the UIGestureRecognizer specified by ios-recognized-gesture-class. This property is designed to let a UIPanGesture work together with the viewpager.
keep-item-view
Android
iOS
Whether to enable lazy loading based on early exposure. Use it together with lazyComponent.
Events
Frontend can bind corresponding event callbacks to listen for runtime behaviors of the element, as shown below.
bindchange
Android
iOS
Clay
Harmony
Page change event. It is triggered only after the UI has fully switched to the next page.
bindoffsetchange
Android
iOS
Clay
Harmony
Callback for page transition progress. The value is expressed in page indexes. For example, moving from page 0 to page 1 yields values from 0 to 1, and moving from page 1 to page 2 yields values from 1 to 2.
bindwillchange
Android
iOS
Clay
Harmony
2.17
Page will change event.
Methods
Frontend can invoke component methods via the SelectorQuery API.
selectTab
Android
iOS
Clay
Harmony
Scrolls to the specified page.
Compatibility
LCD tables only load in the browser
