Skip to content

Commit ba22281

Browse files
committed
Merge branch 'v5.x.x' into ios_cocoapods_transient_framework_fix
* v5.x.x: 5.4.0 [tests] disable admob (has a new runtime check that causes a crash as we don't have a valid admob identifier) [android] update firebase sdk versions - forced to upgrade due to invertase#2122 [android][internals] rework internals utils to better support JSONObject/Array values [GENERAL][BUGFIX][build] - patch v5 build toolchains for XCode10.2 & RN0.59 compatibility (invertase#2166) [tests] update podfile lock [tests] sync v5.x.x local changes [tests] sync v5.x.x local changes [docs] update link [STORAGE][BUGFIX][ANDROID] - Preserve `file://` prefix [JS][BUGFIX] [package.json] - Fix build on Windows (BABEL_ENV error) [Messaging] Add null check to acquire WakeLock on Android (invertase#2092) [TYPES][BUGFIX][AUTHENTICATION] - Change type PhoneAuthSnapshot.Error to NativeError
2 parents fb3f2a2 + 82952b4 commit ba22281

25 files changed

+1614
-680
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Using the native Firebase SDKs with **React Native Firebase** allows you to cons
7070

7171
## Documentation
7272

73-
To check out our latest docs, visit [https://invertase.io/oss/react-native-firebase](https://invertase.io/oss/react-native-firebase)
73+
To check out our latest docs, visit [https://rnfirebase.io/docs](https://rnfirebase.io/docs)
7474

7575
## Questions
7676

android/build.gradle

+12-12
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ dependencies {
144144

145145
// Required dependencies
146146
//noinspection GradleCompatible
147-
compileOnly "com.google.firebase:firebase-core:16.0.8"
147+
compileOnly "com.google.firebase:firebase-core:16.0.9"
148148
compileOnly "com.google.android.gms:play-services-base:16.1.0"
149149

150150
/* -------------------------
@@ -158,27 +158,27 @@ dependencies {
158158
exclude group: 'com.android.support', module: 'customtabs'
159159
}
160160
// Authentication
161-
compileOnly "com.google.firebase:firebase-auth:16.2.1"
161+
compileOnly "com.google.firebase:firebase-auth:17.0.0"
162162
// Analytics
163-
compileOnly "com.google.firebase:firebase-analytics:16.4.0"
163+
compileOnly "com.google.firebase:firebase-analytics:16.5.0"
164164
// Performance Monitoring
165-
compileOnly "com.google.firebase:firebase-perf:16.2.5"
165+
compileOnly "com.google.firebase:firebase-perf:16.2.4"
166166
// Remote Config
167-
compileOnly "com.google.firebase:firebase-config:16.5.0"
167+
compileOnly "com.google.firebase:firebase-config:17.0.0"
168168
// Cloud Storage
169-
compileOnly "com.google.firebase:firebase-storage:16.1.0"
169+
compileOnly "com.google.firebase:firebase-storage:17.0.0"
170170
// Invites
171-
compileOnly "com.google.firebase:firebase-invites:16.1.1"
171+
compileOnly "com.google.firebase:firebase-invites:17.0.0"
172172
// Dynamic Links
173-
compileOnly "com.google.firebase:firebase-dynamic-links:16.1.8"
173+
compileOnly "com.google.firebase:firebase-dynamic-links:17.0.0"
174174
// Real-time Database
175-
compileOnly "com.google.firebase:firebase-database:16.1.0"
175+
compileOnly "com.google.firebase:firebase-database:17.0.0"
176176
// Cloud Functions
177-
compileOnly "com.google.firebase:firebase-functions:16.3.0"
177+
compileOnly "com.google.firebase:firebase-functions:17.0.0"
178178
// Cloud Firestore
179-
compileOnly "com.google.firebase:firebase-firestore:18.2.0"
179+
compileOnly "com.google.firebase:firebase-firestore:19.0.0"
180180
// Cloud Messaging / FCM
181-
compileOnly "com.google.firebase:firebase-messaging:17.5.0"
181+
compileOnly "com.google.firebase:firebase-messaging:18.0.0"
182182
// Crashlytics
183183
compileOnly('com.crashlytics.sdk.android:crashlytics:2.9.5@aar') {
184184
transitive = true

android/src/main/java/io/invertase/firebase/Utils.java

+176-54
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@
88
import com.facebook.react.bridge.ReactContext;
99
import com.facebook.react.bridge.ReadableArray;
1010
import com.facebook.react.bridge.ReadableMap;
11+
import com.facebook.react.bridge.WritableArray;
1112
import com.facebook.react.bridge.WritableMap;
1213
import com.facebook.react.common.LifecycleState;
1314
import com.facebook.react.modules.core.DeviceEventManagerModule;
1415

16+
import org.json.JSONArray;
17+
import org.json.JSONException;
18+
import org.json.JSONObject;
19+
1520
import java.text.SimpleDateFormat;
1621
import java.util.Calendar;
1722
import java.util.Date;
23+
import java.util.Iterator;
1824
import java.util.List;
1925
import java.util.Locale;
2026
import java.util.Map;
@@ -48,62 +54,178 @@ public static void sendEvent(final ReactContext context, final String eventName,
4854
}
4955
}
5056

51-
/**
52-
* Takes a value and calls the appropriate setter for its type on the target map + key
53-
*
54-
* @param key String key to set on target map
55-
* @param value Object value to set on target map
56-
* @param map WritableMap target map to write the value to
57-
*/
57+
public static WritableMap jsonObjectToWritableMap(JSONObject jsonObject) throws JSONException {
58+
Iterator<String> iterator = jsonObject.keys();
59+
WritableMap writableMap = Arguments.createMap();
60+
61+
while (iterator.hasNext()) {
62+
String key = iterator.next();
63+
Object value = jsonObject.get(key);
64+
if (value instanceof Float || value instanceof Double) {
65+
writableMap.putDouble(key, jsonObject.getDouble(key));
66+
} else if (value instanceof Number) {
67+
writableMap.putInt(key, jsonObject.getInt(key));
68+
} else if (value instanceof String) {
69+
writableMap.putString(key, jsonObject.getString(key));
70+
} else if (value instanceof JSONObject) {
71+
writableMap.putMap(key, jsonObjectToWritableMap(jsonObject.getJSONObject(key)));
72+
} else if (value instanceof JSONArray) {
73+
writableMap.putArray(key, jsonArrayToWritableArray(jsonObject.getJSONArray(key)));
74+
} else if (value == JSONObject.NULL) {
75+
writableMap.putNull(key);
76+
}
77+
}
78+
79+
return writableMap;
80+
}
81+
82+
public static WritableArray jsonArrayToWritableArray(JSONArray jsonArray) throws JSONException {
83+
WritableArray writableArray = Arguments.createArray();
84+
85+
for (int i = 0; i < jsonArray.length(); i++) {
86+
Object value = jsonArray.get(i);
87+
if (value instanceof Float || value instanceof Double) {
88+
writableArray.pushDouble(jsonArray.getDouble(i));
89+
} else if (value instanceof Number) {
90+
writableArray.pushInt(jsonArray.getInt(i));
91+
} else if (value instanceof String) {
92+
writableArray.pushString(jsonArray.getString(i));
93+
} else if (value instanceof JSONObject) {
94+
writableArray.pushMap(jsonObjectToWritableMap(jsonArray.getJSONObject(i)));
95+
} else if (value instanceof JSONArray) {
96+
writableArray.pushArray(jsonArrayToWritableArray(jsonArray.getJSONArray(i)));
97+
} else if (value == JSONObject.NULL) {
98+
writableArray.pushNull();
99+
}
100+
}
101+
return writableArray;
102+
}
103+
104+
public static WritableMap mapToWritableMap(Map<String, Object> value) {
105+
WritableMap writableMap = Arguments.createMap();
106+
107+
for (Map.Entry<String, Object> entry : value.entrySet()) {
108+
mapPutValue(entry.getKey(), entry.getValue(), writableMap);
109+
}
110+
111+
return writableMap;
112+
}
113+
114+
private static WritableArray listToWritableArray(List<Object> objects) {
115+
WritableArray writableArray = Arguments.createArray();
116+
for (Object object : objects) {
117+
arrayPushValue(object, writableArray);
118+
}
119+
return writableArray;
120+
}
121+
122+
@SuppressWarnings("unchecked")
123+
public static void arrayPushValue(@Nullable Object value, WritableArray array) {
124+
if (value == null || value == JSONObject.NULL) {
125+
array.pushNull();
126+
return;
127+
}
128+
129+
String type = value.getClass().getName();
130+
switch (type) {
131+
case "java.lang.Boolean":
132+
array.pushBoolean((Boolean) value);
133+
break;
134+
case "java.lang.Long":
135+
Long longVal = (Long) value;
136+
array.pushDouble((double) longVal);
137+
break;
138+
case "java.lang.Float":
139+
float floatVal = (float) value;
140+
array.pushDouble((double) floatVal);
141+
break;
142+
case "java.lang.Double":
143+
array.pushDouble((double) value);
144+
break;
145+
case "java.lang.Integer":
146+
array.pushInt((int) value);
147+
break;
148+
case "java.lang.String":
149+
array.pushString((String) value);
150+
break;
151+
case "org.json.JSONObject$1":
152+
try {
153+
array.pushMap(jsonObjectToWritableMap((JSONObject) value));
154+
} catch (JSONException e) {
155+
array.pushNull();
156+
}
157+
break;
158+
case "org.json.JSONArray$1":
159+
try {
160+
array.pushArray(jsonArrayToWritableArray((JSONArray) value));
161+
} catch (JSONException e) {
162+
array.pushNull();
163+
}
164+
break;
165+
default:
166+
if (List.class.isAssignableFrom(value.getClass())) {
167+
array.pushArray(listToWritableArray((List<Object>) value));
168+
} else if (Map.class.isAssignableFrom(value.getClass())) {
169+
array.pushMap(mapToWritableMap((Map<String, Object>) value));
170+
} else {
171+
Log.d(TAG, "utils:arrayPushValue:unknownType:" + type);
172+
array.pushNull();
173+
}
174+
}
175+
}
176+
58177
@SuppressWarnings("unchecked")
59178
public static void mapPutValue(String key, @Nullable Object value, WritableMap map) {
60-
if (value == null) {
179+
if (value == null || value == JSONObject.NULL) {
61180
map.putNull(key);
62-
} else {
63-
String type = value
64-
.getClass()
65-
.getName();
66-
switch (type) {
67-
case "java.lang.Boolean":
68-
map.putBoolean(key, (Boolean) value);
69-
break;
70-
case "java.lang.Long":
71-
Long longVal = (Long) value;
72-
map.putDouble(key, (double) longVal);
73-
break;
74-
case "java.lang.Float":
75-
float floatVal = (float) value;
76-
map.putDouble(key, (double) floatVal);
77-
break;
78-
case "java.lang.Double":
79-
map.putDouble(key, (Double) value);
80-
break;
81-
case "java.lang.Integer":
82-
map.putInt(key, (int) value);
83-
break;
84-
case "java.lang.String":
85-
map.putString(key, (String) value);
86-
break;
87-
case "org.json.JSONObject$1":
88-
map.putString(key, value.toString());
89-
break;
90-
default:
91-
if (List.class.isAssignableFrom(value.getClass())) {
92-
map.putArray(key, Arguments.makeNativeArray((List<Object>) value));
93-
} else if (Map.class.isAssignableFrom(value.getClass())) {
94-
WritableMap childMap = Arguments.createMap();
95-
Map<String, Object> valueMap = (Map<String, Object>) value;
96-
97-
for (Map.Entry<String, Object> entry : valueMap.entrySet()) {
98-
mapPutValue(entry.getKey(), entry.getValue(), childMap);
99-
}
100-
101-
map.putMap(key, childMap);
102-
} else {
103-
Log.d(TAG, "utils:mapPutValue:unknownType:" + type);
104-
map.putNull(key);
105-
}
106-
}
181+
return;
182+
}
183+
184+
String type = value.getClass().getName();
185+
switch (type) {
186+
case "java.lang.Boolean":
187+
map.putBoolean(key, (Boolean) value);
188+
break;
189+
case "java.lang.Long":
190+
Long longVal = (Long) value;
191+
map.putDouble(key, (double) longVal);
192+
break;
193+
case "java.lang.Float":
194+
float floatVal = (float) value;
195+
map.putDouble(key, (double) floatVal);
196+
break;
197+
case "java.lang.Double":
198+
map.putDouble(key, (double) value);
199+
break;
200+
case "java.lang.Integer":
201+
map.putInt(key, (int) value);
202+
break;
203+
case "java.lang.String":
204+
map.putString(key, (String) value);
205+
break;
206+
case "org.json.JSONObject$1":
207+
try {
208+
map.putMap(key, jsonObjectToWritableMap((JSONObject) value));
209+
} catch (JSONException e) {
210+
map.putNull(key);
211+
}
212+
break;
213+
case "org.json.JSONArray$1":
214+
try {
215+
map.putArray(key, jsonArrayToWritableArray((JSONArray) value));
216+
} catch (JSONException e) {
217+
map.putNull(key);
218+
}
219+
break;
220+
default:
221+
if (List.class.isAssignableFrom(value.getClass())) {
222+
map.putArray(key, listToWritableArray((List<Object>) value));
223+
} else if (Map.class.isAssignableFrom(value.getClass())) {
224+
map.putMap(key, mapToWritableMap((Map<String, Object>) value));
225+
} else {
226+
Log.d(TAG, "utils:mapPutValue:unknownType:" + type);
227+
map.putNull(key);
228+
}
107229
}
108230
}
109231

@@ -164,7 +286,7 @@ public static boolean isAppInForeground(Context context) {
164286
if (
165287
appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND
166288
&& appProcess.processName.equals(packageName)
167-
) {
289+
) {
168290
ReactContext reactContext;
169291

170292
try {

android/src/main/java/io/invertase/firebase/messaging/RNFirebaseInstanceIdService.java

-24
This file was deleted.

android/src/main/java/io/invertase/firebase/messaging/RNFirebaseMessagingService.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.invertase.firebase.messaging;
22

33
import android.content.Intent;
4+
import android.content.ComponentName;
45
import android.support.v4.content.LocalBroadcastManager;
56
import android.util.Log;
67

@@ -58,10 +59,10 @@ public void onMessageReceived(RemoteMessage message) {
5859
RNFirebaseBackgroundMessagingService.class
5960
);
6061
headlessIntent.putExtra("message", message);
61-
this
62-
.getApplicationContext()
63-
.startService(headlessIntent);
64-
HeadlessJsTaskService.acquireWakeLockNow(this.getApplicationContext());
62+
ComponentName name = this.getApplicationContext().startService(headlessIntent);
63+
if (name != null) {
64+
HeadlessJsTaskService.acquireWakeLockNow(this.getApplicationContext());
65+
}
6566
} catch (IllegalStateException ex) {
6667
Log.e(
6768
TAG,

android/src/main/java/io/invertase/firebase/notifications/RNFirebaseBackgroundNotificationActionReceiver.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.content.BroadcastReceiver;
44
import android.content.Context;
55
import android.content.Intent;
6+
import android.content.ComponentName;
67
import android.os.Bundle;
78
import android.support.v4.app.RemoteInput;
89

@@ -62,8 +63,10 @@ public void onReceive(Context context, Intent intent) {
6263
if (remoteInput != null) {
6364
serviceIntent.putExtra("results", remoteInput);
6465
}
65-
context.startService(serviceIntent);
66-
HeadlessJsTaskService.acquireWakeLockNow(context);
66+
ComponentName name = context.startService(serviceIntent);
67+
if (name != null) {
68+
HeadlessJsTaskService.acquireWakeLockNow(context);
69+
}
6770
}
6871
}
6972
}

0 commit comments

Comments
 (0)