0

Looking for suggestion how to remove number from notification counter badge


Should be look like this example


Badge should render notification count that receiving from BE and calculated as sum of personal message notification number and events notifications count and at same time after user open app, it should whipe events notifications count and render only personal message count For iOs all works fine but for android works bad because badge activated only when new notification arriwed and use value from device top bar when app is closed or value that i set with Notifications.setBadgeCountAsync() but in case user swipe and clear all notification from top bar it also stop rendering value from Notifications.setBadgeCountAsync() Well-know that it is not possible to handle rendering of current notification badge count when app is closed for Android, so maybe need to find out how to pass needed value with channel or with every new notification just rewrite badge to custom badge without number, or maybe it is possible to set opacity for number inside badge

Key features: "react-native": "0.71.7", "expo": "^48.0.0", "expo-notifications": "~0.18.1",

Expected version of android to use: version 8 and newer

Now notification handled as:

async function registerForPushNotificationsAsync() {
    let token;
    if (Device.isDevice) {
      const { status: existingStatus } =
        await Notifications.getPermissionsAsync();
      let finalStatus = existingStatus;
      if (existingStatus !== 'granted') {
        const { status } = await Notifications.requestPermissionsAsync();
        finalStatus = status;
      }
      if (finalStatus !== 'granted') {
        return;
      }
      token = (await Notifications.getExpoPushTokenAsync()).data;
    }
    if (Platform.OS === 'android') {
      Notifications.setNotificationChannelAsync('default', {
        name: 'default',
        importance: Notifications.AndroidImportance.MAX,
        vibrationPattern: [0, 250, 250, 250],
        lightColor: '#FF231F7C',
      });
    }
    return token;
  }

  const setBadgeCountAppIsOpen = async () => {
    await Notifications.requestPermissionsAsync({
      ios: {
        allowBadge: true,
      },
    });
    const count = await Notifications.setBadgeCountAsync(
      data?.unreadMessages?.length ?? 0
    );
    return count;
  };
  useEffect(() => {
    setBadgeCountAppIsOpen();
    getDeviceToken();
  }, []);

  useEffect(() => {
    setBadgeCountAppIsOpen();
  }, [data?.unreadMessages?.length]);
Serg Mah
  • 1
  • 1

0 Answers0