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

How to add TabBar badge #3692

Closed
Bundas opened this issue Mar 8, 2018 · 2 comments
Closed

How to add TabBar badge #3692

Bundas opened this issue Mar 8, 2018 · 2 comments

Comments

@Bundas
Copy link

Bundas commented Mar 8, 2018

Hello, I know there have been already resolved issues like this #766, but I believe they have not been resolved completely because the badge is not fitting correctly (picture below). Any idea how to fix that? In my opinion it would work fine If the Tab container was wider/bigger.. But I don't know how to do so

import IconBadge from 'react-native-icon-badge';

return TabNavigator(
        {
            Food: {
                screen: stackNavigator,
                navigationOptions: {
                    tabBarIcon: (
                        <View
                            style={{
                                flexDirection: 'row',
                                alignItems: 'center',
                                justifyContent: 'center'
                            }}
                        >
                            <IconBadge
                                MainElement={
                                    <Ionicons
                                        // style={{ margin: 10 }}
                                        name={'cart'}
                                        size={25}
                                        color={'white'}
                                    />
                                }
                                BadgeElement={
                                    <Text style={{ color: '#FFFFFF' }}>
                                        {1}
                                    </Text>
                                }
                                IconBadgeStyle={{
                                    width: 15,
                                    height: 15,
                                    backgroundColor: 'red'
                                }}
                                Hidden={false}
                            />
                        </View>
                    ),
                    tabBarLabel: 'Food'
                }
            },
            Cart: {
                screen: RandomScene,
                navigationOptions: {
                    tabBarIcon: (
                        <Ionicons name={'cart'} size={25} color={'white'} />
                    ),
                    tabBarLabel: 'Cart'
                }
            },
            Profile: {
                screen: RandomScene,
                navigationOptions: {
                    tabBarIcon: (
                        <View>
                            <Ionicons
                                name={'account'}
                                size={25}
                                color={'white'}
                            />
                            {
                                <View
                                    style={{
                                        position: 'absolute',
                                        right: 10,
                                        top: 5,
                                        backgroundColor: 'red',
                                        borderRadius: 9,
                                        width: 18,
                                        height: 18,
                                        justifyContent: 'center',
                                        alignItems: 'center'
                                    }}
                                >
                                    <Text style={{ color: 'white' }}>2</Text>
                                </View>
                            }
                        </View>
                    ),
                    tabBarLabel: 'Profile'
                }
            }
        },
        {
            tabBarPosition: 'bottom',
            lazy: false,
            tabBarOptions: {
                showIcon: true,
                showLabel: false,
                labelStyle: { backgroundColor: 'red' }
            },
            swipeEnabled: false
        }
    );

28660918_2024767637563533_6843494992732749824_n

@matthamil
Copy link
Member

👋 Hi! The issues are reserved for bug reports only. If you believe this is a bug in React Navigation, please reopen a new issue with a reproducible Snack. If you have questions about usage, check out Stack Overflow or the Reactiflux Discord server.

@chansuke
Copy link

Add position:absolute in IconBadgeStyle and tweak the position will fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants