invertase / react-native-firebase

šŸ”„ A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.66k stars 2.21k forks source link

NULL date from firestore #1869

Closed selyon closed 5 years ago

selyon commented 5 years ago

Issue

Every query that get data from firestore return null dates. In firestore the dates are timestamp fields ( see attachment for examples) dates

Project Files

This is the list of my dependencies, if it's usefull

"dependencies": { "moment": "^2.24.0", "native-base": "^2.8.1", "react": "16.6.1", "react-moment": "^0.8.4", "react-native": "0.57.6", "react-native-device-info": "^0.24.3", "react-native-firebase": "^5.2.1", "react-native-gifted-chat": "^0.6.0", "react-native-image-picker": "^0.28.0", "react-native-mauron85-background-geolocation": "^0.5.0-alpha.50", "react-native-navigation": "^1.1.493", "react-native-vector-icons": "^6.1.0", "react-redux": "^5.1.1", "redux": "^4.0.1", "rn-fetch-blob": "^0.10.15" }

I only work with Android at the moment

Android

android/build.gradle:

apply plugin: "com.android.application"

import com.android.build.OutputFile

project.ext.react = [ entryFile: "index.js" ]

apply from: "../../node_modules/react-native/react.gradle"

def enableSeparateBuildPerCPUArchitecture = false

def enableProguardInReleaseBuilds = false

android { compileSdkVersion 27 buildToolsVersion '28.0.3'

defaultConfig {
    applicationId ""
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode 1
    versionName "1.0"
    ndk {
        abiFilters "armeabi-v7a", "x86"
    }
    multiDexEnabled true
}
splits {
    abi {
        reset()
        enable enableSeparateBuildPerCPUArchitecture
        universalApk false  // If true, also generate a universal APK
        include "armeabi-v7a", "x86"
    }
}
buildTypes {
    release {
        minifyEnabled enableProguardInReleaseBuilds
        proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
    }
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
    variant.outputs.each { output ->
        // For each separate APK per architecture, set a unique version code as described here:
        // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
        def versionCodes = ["armeabi-v7a":1, "x86":2]
        def abi = output.getFilter(OutputFile.ABI)
        if (abi != null) {  // null for the universal-debug, universal-release variants
            output.versionCodeOverride =
                    versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
        }
    }
}

}

dependencies { implementation project(':react-native-image-picker') implementation project(':rn-fetch-blob') implementation project(':react-native-device-info') implementation fileTree(dir: "libs", include: ["*.jar"]) implementation "com.facebook.react:react-native:+" // From node_modules implementation project(':react-native-firebase') implementation project(':react-native-vector-icons') implementation project(':react-native-navigation') implementation project(':react-native-mauron85-background-geolocation') implementation "com.android.support:appcompat-v7:27.1.1" implementation 'com.android.support:support-v4:27.1.1' implementation 'com.android.support:design:27.1.1' implementation 'com.google.firebase:firebase-core:16.0.6' implementation 'com.google.firebase:firebase-auth:16.1.0' implementation "com.google.firebase:firebase-firestore:18.0.0" implementation 'com.google.firebase:firebase-database:16.0.6' implementation 'com.google.firebase:firebase-storage:16.0.5' implementation 'com.google.firebase:firebase-messaging:17.3.4' implementation 'com.google.android.gms:play-services-location:16.0.0' }

// 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' }

project.ext.vectoricons = [ iconFontNames: [ 'Ionicons.ttf' ] // Name of the font files you want to copy ]

apply from: "../../node_modules/react-native-vector-icons/fonts.gradle" apply plugin: 'com.google.gms.google-services'

android/app/build.gradle:

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

buildscript { ext { buildToolsVersion = "27.0.3" minSdkVersion = 16 compileSdkVersion = 27 targetSdkVersion = 26 supportLibVersion = "27.1.1" googlePlayServicesVersion = "11.8.0" gradle3EXPERIMENTAL = "yes" oreoEXPERIMENTAL = "yes" } repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.3.0' classpath 'com.google.gms:google-services:4.2.0' // 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' } } }

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

android/settings.gradle:

rootProject.name = 'overmoverDev' include ':react-native-image-picker' project(':react-native-image-picker').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-image-picker/android') include ':app'

include ':react-native-device-info' project(':react-native-device-info').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-device-info/android')

include ':react-native-firebase' project(':react-native-firebase').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-firebase/android')

include ':react-native-vector-icons' project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android')

include ':react-native-navigation' project(':react-native-navigation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-navigation/android/app/')

include ':react-native-mauron85-background-geolocation-common' project(':react-native-mauron85-background-geolocation-common').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-mauron85-background-geolocation/android/common') include ':react-native-mauron85-background-geolocation' project(':react-native-mauron85-background-geolocation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-mauron85-background-geolocation/android/lib')

include ':rn-fetch-blob' project(':rn-fetch-blob').projectDir = new File(rootProject.projectDir, '../node_modules/rn-fetch-blob/android')

MainApplication.java:

package com.selyon.overmoverdev;

import com.facebook.react.ReactPackage;

import com.oblador.vectoricons.VectorIconsPackage; import com.reactnativenavigation.NavigationApplication; import com.reactnativenavigation.bridge.NavigationReactPackage; import io.invertase.firebase.RNFirebasePackage; import io.invertase.firebase.auth.RNFirebaseAuthPackage; import io.invertase.firebase.firestore.RNFirebaseFirestorePackage; import io.invertase.firebase.database.RNFirebaseDatabasePackage; import io.invertase.firebase.storage.RNFirebaseStoragePackage; import io.invertase.firebase.messaging.RNFirebaseMessagingPackage; import io.invertase.firebase.notifications.RNFirebaseNotificationsPackage; import com.marianhello.bgloc.react.BackgroundGeolocationPackage; import com.learnium.RNDeviceInfo.RNDeviceInfo; import com.imagepicker.ImagePickerPackage; import com.RNFetchBlob.RNFetchBlobPackage;

import java.util.Arrays; import java.util.List;

import com.google.firebase.database.FirebaseDatabase;

public class MainApplication extends NavigationApplication {

@Override
public void onCreate(){
    super.onCreate();
    //FirebaseDatabase.getInstance().setPersistenceEnabled(true);
}

@Override
public boolean isDebug() {
  // Make sure you are using BuildConfig from your own application
  return BuildConfig.DEBUG;
}

protected List<ReactPackage> getPackages() {
    // Add additional packages you require here
    // No need to add RnnPackage and MainReactPackage
    return Arrays.<ReactPackage>asList(
        new VectorIconsPackage(),
        new NavigationReactPackage(),
        new RNFirebasePackage(),
        new RNFirebaseAuthPackage(),
        new RNFirebaseFirestorePackage(),
        new RNFirebaseDatabasePackage(),
        new RNFirebaseStoragePackage(),
        new BackgroundGeolocationPackage(),
        new RNDeviceInfo(),
        new ImagePickerPackage(),
        new RNFetchBlobPackage(),
        new RNFirebaseMessagingPackage(),
        new RNFirebaseNotificationsPackage()
    );
}

@Override
public List<ReactPackage> createAdditionalReactPackages() {
    return getPackages();
}

}

AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

<application
  android:name=".MainApplication"
  android:label="@string/app_name"
  android:icon="@mipmap/ic_launcher"
  android:allowBackup="false"
  android:windowSoftInputMode="adjustResize"
  android:theme="@style/AppTheme"
    tools:ignore="GoogleAppIndexingWarning">
  <activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
    android:windowSoftInputMode="adjustResize">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
  </activity>
  <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />

    <service android:name="io.invertase.firebase.messaging.RNFirebaseBackgroundMessagingService" />
    <service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>
    <service android:name="io.invertase.firebase.messaging.RNFirebaseInstanceIdService">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
        </intent-filter>
    </service>
</application>


Environment


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

selyon commented 5 years ago

The problem is the version of the firebase-firestore library. With update 18.0.0 they changed the behaviour of timestamp fields:

The timestampsInSnapshotsEnabled setting is now enabled by default. Timestamp fields that read from a DocumentSnapshot are now returned as Timestamp objects instead of Date objects. This is a breaking change; developers must update any code that expects to receive a Date object

benfontan commented 5 years ago

Yes, but this option (managing timestamp as needed for firestore) is still marked as unsupported in RN Firebase documentation.

Salakar commented 5 years ago

Hey, Is there any reason why you're using version 18 of the Android SDK when the docs specifically say 17.1.5? https://rnfirebase.io/docs/v5.x.x/firestore/android

Version 18 of the Android SDK is not yet supported. Likewise for iOS, you should use <= v5.15 of the pods.

We're working on adding support

selyon commented 5 years ago

Is there any reason why you're using version 18 when the docs specifically say 17.1.5? https://rnfirebase.io/docs/v5.x.x/firestore/android

Version 18 SDK is not yet supported.

Android is not mentioned here, it says 17.1.5 only in the example of the installation guide and it's not written that it's the last version supported. I always update my libraries to the last version if i can, that's why i tried version 18. immagine

tu55eladd commented 5 years ago

Had the same issue on IOS in version 5.16 of 'Firebase/Firestore', works when i downgraded to 5.15

zacwasielewski commented 5 years ago

Downgrading to 5.15 worked for me, too.

Salakar commented 5 years ago

@selyon, the version is shown in the dependency example code on the link above as 17.1.5, the readme on the root of the repo is for Google play services SDK which is different.

I can see how this can cause some confusion so I think we'll remove the versions from the root and refrer to them specifically in each module. Sorry for any confusion šŸ™ˆ

felipap commented 5 years ago

Also experienced this for iOS. Downgraded the Firebase/Firestore pod to 5.15 and it worked.

stale[bot] commented 5 years ago

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.

Salakar commented 5 years ago

Hey all, please could you try the recently release v5.3.0 version of this library.

Changelog is here: https://rnfirebase.io/docs/v5.x.x/releases/v5.3.x

SimonDrew2018 commented 5 years ago

Did anyone actually have to change anything for this to work again? I'm getting the same issue where Timestamp is coming back as NULL but I can see it in the firebase back end. Do I have to do any converting in the code?

iOS: react-native-firebase v5.5.6

pod 'Firebase/Core', '~> 6.3.0' pod 'Firebase/Auth', '~> 6.3.0' pod 'Firebase/Firestore', '~> 6.3.0'