I am using React Native Firebase and I am trying to enable persistence for my app.
On my Android onCreate:
public void onCreate() {
super.onCreate();
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
SoLoader.init(this, /* native exopackage */ false);
}
For some reason when I am online and I kill my app and reopen, the images seems to reload and it takes long to appear..If I turn the net off they will come up instantly showing that the offline data actually works.
How do I enable the persistence for the firestore so it will load the unchanged data from the cache instantly?
I saw the documentation which shows that I would need to add this code for the android:
FirebaseFirestoreSettings settings = new FirebaseFirestoreSettings.Builder()
.setPersistenceEnabled(true)
.build();
db.setFirestoreSettings(settings);
but I have no idea how to integrate with the React Native Firebase as I am importing the RNFirebaseFirestorePackage
Any help would be appreciated!
import firestore from '@react-native-firebase/firestore'; const usersCollection = firestore(). collection('Users'); The collection method returns a CollectionReference class, which provides properties and methods to query and fetch the data from Cloud Firestore.
This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.
Note that Firebase Auth web sessions are single host origin and will be persisted for a single domain only. Indicates that the state will only persist in the current session or tab, and will be cleared when the tab or window in which the user authenticated is closed.
For react-native+firebase, one of my suggestion would be react-native-firebase which is bridging between JS and native framework.
Doing quick search, seems like you cannot directly - enable persistance.
You need to do it through Settings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With