Container that allows to flip left and right between child views. Each child view of the ViewPagerAndroid
will be treated as a separate page and will be stretched to fill the ViewPagerAndroid
.
It is important all children are <View>
s and not composite components. You can set style properties like padding
or backgroundColor
for each child. It is also important that each child have a key
prop.
Example:
render: function() {
return (
<ViewPagerAndroid
style={styles.viewPager}
initialPage={0}>
<View style={styles.pageStyle} key="1">
<Text>First page</Text>
</View>
<View style={styles.pageStyle} key="2">
<Text>Second page</Text>
</View>
</ViewPagerAndroid>
);
}
...
var styles = {
...
viewPager: {
flex: 1
},
pageStyle: {
alignItems: 'center',
padding: 20,
}
}
initialPage
keyboardDismissMode
onPageScroll
onPageScrollStateChanged
onPageSelected
pageMargin
peekEnabled
scrollEnabled
setPage
setPageWithoutAnimation
initialPage
Index of initial page that should be selected. Use setPage
method to update the page, and onPageSelected
to monitor page changes
Type | Required |
---|---|
number | No |
keyboardDismissMode
Determines whether the keyboard gets dismissed in response to a drag.
Type | Required |
---|---|
enum('none', 'on-drag') | No |
onPageScroll
Executed when transitioning between pages (ether because of animation for the requested page change or when user is swiping/dragging between pages) The event.nativeEvent
object for this callback will carry following data:
Type | Required |
---|---|
function | No |
onPageScrollStateChanged
Function called when the page scrolling state has changed. The page scrolling state can be in 3 states:
Type | Required |
---|---|
function | No |
onPageSelected
This callback will be called once ViewPager finish navigating to selected page (when user swipes between pages). The event.nativeEvent
object passed to this callback will have following fields:
Type | Required |
---|---|
function | No |
pageMargin
Blank space to show between pages. This is only visible while scrolling, pages are still edge-to-edge.
Type | Required |
---|---|
number | No |
peekEnabled
Whether enable showing peekFraction or not. If this is true, the preview of last and next page will show in current screen. Defaults to false.
Type | Required |
---|---|
bool | No |
scrollEnabled
When false, the content does not scroll. The default value is true.
Type | Required |
---|---|
bool | No |
setPage
A helper function to scroll to a specific page in the ViewPager. The transition between pages will be animated.
Type | Required |
---|---|
Number | Yes |
setPageWithoutAnimation
A helper function to scroll to a specific page in the ViewPager. The transition between pages will not be animated.
Type | Required |
---|---|
Number | Yes |
Type |
---|
$Enum |
Constants:
Value | Description |
---|---|
idle | |
dragging | |
settling |
© 2015–2018 Facebook Inc.
Licensed under the Creative Commons Attribution 4.0 International Public License.
https://facebook.github.io/react-native/docs/viewpagerandroid.html