Closed Manouli closed 5 years ago
I am having the same issue. Documents created from Android do not appear on iOS, and vice versa. Any ideas anyone?
After spending more time debugging this it seems that when I remove this line from the code the onSnapshot works fine
Before:
this.channelRef = dbRef
.where('users', 'array-contains', props.user)
.orderBy('dateUpdated', 'desc');
After:
this.channelRef = dbRef
.orderBy('dateUpdated', 'desc');
So when doing .where()
the onSnapshot does not seem to work. Any ideas on how to fix that? Or maybe an alternative way?
Thanks a lot in advance.
Having the same issue here too 👎
@Manouli please could you provide me with a sample of your data and a full example of the code that I can use to create a reproducible test and look if there's anything in RNFirebase causing the issue or if it's the Native SDKs.
Thanks in advance!
Loving react-native-firebase
and the support we provide? Please consider supporting us with any of the below:
React Native Firebase
and Invertase
on Twitter @Salakar First of all thank you for getting back to me.
Here is a screenshot of data structure inside my database.
Also here is a screenshot to demonstrate that I m getting different data on the two different simulators. All 3 channels should be listed but I m getting only the ones that each simulator has created. iPhone has created 1 and Android 2.
Here is a code example to replicate this functionality. Make sure you create channels on each simulator and have them connected on the same time.
I have put some comments in the code too to help you even further but I think the example is plain enough.
Let me know if you need any further info.
Code:
import React from 'react';
import firebase from 'react-native-firebase';
import { View, FlatList, ScrollView, StyleSheet, Text } from 'react-native';
export default class ChannelList extends React.PureComponent {
// Swap the id 88 with the id that you want to use.
// Have to simulators running.
// 1 for iOS and 1 for Android.
// Create channels from each simulator.
// Watch the snapshot bug happening.
// Removing the .where('users', 'array-contains', 88) lists all the channels
// Note that when we have same simulators or devices ios with ios or android
// with android it works as expected.
constructor(props) {
super(props);
this.state = {
channels: [],
};
this.channelRef = firebase.firestore()
.collection('channels')
.where('users', 'array-contains', 88) // Swap for any id just a placeholder
.orderBy('dateUpdated', 'desc');
this.channelWatcher = null;
}
componentDidMount() {
this.channelWatcher = this.channelRef.onSnapshot(this.onChannelUpdate);
}
componentWillUnmount() {
this.channelWatcher();
}
onChannelUpdate = (snapshot) => {
const channels = snapshot.docs.map(docSnapshot => ({
id: docSnapshot.id,
...docSnapshot.data(),
}));
this.setState({
channels,
});
};
createChannel = channel => firebase.firestore()
.collection('channels')
.add(channel)
.then(document => document)
.catch((error) => {
console.error('Error adding document: ', error);
});
renderChannel = item => (
<Text>{item.name}</Text>
);
renderChannels = () => {
const { channels } = this.state;
const keyExtractor = item => `${item.id}`;
// Create a new channel each time to test it properly with your own user ids
// I am using 88 as my id
const channel = {
createdBy: {
id: 88,
},
dateUpdated: new Date(),
name: 'New channel',
users: [88, 100],
};
return (
<ScrollView style={styles.scrollView}>
<FlatList
keyExtractor={keyExtractor}
data={channels}
renderItem={({ item }) => this.renderChannel(item)}
/>
<Text
style={styles.addButton}
onPress={() => this.createChannel(channel)}
>
Add channel
</Text>
</ScrollView>
);
}
render() {
return (
<View style={{ flex: 1 }}>
<View style={styles.messageContainer}>
{ this.renderChannels() }
</View>
</View>
);
}
}
const styles = StyleSheet.create({
addButton: {
width: 200,
padding: 10,
textAlign: 'center',
backgroundColor: 'green',
color: 'white',
},
messageContainer: {
flex: 1,
},
scrollView: {
marginTop: 20,
flex: 1,
},
channelsContainer: {
marginTop: 20,
flex: 1,
},
});
Hello 👋, this issue has been automatically marked as stale because it has not had activity for quite some time. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.
Hello 👋, to help manage issues we automatically close stale issues. This issue has been automatically marked as stale because it has not had activity for quite some time. Has this issue been fixed, or does it still require the community's attention?
This issue will be closed in 15 days if no further activity occurs. Thank you for your contributions.
Same here. onSnapshot doesn't work after a while.
Hello 👋, to help manage issues we automatically close stale issues. This issue has been automatically marked as stale because it has not had activity for quite some time. Has this issue been fixed, or does it still require the community's attention?
This issue will be closed in 15 days if no further activity occurs. Thank you for your contributions.
Closing this issue after a prolonged period of inactivity. If this is still present in the latest release, please feel free to create a new issue with up-to-date information.
still having the same issue, using:
package.json
"react-native-firebase": "5.5.6"
android/app/build.gradle
implementation "com.google.firebase:firebase-firestore:19.0.0"
its not working, same issue here, please help
I'm having the same issue. I don't even use .where - it only fetches the data the first time, and there's no listening to updates.
I am also facing the same issue when trying to filter data based upon created_at.
In my experience no one has the same issue. There is always some difference in the combo of project setup, versions in use, platforms reproduced on, APIs used and code. Please open a new issue with full details and a way to reproduce the problem and we may examine
Issue
I am trying to create a chat system using react native firebase firestore.
I am facing a problem on my channel list where the snapshots don't work as expected when two different platforms are using the chat.
When an ios is using it and another ios is using too we have no issues. The same goes for android. When two android are being used the snapshots update properly.
However when I have ios with android the snapshots are not being called propely.
So this lists my channels properly
I am creating a snapshot listener inside my react native component's constructor.
Then inside my componentDidMount
this.channelWatcher = this.channelRef.onSnapshot(this.onChannelUpdate);
And this is the onChannelUpdate
When I have the same platform it works smoothly. When I have two different platforms it removes the channels that get updated depending on which platform is updating the channels. So if android updates the channel Android would then see the channel and the iOS won't and the opposite is happening as well. Any ideas what could be causing this?
I am pretty sure that that this is a package specific issue because its not happening on the web.
Project Files
iOS
ios/Podfile
:AppDelegate.m
:Android
android/build.gradle
:android/app/build.gradle
:android/settings.gradle
:MainApplication.java
:AndroidManifest.xml
:Environment
ADD_SOMETHING_HERE
e.g. iOS 10 or Android API 28N/A
N/A
N/A
Xcode 10
React Native
version:0.57.8
React Native Firebase
library version:5.2.0
Firebase
module(s) you're using that has the issue:TypeScript
?N/A
ExpoKit
?ExpoKit
N/A
Think
react-native-firebase
is great? Please consider supporting the project with any of the below:React Native Firebase
andInvertase
on Twitter