Skip to content

Commit 57064cf

Browse files
Jasan SinghJasan Singh
authored andcommitted
added code for to avoid one frame delay to calculate intiallaytout for react native tab views
1 parent 679beba commit 57064cf

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

app/containers/TabBarB/TabBarBContainer.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import React, { Component } from 'react';
2-
import { View, StyleSheet } from 'react-native';
2+
import { View, StyleSheet, Dimensions } from 'react-native';
33
import { TabViewAnimated, TabBar } from 'react-native-tab-view';
44
import { ListsContainer } from '~/containers'
55
import TabBarBottom from './TabBarBottom'
66
import Icon from 'react-native-vector-icons/Ionicons'
77

8+
const initialLayout = {
9+
height: 0,
10+
width: Dimensions.get('window').width,
11+
}
812

913
export default class TabViewExample extends Component {
1014
state = {
@@ -17,7 +21,6 @@ export default class TabViewExample extends Component {
1721
};
1822

1923
handleChangeTab = (index) => {
20-
console.log('Top TABBAR index: ', index)
2124
this.setState({ index });
2225
};
2326

@@ -26,7 +29,6 @@ export default class TabViewExample extends Component {
2629
};
2730

2831
renderScene = ({ route }) => {
29-
console.log('Top TABBAR key: ', route.key)
3032
switch (route.key) {
3133
case '1':
3234
return <TabBarBottom />
@@ -62,6 +64,7 @@ export default class TabViewExample extends Component {
6264
renderScene={this.renderScene}
6365
renderHeader={this.renderHeader}
6466
onRequestChangeTab={this.handleChangeTab}
67+
initialLayout={initialLayout}
6568
/>
6669
);
6770
}

app/containers/TabBarB/TabBarBottom.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import React, { Component } from 'react';
2-
import { View, StyleSheet, Platform } from 'react-native';
2+
import { View, StyleSheet, Platform, Dimensions } from 'react-native';
33
import { TabViewAnimated, TabBar, TabViewPagerScroll, TabViewPagerPan } from 'react-native-tab-view';
44
import Icon from 'react-native-vector-icons/Ionicons'
55

6+
const initialLayout = {
7+
height: 0,
8+
width: Dimensions.get('window').width,
9+
}
10+
11+
612
export default class TabBarBottom extends Component {
713
state = {
814
index: 0,
@@ -13,7 +19,6 @@ export default class TabBarBottom extends Component {
1319
};
1420

1521
handleChangeTab = (index) => {
16-
console.log('Bottom TABBAR index: ', index)
1722
this.setState({ index });
1823
};
1924

@@ -22,7 +27,6 @@ export default class TabBarBottom extends Component {
2227
};
2328

2429
renderScene = ({ route }) => {
25-
console.log('Bottom TABBAR key: ', route.key)
2630
switch (route.key) {
2731
case '1':
2832
return <View style={[ styles.page, { backgroundColor: '#96ceb4' } ]} />;
@@ -55,6 +59,7 @@ export default class TabBarBottom extends Component {
5559
swipeEnabled ={false}
5660
animationEnabled ={false}
5761
renderPager={this.renderPager}
62+
initialLayout={initialLayout}
5863
/>
5964
);
6065
}

0 commit comments

Comments
 (0)