Fix drawer according to number of teams (#974)

This commit is contained in:
enahum 2017-10-02 12:22:14 -03:00 committed by GitHub
parent 0df3c7428a
commit 13922e3764
3 changed files with 30 additions and 16 deletions

View file

@ -315,26 +315,37 @@ export default class ChannelDrawer extends PureComponent {
openDrawerOffset
} = this.state;
const showTeams = openDrawerOffset !== 0 && teamsCount > 1;
const multipleTeams = teamsCount > 1;
const showTeams = openDrawerOffset !== 0 && multipleTeams;
if (this.drawerSwiper) {
if (showTeams) {
if (multipleTeams) {
this.drawerSwiper.getWrappedInstance().runOnLayout();
} else if (!openDrawerOffset) {
this.drawerSwiper.getWrappedInstance().scrollToStart();
}
}
const teamsList = (
<View style={style.swiperContent}>
<TeamsList
closeChannelDrawer={this.closeChannelDrawer}
navigator={navigator}
/>
</View>
);
const lists = [];
if (multipleTeams) {
const teamsList = (
<View
key='teamsList'
style={style.swiperContent}
>
<TeamsList
closeChannelDrawer={this.closeChannelDrawer}
navigator={navigator}
/>
</View>
);
lists.push(teamsList);
}
const channelsList = (
<View style={style.swiperContent}>
lists.push(
<View
key='channelsList'
style={style.swiperContent}
>
<ChannelsList
navigator={navigator}
onSelectChannel={this.selectChannel}
@ -354,8 +365,7 @@ export default class ChannelDrawer extends PureComponent {
showTeams={showTeams}
theme={theme}
>
{teamsList}
{channelsList}
{lists}
</DrawerSwiper>
);
};

View file

@ -53,10 +53,12 @@ export default class DrawerSwiper extends PureComponent {
theme
} = this.props;
const initialPage = React.Children.count(children) - 1;
return (
<Swiper
ref='swiper'
initialPage={1}
initialPage={initialPage}
onIndexChanged={this.swiperPageSelected}
paginationStyle={style.pagination}
width={deviceWidth - openDrawerOffset}

View file

@ -70,7 +70,9 @@ export default class Swiper extends PureComponent {
onLayout = () => {
if (this.runOnLayout) {
if (Platform.OS === 'ios') {
this.scrollView.scrollTo({x: this.offset, animated: false});
setTimeout(() => {
this.scrollView.scrollTo({x: this.props.width * this.state.index, animated: false});
}, 100);
} else {
this.scrollView.setPageWithoutAnimation(this.state.index);
}