Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On Android, TitleIndicator scrolls to title of initial page #149

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions viewpager/indicator/PagerTitleIndicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { StyleSheet, View, ViewPropTypes, Text, TouchableOpacity,ScrollView ,Dimensions} from 'react-native'
import { StyleSheet, View, ViewPropTypes, Text, TouchableOpacity,ScrollView ,Dimensions, Platform} from 'react-native'
import IndicatorViewPager from '../IndicatorViewPager'

const itemLayoutInfo = [];
Expand Down Expand Up @@ -43,7 +43,7 @@ export default class PagerTitleIndicator extends Component {

constructor(props) {
super(props);
this._preSelectedIndex = props.initialPage;
this._preSelectedIndex = 0;
this._contentHorOffset = 0;
this._currentMaxHor = screenWidth;
this._titleCount = props.titles.length || 0;
Expand Down Expand Up @@ -91,6 +91,10 @@ export default class PagerTitleIndicator extends Component {
key={index}
onLayout={e => {
itemLayoutInfo[index] = e.nativeEvent;

if(Platform.OS == 'android' && index == (this.props.titles.length - 1)){
this.onPageSelected({position: this.props.initialPage});
}
}}
onPress={() => {
if(this.props.trackScroll === true){
Expand Down