React-native-firebase: Firebase.database().ref().on() not firing after reloading the app

Created on 6 Nov 2018  路  5Comments  路  Source: invertase/react-native-firebase


Issue


database ref's doesnt trigger after i reload the app.
I went through the patch and i upgraded react native firebase package to 5.1.0 but its not working. Its happening in Android physical and emulator phones and i am working in windows environment.
package.json dependencies.
"react": "16.5.0",
"react-native": "0.57.0",
"react-native-firebase": "^5.1.0",


Project Files






iOS

N/A

ios/Podfile:

  • [x] I'm not using Pods
  • [x] I'm using Pods and my Podfile looks like:
# N/A

AppDelegate.m:

N/A

// N/A

Android

android/build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext {
buildToolsVersion = "28.0.2"
minSdkVersion = 16
compileSdkVersion = 27
targetSdkVersion = 26
supportLibVersion = "27.1.1"
}
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
classpath 'com.google.gms:google-services:4.0.1'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

}

allprojects {
repositories {
mavenLocal()
google()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
}

task wrapper(type: Wrapper) {
gradleVersion = '4.6'
distributionUrl = distributionUrl.replace("bin", "all")
}

// N/A

android/app/build.gradle:

dependencies {
implementation project(':react-native-image-picker')
implementation project(':react-native-firebase')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules

//React Native contacts wrapper
implementation project(':react-native-contacts-wrapper')


// Firebase dependencies
implementation "com.google.android.gms:play-services-base:16.0.1"
implementation "com.google.firebase:firebase-core:16.0.4"
implementation "com.google.firebase:firebase-auth:16.0.5"
implementation "com.google.firebase:firebase-database:16.0.4"
implementation "com.google.firebase:firebase-storage:16.0.4"

}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}

apply plugin: 'com.google.gms.google-services'

// N/A

android/settings.gradle:

N/A

// N/A

MainApplication.java:

N/A

// N/A

AndroidManifest.xml:

N/A

<!-- N/A -->

Environment

  • Platform that you're experiencing the issue on:

    • [ ] iOS

    • [ X] Android

    • [ ] iOS but have not tested behavior on Android

    • [ ] Android but have not tested behavior on iOS

    • [ ] Both

  • If known, the version of the platform are you experiencing the issue on:

    • ADD_SOMETHING_HERE e.g. iOS 10 or Android API 28

  • Operating System:

    • [ ] MacOS, version: N/A

    • [ ] Windows, version: N/A

    • [ ] Other, please specify: N/A

  • Build Tools:

    • ADD_SOMETHING_HERE e.g. Xcode 10, Android Studio 3.2

  • React Native version:

    • ADD_SOMETHING_HERE

  • React Native Firebase library version:

    • ADD_SOMETHING_HERE

  • Firebase module(s) you're using that has the issue:

    • [ ] N/A

    • [ ] Authentication

    • [ ] Analytics

    • [ ] Cloud Firestore

    • [ ] Cloud Messaging (FCM)

    • [ ] Crashlytics

    • [ ] Dynamic Links

    • [ ] Functions Callable

    • [ ] Invites

    • [ ] Instance ID

    • [ ] Notifications

    • [ ] Performance Monitoring

    • [x ] Realtime Database

    • [ ] Remote Config

    • [ ] Storage

  • Are you using TypeScript?

    • [x] No

    • [ ] Yes, version: N/A

  • Are you using Expo, e.g. ExpoKit?

    • [x] No

    • [ ] Yes, I've _not_ ejected

    • [ ] Yes, but I have ejected to ExpoKit

    • [ ] Yes, but I have ejected to vanilla React Native

    • Expo version: N/A




Think react-native-firebase is great? Please consider supporting the project with any of the below:

All 5 comments

@gvetsa I don't know if it helps, but I had the same issue, upgraded build tools and gradle as explained in the release notes, but it didn't fix the issue until I uninstalled the app from my phone, cleaned all intermediate gradle build files, and rebuilt the app. It seems to work for me now.

Edit: actually, scrap that, sorry. I still have the issue, but only with Live Reload.

Sorry, it is my coding issue. It is working. Closing the issue.

@gvetsa can you share what your mistake was? It might help me (and others?) fix my problem :)

@laurentS As per your request, this is what happened with my code.Its a silly coding mistake on my side.
i am using redux-persist to save the data on the device. i have two routes defined in my code.
1) If the User is not authenticated, then authenticate and then create listeners for listening to changes from firebase
2) If the user is authenticated, fetch the data from device Async storage and register for listener for any upcoming messages.
The part i missed is i forgot to re-register for listeners on reload. So i am not getting any messages or changes from firebase.

@laurentS As per your request, this is what happened with my code.Its a silly coding mistake on my side.
i am using redux-persist to save the data on the device. i have two routes defined in my code.

  1. If the User is not authenticated, then authenticate and then create listeners for listening to changes from firebase
  2. If the user is authenticated, fetch the data from device Async storage and register for listener for any upcoming messages.
    The part i missed is i forgot to re-register for listeners on reload. So i am not getting any messages or changes from firebase.

Can you please explain how did you re-register listeners?

Was this page helpful?
0 / 5 - 0 ratings