Utilizing React Native to implement dynamic in-app badge notifications based on Firebase/Firestore data

My tech stack:

  • React Native
  • OneSignal for push notifications
  • React Navigation
  • React Native Elements (Badge component)
  • React Native Vector Icons
  • Firebase, Firestore as backend

Within my app, I have two buttons located in the topRight Stack Screen.

<Stack.Screen
    name="CreateEvent"
    component={CreateEvent}
    options={{
        headerRight: () => (
             <View style={{ flexDirection: "row", alignItems: "center", marginRight: 10 }}>
                   <TouchableOpacity
                        onPress={() => { navigation.navigate("InvitationsNav") }}>
                            <Badge
                                status="error"
                                containerStyle={{ position: 'absolute', top: -4, right: -4 }}
                                value="10"/> // <--- hardcoded value

                                <IconMaterialIcons
                                    name="event"
                                    color={Constants.colors.primaryColor}
                                    backgroundColor="transparent"
                                    size={30}
                                    style={{ paddingHorizontal: 10 }}/>
                   </TouchableOpacity>

                   <TouchableOpacity
                        onPress={() => { navigation.navigate("nl_Notifications") }}>
                            <Badge
                                status="error"
                                containerStyle={{ position: 'absolute', top: -4, right: -4 }}
                                value="2"/> // <--- hardcoded value
                            <IconIonicons
                                name="notifications-outline"
                                color={Constants.colors.primaryColor}
                                backgroundColor="rgba(52, 52, 52, 0.0)"
                                size={30}
                                style={{ paddingHorizontal: 10 }}/>
                  </TouchableOpacity>
               </View>)

https://i.sstatic.net/dtlJZ.png

The hardcoded values on the image need to be dynamic.

I want to update the badge values based on unseen Firestore documents. For example, if a user has 3 new notifications, I want the badge to display 3.

One approach could be to add a "seen: false" flag to Firestore documents. But pre-loading documents with "seen == false" may not be efficient.

Is there a way to dynamically update badge values using OneSignal Push notifications or another solution?

Any suggestions on how to tackle this issue are welcome. Thank you!

Answer №1

After reviewing your point:

However, the concern arises with the need to pre-load firestore documents with seen == false and the potential economic implications of this approach.

Contrary to the assertion made, firestore documents do not have to adhere to a uniform structure, allowing for the application of such logic exclusively to new documents. Alternatively, this logic could be incorporated into older documents for the sake of data consistency, given that the documents will never revert to being "unseen". This, however, may not be a strict necessity in this scenario.

While I lack expertise in the utilization of OneSignal for push notifications, rendering me unable to propose an alternative solution using that platform, in the context of Firestore, the flag option serves as a viable solution. Considering the inevitable interaction with Firestore to verify the status of documents, the flag option presents an adequate resolution.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

AngularJS UI router regular expressions allows for dynamic and flexible routing

I'm attempting to find a parameter with two possible values: 'current' or a number with at least 10 digits. Here's what I've tried: url: '/history/{code:^current$|^[0-9]{10,}$}' Although this regular expression suc ...

Content within iframe is failing to load correctly on both Firefox and Internet Explorer browsers

On my website, I have 4 iframes embedded in 4 different tabs. I've noticed that the content is being cropped when viewed on Firefox, but it loads properly when using Chrome. Strangely, if I manually reload the iframe, the content displays correctly. T ...

Upgrade your AngularJS Directive to an Angular 2.x+ Directive by using an HTML decorator

Is it no longer possible to utilize Angular directives as what I like to refer to as "HTML decorators"? I found this method extremely useful in Angular 1.x when transitioning legacy applications to Single Page Apps by creating a set of directives to enhan ...

The jQuery message validator is currently experiencing some issues with its functionality

I am working on implementing a basic login system using jQuery and it appears to be functioning correctly, but I keep getting an error message in my jQuery code here: alert('Error in system');. What's puzzling is that when I use alert(answe ...

How do I select all checkboxes in TypeScript when I only click on one of them?

I'm currently working with a list of checkboxes in my HTML code: <div class="col-sm-12" *ngIf="ControllerModel"> <div *ngFor="let controller of ControllerModel" class="panel col-md-6 col-lg-6 col-xs-6"> <div class="panel-heading" ...

Using Kendo Grid to Transfer Data Between Grid Cells

Recently, I encountered a problem in my Kendo MVC project where I needed to drag a product code from one Kendo Grid to another when the cell value was empty. Here's the scenario: Grid A contains products ordered, but the vendor sending the list has i ...

Tips for enabling TypeScript's static typings to function during runtime

function multiply(num: number): number { console.log(num * 10) // NaN return num * 10 } multiply("not-a-number") // result == NaN When attempting to call the function above with a hardcoded invalid argument type, TypeScript correctly identifies and w ...

Having trouble deploying my Express/Next app on Netlify

I am facing issues deploying my Next/Express app on Netlify. While the app functions perfectly locally, I encounter problems when attempting to deploy it using Netlify lambda function. Here are the links to my test git repositories: https://github.com/La ...

Error encountered: EPERM when attempting to rename a directory in Node.js unexpectedly

There is a requirement for me to remove the Backup folder, rename the processor as Backup, create a Processor folder again, and send a response to the user. The code I am using for this task is as follows: fsExtra.remove('app/Backup', function(e ...

Angucomplete Alternative solves the challenge of accessing remote URLs

I have been using the Angucomplete Alt directive for creating an autocomplete feature. It has been working well so far, but now I want to customize a specific request to be sent to my server. <div angucomplete-alt id="input-name" ...

Notification that appears when accessed on a mobile device

I have encountered an issue with my website where mobile users are being continuously redirected to the mobile site due to the hosting of the sites in different places preventing the use of cookies to remember the redirection. As a result, a loop occurs. ...

Tips for extracting HTML content from JSON data as valid HTML code

I am attempting to extract HTML content from a JSON object response.indexText, which has been validated with JSONLint. { "indexText": "<div id=\"content-home\"><h1> Hello World! <\/h1> <p>Some text.<\/p> ...

Leveraging NestJs Libraries within Your Nx Monorepo Main Application

I am currently part of a collaborative Nx monorepo workspace. The setup of the workspace looks something like this: https://i.stack.imgur.com/zenPw.png Within the structure, the api functions as a NestJS application while the data-access-scripts-execute ...

How to refresh component after clearing dates in Vuetify datepicker

Currently, I am working with a datepicker in Vuetify JS and I need to find a way to clear the dates and refresh the component. In addition, there is a v-data table that is filtered based on the dates range array. I am exploring options to either add a &ap ...

Glow Texture Hiding Edges in THREE.js SpriteMaterial

While adding a SpriteMaterial glow texture to certain THREE.js nodes, I've encountered some rendering issues, particularly with how it appears over edges. Interestingly, at some angles, everything looks fine, but from other perspectives, the edges see ...

Sending a JavaScript click event using curl and PHP

Attempting to extract information from a website. The main page contains multiple option buttons along with an ACCEPT and RESET button. When the user selects options and clicks on the ACCEPT button, new content is displayed. I have a question regarding ma ...

Internet Explorer causing trouble with reliable Ajax dropdown selection

There are two drop-down lists on my website, where the options in one depend on the selection in the other. The Ajax code works perfectly fine in Chrome and Mozilla, but it's not functioning correctly in Internet Explorer (specifically IE9). I need so ...

How can I effectively exclude API keys from commits in Express by implementing a .gitignore file?

Currently, my API keys are stored in the routes/index.js file of my express app. I'm thinking that I should transfer these keys to an object in a new file located in the parent directory of the app (keys.js), and then include this file in my routes/in ...

The application experiences a sudden crash when utilizing the UIAlertController feature

When I click on the sign-out button on the page, I want to display the OK-Cancel tips. Here is the code I have used: UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Tips" message:@"Sign out?" preferredStyle:UIAlertControllerStyl ...

My Tailwind CSS toggle button disappears in dark mode, why is that happening?

<button aria-label="Toggle Dark Mode" type="button" className="lg:inline-flex lg:w-40 md:w-screen p-3 h-12 w-12 order-2 md:order-3" onClick={() => setTheme(theme === 'dark' ? &ap ...