/** * Copyright (c) 2015-present, Facebook, Inc. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @format */ 'use strict'; var React = require('react'); var ReactNative = require('react-native'); var { Image, StyleSheet, Text, TouchableWithoutFeedback, TouchableOpacity, View, ViewPagerAndroid, } = ReactNative; import type {ViewPagerScrollState} from 'ViewPagerAndroid'; var PAGES = 5; var BGCOLOR = ['#fdc08e', '#fff6b9', '#99d1b7', '#dde5fe', '#f79273']; var IMAGE_URIS = [ 'https://apod.nasa.gov/apod/image/1410/20141008tleBaldridge001h990.jpg', 'https://apod.nasa.gov/apod/image/1409/volcanicpillar_vetter_960.jpg', 'https://apod.nasa.gov/apod/image/1409/m27_snyder_960.jpg', 'https://apod.nasa.gov/apod/image/1409/PupAmulti_rot0.jpg', 'https://apod.nasa.gov/apod/image/1510/lunareclipse_27Sep_beletskycrop4.jpg', ]; class LikeCount extends React.Component { state = { likes: 7, }; onClick = () => { this.setState({likes: this.state.likes + 1}); }; render() { var thumbsUp = '\uD83D\uDC4D'; return ( {thumbsUp + ' Like'} {this.state.likes + ' likes'} ); } } class Button extends React.Component { _handlePress = () => { if (this.props.enabled && this.props.onPress) { this.props.onPress(); } }; render() { return ( {this.props.text} ); } } class ProgressBar extends React.Component { render() { var fractionalPosition = this.props.progress.position + this.props.progress.offset; var progressBarSize = (fractionalPosition / (PAGES - 1)) * this.props.size; return ( ); } } class ViewPagerAndroidExample extends React.Component { static title = ''; static description = 'Container that allows to flip left and right between child views.'; state = { page: 0, animationsAreEnabled: true, scrollEnabled: true, progress: { position: 0, offset: 0, }, }; onPageSelected = e => { this.setState({page: e.nativeEvent.position}); }; onPageScroll = e => { this.setState({progress: e.nativeEvent}); }; onPageScrollStateChanged = (state: ViewPagerScrollState) => { this.setState({scrollState: state}); }; move = delta => { var page = this.state.page + delta; this.go(page); }; go = page => { if (this.state.animationsAreEnabled) { this.viewPager.setPage(page); } else { this.viewPager.setPageWithoutAnimation(page); } this.setState({page}); }; render() { var pages = []; for (var i = 0; i < PAGES; i++) { var pageStyle = { backgroundColor: BGCOLOR[i % BGCOLOR.length], alignItems: 'center', padding: 20, }; pages.push( , ); } var {page, animationsAreEnabled} = this.state; return ( { this.viewPager = viewPager; }}> {pages}