I
I
Ilya2019-06-03 14:08:42
React Native
Ilya, 2019-06-03 14:08:42

How to set badge count in react-navigation?

I decided to add a badge for the icon in the bottom-navigation.
Found the right module installed. Everything is working.
Such question as to me now to transfer value to it?
In my case, I have a rest that works as soon as you enter the application.
How do I pass data.length to it?
The code is like this :
App.js <- Here I have a StackNavigator

Alarm: {
      screen: Alarm,
      navigationOptions: { tabBarIcon: AlarmTabIcon }
    },

const AlarmTabIcon = ({ tintColor }) => (
  <View
    style={{
      flexDirection: "row",
      alignItems: "center",
      justifyContent: "center"
    }}
  >
    <IconBadge
      MainElement={<Ionicons name="ios-alert" size={26} color={tintColor} />}
      BadgeElement={
        <Text style={{ color: "#FFFFFF", fontSize: 8 }}>
          { Сюда нужно передавать значение }
        </Text>
      }
      IconBadgeStyle={{ width: 14, height: 14, backgroundColor: "#4B1E70" }}
      
    />
  </View>
);

The idea was to store the value in AsyncStorage (data.length)
But how can I pass it to a constant and will it update when data.length changes its value.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
davidnum95, 2019-06-04
@davidnum95

I did this: I downloaded info on badges, wrote them to the store (redux), then each component of the icon connected to the store and got the data from there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question