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

fix(Tab): indicator width calculations #3807

Draft
wants to merge 6 commits into
base: next
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions example/src/navigation/RootNavigator.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createDrawerNavigator } from '@react-navigation/drawer';
import { useTheme } from '@rneui/themed';
import { Tab, useTheme } from '@rneui/themed';
import DrawerNavigator from './DrawerNavigator';
import Avatars from '../views/avatars';
import Cards from '../views/cards';
Expand Down Expand Up @@ -70,7 +70,7 @@ function RootNavigator() {
backgroundColor: theme?.colors?.grey4,
}}
>
<Drawer.Screen name="Avatars" component={Avatars} />
<Drawer.Screen name="Avatars" component={Tabs} />
<Drawer.Screen name="Badge" component={Badge} />
<Drawer.Screen name="BottomSheet" component={BottomSheet} />
<Drawer.Screen name="Buttons" component={Buttons} />
Expand Down
199 changes: 88 additions & 111 deletions example/src/views/tabs.tsx
Original file line number Diff line number Diff line change
@@ -1,123 +1,100 @@
import React from 'react';
import { Header } from '../components/header';
import { Tab, Text, TabView } from '@rneui/themed';
import { Tabs, TabsRef } from '@rneui/base/dist/Tab/Tab';
import { Button, Tab as TabBar, TabView, Text } from '@rneui/themed';
import React, { useRef } from 'react';
import { ScrollView } from 'react-native';
import { Header } from '../components/header';

export default () => {
const [index, setIndex] = React.useState(0);
const tabRef = useRef<TabsRef>();

console.log('tabs re render');
return (
<>
<Header title="Tab" />
<Tab
value={Math.ceil(index > -1 ? index : 0)}
onChange={(e) => setIndex(e)}
indicatorStyle={{
backgroundColor: 'white',
height: 3,
}}
scrollable
variant="primary"
>
<Tab.Item
containerStyle={{
width: 180,
}}
title="Recent"
titleStyle={{ fontSize: 12 }}
icon={{ name: 'timer', type: 'ionicon', color: 'white' }}
/>
<Tab.Item
title="Custom"
containerStyle={(active) => ({
backgroundColor: active ? '#208990' : 'transparent',
width: 180,
})}
titleStyle={{ fontSize: 12 }}
icon={{ name: 'heart', type: 'ionicon', color: 'white' }}
/>
<Tab.Item
containerStyle={{
width: 180,
}}
title="Cart"
titleStyle={{ fontSize: 12 }}
icon={{ name: 'cart', type: 'ionicon', color: 'white' }}
/>
<Tab.Item
containerStyle={{
width: 180,
}}
title="Example tab 1"
titleStyle={{ fontSize: 12 }}
icon={{ name: 'cart', type: 'ionicon', color: 'white' }}
/>
<Tab.Item
containerStyle={{
width: 180,
}}
title="Example tab 2"
titleStyle={{ fontSize: 12 }}
icon={{ name: 'cart', type: 'ionicon', color: 'white' }}
/>
<Tab.Item
containerStyle={{
width: 180,
<Tabs ref={tabRef}>
<TabBar
indicatorStyle={{
backgroundColor: 'white',
height: 3,
}}
title="Example tab 3"
titleStyle={{ fontSize: 12 }}
icon={{ name: 'cart', type: 'ionicon', color: 'white' }}
/>
</Tab>
{/* <Text>
{index}
</Text> */}
scrollable
>
<TabBar.Item
title="Recent"
titleStyle={{ fontSize: 12 }}
icon={{ name: 'timer', type: 'ionicon', color: 'white' }}
/>
<TabBar.Item
title="Custom"
containerStyle={(active) => ({
backgroundColor: active ? '#208990' : 'transparent',
})}
titleStyle={{ fontSize: 12 }}
icon={{ name: 'heart', type: 'ionicon', color: 'white' }}
/>
<TabBar.Item
title="Cart"
titleStyle={{ fontSize: 12 }}
icon={{ name: 'cart', type: 'ionicon', color: 'white' }}
/>
<TabBar.Item
title="Example tab 1"
titleStyle={{ fontSize: 12 }}
icon={{ name: 'cart', type: 'ionicon', color: 'white' }}
/>
<TabBar.Item
title="Example tab 2"
titleStyle={{ fontSize: 12 }}
icon={{ name: 'cart', type: 'ionicon', color: 'white' }}
/>
<TabBar.Item
title="Example tab 3"
titleStyle={{ fontSize: 12 }}
icon={{ name: 'cart', type: 'ionicon', color: 'white' }}
/>
</TabBar>

<TabView
onSwipeStart={(e) => console.log(e)}
value={index}
onChange={setIndex}
animationType="spring"
// containerStyle={{ width: 240, height: 200 }}
>
<TabView.Item style={{ backgroundColor: 'red', width: '100%' }}>
<ScrollView>
<Text h1>Recent 0</Text>
<Text h1>Recent 0</Text>
<Text h1>Recent 0</Text>
<Text h1>Recent 0</Text>
<Text h1>Recent 0</Text>
<Text h1>Recent 0</Text>
<Text h1>Recent 0</Text>
<Text h1>Recent 0</Text>
<Text h1>Recent 0</Text>
<Text h1>Recent 0</Text>
<Text h1>Recent 0</Text>
<Text h1>Recent 0</Text>
<Text h1>Recent 0</Text>
<Text h1>Recent 0</Text>
<Text h1>Recent 0</Text>
<Text h1>Recent 0</Text>
<Text h1>Recent 0</Text>
</ScrollView>
</TabView.Item>
<TabView.Item style={{ backgroundColor: 'blue', width: '100%' }}>
<Text h1>Favorite 1</Text>
</TabView.Item>
<TabView.Item style={{ backgroundColor: 'green', width: '100%' }}>
<Text h1>Cart 2${Math.random()}</Text>
</TabView.Item>
<TabView.Item style={{ backgroundColor: 'red', width: '100%' }}>
<Text h1>Example 3</Text>
</TabView.Item>
<TabView.Item style={{ backgroundColor: 'blue', width: '100%' }}>
<Text h1>Example 4</Text>
</TabView.Item>
<TabView.Item style={{ backgroundColor: 'green', width: '100%' }}>
<Text h1>Example 5</Text>
</TabView.Item>
</TabView>
<TabView onSwipeStart={console.log}>
<TabView.Item style={{ backgroundColor: 'red', width: '100%' }}>
<ScrollView>
<Button onPress={() => tabRef.current.changeIndex(2)}>
Jump to Tab 3
</Button>
<Text h1>{Math.random()}</Text>
<Text h1>Recent 0</Text>
<Text h1>Recent 0</Text>
<Text h1>Recent 0</Text>
<Text h1>Recent 0</Text>
<Text h1>Recent 0</Text>
<Text h1>Recent 0</Text>
<Text h1>Recent 0</Text>
<Text h1>Recent 0</Text>
<Text h1>Recent 0</Text>
<Text h1>Recent 0</Text>
<Text h1>Recent 0</Text>
<Text h1>Recent 0</Text>
<Text h1>Recent 0</Text>
<Text h1>Recent 0</Text>
<Text h1>Recent 0</Text>
<Text h1>Recent 0</Text>
</ScrollView>
</TabView.Item>
<TabView.Item style={{ backgroundColor: 'blue', width: '100%' }}>
<Text h1>Favorite 1</Text>
</TabView.Item>
<TabView.Item style={{ backgroundColor: 'green', width: '100%' }}>
<Text h1>Cart 2${Math.random()}</Text>
</TabView.Item>
<TabView.Item style={{ backgroundColor: 'red', width: '100%' }}>
<Text h1>Example 3</Text>
</TabView.Item>
<TabView.Item style={{ backgroundColor: 'blue', width: '100%' }}>
<Text h1>Example 4</Text>
</TabView.Item>
<TabView.Item style={{ backgroundColor: 'green', width: '100%' }}>
<Text h1>Example 5</Text>
</TabView.Item>
</TabView>
</Tabs>
</>
);
};
2 changes: 1 addition & 1 deletion packages/base/src/Tab/Tab.Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ const styles = StyleSheet.create({
paddingVertical: 8,
},
containerStyle: {
flex: 1,
// flex: 1,
borderRadius: 0,
},
});
Expand Down