sync with master

This commit is contained in:
Salakar 2018-03-28 16:28:19 +01:00
commit 9511b567b9
25 changed files with 392 additions and 240 deletions

View File

@ -2,16 +2,13 @@ buildscript {
ext.firebaseVersion = '12.0.0'
repositories {
jcenter()
mavenLocal()
maven {
url "https://maven.google.com"
}
google()
maven {
url 'https://maven.fabric.io/public'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.android.tools.build:gradle:3.1.0'
classpath 'io.fabric.tools:gradle:1.25.1'
}
}
@ -20,10 +17,10 @@ apply plugin: 'com.android.library'
android {
compileSdkVersion 27
buildToolsVersion "27.0.2"
buildToolsVersion "27.0.3"
defaultConfig {
minSdkVersion 16
targetSdkVersion 27
targetSdkVersion 26
versionCode 1
versionName "1.0"
multiDexEnabled true
@ -48,7 +45,6 @@ allprojects {
}
}
rootProject.gradle.buildFinished { buildResult ->
if (buildResult.getFailure() != null) {
try {
@ -79,31 +75,29 @@ rootProject.gradle.buildFinished { buildResult ->
logger.log(LogLevel.ERROR, "| |")
logger.log(LogLevel.ERROR, " ----------------------------------------------------------- ")
}
} catch (Exception exception) {
}
} catch (Exception exception) {}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
//noinspection GradleDynamicVersion
compile "com.facebook.react:react-native:+" // From node_modules
compile "com.android.support:support-v4:27.1.0"
compile 'me.leolin:ShortcutBadger:1.1.21@aar'
compile "com.google.android.gms:play-services-base:$firebaseVersion"
compile "com.google.firebase:firebase-core:$firebaseVersion"
compile "com.google.firebase:firebase-config:$firebaseVersion"
compile "com.google.firebase:firebase-auth:$firebaseVersion"
compile "com.google.firebase:firebase-database:$firebaseVersion"
compile "com.google.firebase:firebase-storage:$firebaseVersion"
compile "com.google.firebase:firebase-messaging:$firebaseVersion"
compile "com.google.firebase:firebase-crash:$firebaseVersion"
compile "com.google.firebase:firebase-perf:$firebaseVersion"
compile "com.google.firebase:firebase-ads:$firebaseVersion"
compile "com.google.firebase:firebase-firestore:$firebaseVersion"
compile "com.google.firebase:firebase-invites:$firebaseVersion"
compile('com.crashlytics.sdk.android:crashlytics:2.9.1@aar') {
// compile fileTree(include: ['*.jar'], dir: 'libs')
api "com.facebook.react:react-native:+" // From node_modules
api "com.android.support:support-v4:27.0.2"
compileOnly 'me.leolin:ShortcutBadger:1.1.21@aar'
compileOnly "com.google.android.gms:play-services-base:$firebaseVersion"
compileOnly "com.google.firebase:firebase-core:$firebaseVersion"
compileOnly "com.google.firebase:firebase-config:$firebaseVersion"
compileOnly "com.google.firebase:firebase-auth:$firebaseVersion"
compileOnly "com.google.firebase:firebase-database:$firebaseVersion"
compileOnly "com.google.firebase:firebase-storage:$firebaseVersion"
compileOnly "com.google.firebase:firebase-messaging:$firebaseVersion"
compileOnly "com.google.firebase:firebase-crash:$firebaseVersion"
compileOnly "com.google.firebase:firebase-perf:$firebaseVersion"
compileOnly "com.google.firebase:firebase-ads:$firebaseVersion"
compileOnly "com.google.firebase:firebase-firestore:$firebaseVersion"
compileOnly "com.google.firebase:firebase-invites:$firebaseVersion"
compileOnly('com.crashlytics.sdk.android:crashlytics:2.9.1@aar') {
transitive = true
}
}

View File

@ -596,8 +596,7 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
if (props.hasKey("photoURL")) {
String photoURLStr = props.getString("photoURL");
Uri uri = Uri.parse(photoURLStr);
profileBuilder.setPhotoUri(uri);
profileBuilder.setPhotoUri(photoURLStr == null ? null : Uri.parse(photoURLStr));
}
UserProfileChangeRequest profileUpdates = profileBuilder.build();
@ -1067,7 +1066,7 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
public void reauthenticateAndRetrieveDataWithCredential(String appName, String provider, String authToken, String authSecret, final Promise promise) {
reauthenticate(appName, provider, authToken, authSecret, promise, true);
}
public void reauthenticate(String appName, String provider, String authToken, String authSecret, final Promise promise, final boolean withData) {
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
final FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp);

View File

@ -18,6 +18,7 @@ import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.FirebaseApp;
import com.google.firebase.firestore.FirebaseFirestoreSettings;
import com.google.firebase.firestore.Transaction;
import com.google.firebase.firestore.DocumentReference;
import com.google.firebase.firestore.FieldValue;
@ -47,14 +48,42 @@ public class RNFirebaseFirestore extends ReactContextBaseJavaModule {
* REACT NATIVE METHODS
*/
/**
* @param enabled
*/
@ReactMethod
public void disableNetwork(String appName, final Promise promise) {
getFirestoreForApp(appName).disableNetwork().addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.d(TAG, "disableNetwork:onComplete:success");
promise.resolve(null);
} else {
Log.e(TAG, "disableNetwork:onComplete:failure", task.getException());
RNFirebaseFirestore.promiseRejectException(promise, (FirebaseFirestoreException)task.getException());
}
}
});
}
@ReactMethod
public void enableLogging(Boolean enabled) {
FirebaseFirestore.setLoggingEnabled(enabled);
}
@ReactMethod
public void enableNetwork(String appName, final Promise promise) {
getFirestoreForApp(appName).enableNetwork().addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.d(TAG, "enableNetwork:onComplete:success");
promise.resolve(null);
} else {
Log.e(TAG, "enableNetwork:onComplete:failure", task.getException());
RNFirebaseFirestore.promiseRejectException(promise, (FirebaseFirestoreException)task.getException());
}
}
});
}
@ReactMethod
public void collectionGet(String appName, String path, ReadableArray filters,

View File

@ -110,19 +110,37 @@ public class BundleJSONConverter {
SETTERS.put(JSONArray.class, new Setter() {
public void setOnBundle(Bundle bundle, String key, Object value) throws JSONException {
JSONArray jsonArray = (JSONArray) value;
// Empty list, can't even figure out the type, assume an ArrayList<String>
if (jsonArray.length() == 0) {
bundle.putStringArrayList(key, new ArrayList<String>());
return;
}
// Only strings are supported for now
if (jsonArray.get(0) instanceof String) {
ArrayList<String> stringArrayList = new ArrayList<String>();
// Assume an empty list is an ArrayList<String>
if (jsonArray.length() == 0 || jsonArray.get(0) instanceof String) {
ArrayList<String> stringArrayList = new ArrayList<>();
for (int i = 0; i < jsonArray.length(); i++) {
stringArrayList.add((String) jsonArray.get(i));
}
bundle.putStringArrayList(key, stringArrayList);
} else if (jsonArray.get(0) instanceof Integer) {
ArrayList<Integer> integerArrayList = new ArrayList<>();
for (int i = 0; i < jsonArray.length(); i++) {
integerArrayList.add((Integer) jsonArray.get(i));
}
bundle.putIntegerArrayList(key, integerArrayList);
} else if (jsonArray.get(0) instanceof Boolean) {
boolean[] booleanArray = new boolean[jsonArray.length()];
for (int i = 0; i < jsonArray.length(); i++) {
booleanArray[i] = (Boolean)jsonArray.get(i);
}
bundle.putBooleanArray(key, booleanArray);
} else if (jsonArray.get(0) instanceof Double) {
double[] doubleArray = new double[jsonArray.length()];
for (int i = 0; i < jsonArray.length(); i++) {
doubleArray[i] = (Double)jsonArray.get(i);
}
bundle.putDoubleArray(key, doubleArray);
} else if (jsonArray.get(0) instanceof Long) {
long[] longArray = new long[jsonArray.length()];
for (int i = 0; i < jsonArray.length(); i++) {
longArray[i] = (Long) jsonArray.get(i);
}
bundle.putLongArray(key, longArray);
} else if (jsonArray.get(0) instanceof JSONObject) {
ArrayList<Bundle> bundleArrayList = new ArrayList<>();
for (int i =0; i < jsonArray.length(); i++) {
@ -162,7 +180,11 @@ public class BundleJSONConverter {
JSONArray jsonArray = new JSONArray();
List<Object> listValue = (List<Object>) value;
for (Object objValue : listValue) {
if (objValue instanceof String) {
if (objValue instanceof String
|| objValue instanceof Integer
|| objValue instanceof Double
|| objValue instanceof Long
|| objValue instanceof Boolean) {
jsonArray.put(objValue);
} else if (objValue instanceof Bundle) {
jsonArray.put(convertToJSON((Bundle) objValue));

View File

@ -96,13 +96,15 @@ public class RNFirebaseMessaging extends ReactContextBaseJavaModule {
}
@ReactMethod
public void subscribeToTopic(String topic) {
public void subscribeToTopic(String topic, Promise promise) {
FirebaseMessaging.getInstance().subscribeToTopic(topic);
promise.resolve(null);
}
@ReactMethod
public void unsubscribeFromTopic(String topic) {
public void unsubscribeFromTopic(String topic, Promise promise) {
FirebaseMessaging.getInstance().unsubscribeFromTopic(topic);
promise.resolve(null);
}
private class MessageReceiver extends BroadcastReceiver {

View File

@ -35,11 +35,15 @@ public class RNFirebaseMessagingService extends FirebaseMessagingService {
// Broadcast it so it is only available to the RN Application
LocalBroadcastManager.getInstance(this).sendBroadcast(messagingEvent);
} else {
// If the app is in the background we send it to the Headless JS Service
Intent headlessIntent = new Intent(this.getApplicationContext(), RNFirebaseBackgroundMessagingService.class);
headlessIntent.putExtra("message", message);
this.getApplicationContext().startService(headlessIntent);
HeadlessJsTaskService.acquireWakeLockNow(this.getApplicationContext());
try {
// If the app is in the background we send it to the Headless JS Service
Intent headlessIntent = new Intent(this.getApplicationContext(), RNFirebaseBackgroundMessagingService.class);
headlessIntent.putExtra("message", message);
this.getApplicationContext().startService(headlessIntent);
HeadlessJsTaskService.acquireWakeLockNow(this.getApplicationContext());
} catch (IllegalStateException ex) {
Log.e(TAG, "Background messages will only work if the message priority is set to 'high'", ex);
}
}
}
}

View File

@ -64,7 +64,7 @@ public class RNFirebaseNotificationManager {
this.preferences = context.getSharedPreferences(PREFERENCES_KEY, Context.MODE_PRIVATE);
}
public void cancelAllNotifications() {
public void cancelAllNotifications(Promise promise) {
try {
Map<String, ?> notifications = preferences.getAll();
@ -72,16 +72,25 @@ public class RNFirebaseNotificationManager {
cancelAlarm(notificationId);
}
preferences.edit().clear().apply();
promise.resolve(null);
} catch (SecurityException e) {
// TODO: Identify what these situations are
// In some devices/situations cancelAllLocalNotifications can throw a SecurityException.
Log.e(TAG, e.getMessage());
promise.reject("notification/cancel_notifications_error", "Could not cancel notifications", e);
}
}
public void cancelNotification(String notificationId) {
cancelAlarm(notificationId);
preferences.edit().remove(notificationId).apply();
public void cancelNotification(String notificationId, Promise promise) {
try {
cancelAlarm(notificationId);
preferences.edit().remove(notificationId).apply();
} catch (SecurityException e) {
// TODO: Identify what these situations are
// In some devices/situations cancelAllLocalNotifications can throw a SecurityException.
Log.e(TAG, e.getMessage());
promise.reject("notification/cancel_notification_error", "Could not cancel notifications", e);
}
}
public void createChannel(ReadableMap channelMap) {
@ -162,12 +171,14 @@ public class RNFirebaseNotificationManager {
return array;
}
public void removeAllDeliveredNotifications() {
public void removeAllDeliveredNotifications(Promise promise) {
notificationManager.cancelAll();
promise.resolve(null);
}
public void removeDeliveredNotification(String notificationId) {
public void removeDeliveredNotification(String notificationId, Promise promise) {
notificationManager.cancel(notificationId.hashCode());
promise.resolve(null);
}
@ -236,6 +247,41 @@ public class RNFirebaseNotificationManager {
Double badgeIconType = android.getDouble("badgeIconType");
nb = nb.setBadgeIconType(badgeIconType.intValue());
}
if (android.containsKey("bigPicture")) {
Bundle bigPicture = android.getBundle("bigPicture");
NotificationCompat.BigPictureStyle bp = new NotificationCompat.BigPictureStyle();
Bitmap picture = getBitmap(bigPicture.getString("picture"));
if (picture != null) {
bp = bp.bigPicture(picture);
}
if (bigPicture.containsKey("largeIcon")) {
Bitmap largeIcon = getBitmap(bigPicture.getString("largeIcon"));
if (largeIcon != null) {
bp = bp.bigLargeIcon(largeIcon);
}
}
if (bigPicture.containsKey("contentTitle")) {
bp = bp.setBigContentTitle(bigPicture.getString("contentTitle"));
}
if (bigPicture.containsKey("summaryText")) {
bp = bp.setSummaryText(bigPicture.getString("summaryText"));
}
nb = nb.setStyle(bp);
}
if (android.containsKey("bigText")) {
Bundle bigText = android.getBundle("bigText");
NotificationCompat.BigTextStyle bt = new NotificationCompat.BigTextStyle();
bt.bigText(bigText.getString("text"));
if (bigText.containsKey("contentTitle")) {
bt = bt.setBigContentTitle(bigText.getString("contentTitle"));
}
if (bigText.containsKey("summaryText")) {
bt = bt.setSummaryText(bigText.getString("summaryText"));
}
nb = nb.setStyle(bt);
}
if (android.containsKey("category")) {
nb = nb.setCategory(android.getString("category"));
}
@ -352,12 +398,14 @@ public class RNFirebaseNotificationManager {
nb = nb.setUsesChronometer(android.getBoolean("usesChronometer"));
}
if (android.containsKey("vibrate")) {
double[] vibrate = android.getDoubleArray("vibrate");
long[] vibrateArray = new long[vibrate.length];
for (int i = 0; i < vibrate.length; i++) {
vibrateArray[i] = ((Double)vibrate[i]).longValue();
ArrayList<Integer> vibrate = android.getIntegerArrayList("vibrate");
if(vibrate != null) {
long[] vibrateArray = new long[vibrate.size()];
for (int i = 0; i < vibrate.size(); i++) {
vibrateArray[i] = vibrate.get(i).longValue();
}
nb = nb.setVibrate(vibrateArray);
}
nb = nb.setVibrate(vibrateArray);
}
if (android.containsKey("visibility")) {
Double visibility = android.getDouble("visibility");
@ -407,9 +455,8 @@ public class RNFirebaseNotificationManager {
Utils.sendEvent(reactContext, "notifications_notification_displayed", Arguments.fromBundle(notification));
}
} catch (Exception e) {
if (promise == null) {
Log.e(TAG, "Failed to send notification", e);
} else {
Log.e(TAG, "Failed to send notification", e);
if (promise != null) {
promise.reject("notification/display_notification_error", "Could not send notification", e);
}
}

View File

@ -62,13 +62,13 @@ public class RNFirebaseNotifications extends ReactContextBaseJavaModule implemen
}
@ReactMethod
public void cancelAllNotifications() {
notificationManager.cancelAllNotifications();
public void cancelAllNotifications(Promise promise) {
notificationManager.cancelAllNotifications(promise);
}
@ReactMethod
public void cancelNotification(String notificationId) {
notificationManager.cancelNotification(notificationId);
public void cancelNotification(String notificationId, Promise promise) {
notificationManager.cancelNotification(notificationId, promise);
}
@ReactMethod
@ -103,17 +103,17 @@ public class RNFirebaseNotifications extends ReactContextBaseJavaModule implemen
}
@ReactMethod
public void removeAllDeliveredNotifications() {
notificationManager.removeAllDeliveredNotifications();
public void removeAllDeliveredNotifications(Promise promise) {
notificationManager.removeAllDeliveredNotifications(promise);
}
@ReactMethod
public void removeDeliveredNotification(String notificationId) {
notificationManager.removeDeliveredNotification(notificationId);
public void removeDeliveredNotification(String notificationId, Promise promise) {
notificationManager.removeDeliveredNotification(notificationId, promise);
}
@ReactMethod
public void setBadge(int badge) {
public void setBadge(int badge, Promise promise) {
// Store the badge count for later retrieval
sharedPreferences.edit().putInt(BADGE_KEY, badge).apply();
if (badge == 0) {
@ -123,6 +123,7 @@ public class RNFirebaseNotifications extends ReactContextBaseJavaModule implemen
Log.d(TAG, "Apply badge count: " + badge);
ShortcutBadger.applyCount(this.getReactApplicationContext(), badge);
}
promise.resolve(null);
}
@ReactMethod

View File

@ -185,11 +185,36 @@ RCT_EXPORT_METHOD(transactionBegin:(NSString *)appDisplayName
* TRANSACTIONS END
*/
RCT_EXPORT_METHOD(disableNetwork:(NSString *)appDisplayName
resolver:(RCTPromiseResolveBlock) resolve
rejecter:(RCTPromiseRejectBlock) reject) {
FIRFirestore *firestore = [RNFirebaseFirestore getFirestoreForApp:appDisplayName];
[firestore disableNetworkWithCompletion:^(NSError * _Nullable error) {
if (error) {
[RNFirebaseFirestore promiseRejectException:reject error:error];
} else {
resolve(nil);
}
}];
}
RCT_EXPORT_METHOD(enableLogging:(BOOL)enabled) {
[FIRFirestore enableLogging:enabled];
}
RCT_EXPORT_METHOD(enableNetwork:(NSString *)appDisplayName
resolver:(RCTPromiseResolveBlock) resolve
rejecter:(RCTPromiseRejectBlock) reject) {
FIRFirestore *firestore = [RNFirebaseFirestore getFirestoreForApp:appDisplayName];
[firestore enableNetworkWithCompletion:^(NSError * _Nullable error) {
if (error) {
[RNFirebaseFirestore promiseRejectException:reject error:error];
} else {
resolve(nil);
}
}];
}
RCT_EXPORT_METHOD(collectionGet:(NSString *)appDisplayName
path:(NSString *)path
filters:(NSArray *)filters

View File

@ -143,7 +143,7 @@ RCT_EXPORT_METHOD(requestPermission:(RCTPromiseResolveBlock)resolve rejecter:(RC
}
// Non Web SDK methods
RCT_EXPORT_METHOD(hasPermission: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
RCT_EXPORT_METHOD(hasPermission:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max) {
dispatch_async(dispatch_get_main_queue(), ^{
resolve(@([RCTSharedApplication() currentUserNotificationSettings].types != UIUserNotificationTypeNone));
@ -158,7 +158,7 @@ RCT_EXPORT_METHOD(hasPermission: (RCTPromiseResolveBlock)resolve rejecter:(RCTPr
}
RCT_EXPORT_METHOD(sendMessage: (NSDictionary *) message
RCT_EXPORT_METHOD(sendMessage:(NSDictionary *) message
resolve:(RCTPromiseResolveBlock) resolve
reject:(RCTPromiseRejectBlock) reject) {
if (!message[@"to"]) {
@ -175,12 +175,18 @@ RCT_EXPORT_METHOD(sendMessage: (NSDictionary *) message
resolve(nil);
}
RCT_EXPORT_METHOD(subscribeToTopic: (NSString*) topic) {
RCT_EXPORT_METHOD(subscribeToTopic:(NSString*) topic
resolve:(RCTPromiseResolveBlock) resolve
reject:(RCTPromiseRejectBlock) reject) {
[[FIRMessaging messaging] subscribeToTopic:topic];
resolve(nil);
}
RCT_EXPORT_METHOD(unsubscribeFromTopic: (NSString*) topic) {
RCT_EXPORT_METHOD(unsubscribeFromTopic: (NSString*) topic
resolve:(RCTPromiseResolveBlock) resolve
reject:(RCTPromiseRejectBlock) reject) {
[[FIRMessaging messaging] unsubscribeFromTopic:topic];
resolve(nil);
}
// ** Start internals **

View File

@ -202,20 +202,24 @@ didReceiveNotificationResponse:(UNNotificationResponse *)response
// ** Finish UNUserNotificationCenterDelegate methods
// *******************************************************
RCT_EXPORT_METHOD(cancelAllNotifications) {
RCT_EXPORT_METHOD(cancelAllNotifications:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject) {
if ([self isIOS89]) {
[RCTSharedApplication() cancelAllLocalNotifications];
} else {
#if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
if (@available(iOS 10.0, *)) {
UNUserNotificationCenter *notificationCenter = [UNUserNotificationCenter currentNotificationCenter];
if (notificationCenter != nil) {
[[UNUserNotificationCenter currentNotificationCenter] removeAllPendingNotificationRequests];
}
#endif
}
}
resolve(nil);
}
RCT_EXPORT_METHOD(cancelNotification:(NSString*) notificationId) {
RCT_EXPORT_METHOD(cancelNotification:(NSString*) notificationId
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject) {
if ([self isIOS89]) {
for (UILocalNotification *notification in RCTSharedApplication().scheduledLocalNotifications) {
NSDictionary *notificationInfo = notification.userInfo;
@ -224,13 +228,14 @@ RCT_EXPORT_METHOD(cancelNotification:(NSString*) notificationId) {
}
}
} else {
#if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
if (@available(iOS 10.0, *)) {
UNUserNotificationCenter *notificationCenter = [UNUserNotificationCenter currentNotificationCenter];
if (notificationCenter != nil) {
[[UNUserNotificationCenter currentNotificationCenter] removePendingNotificationRequestsWithIdentifiers:@[notificationId]];
}
#endif
}
}
resolve(nil);
}
RCT_EXPORT_METHOD(displayNotification:(NSDictionary*) notification
@ -241,7 +246,7 @@ RCT_EXPORT_METHOD(displayNotification:(NSDictionary*) notification
[RCTSharedApplication() presentLocalNotificationNow:notif];
resolve(nil);
} else {
#if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
if (@available(iOS 10.0, *)) {
UNNotificationRequest* request = [self buildUNNotificationRequest:notification withSchedule:false];
[[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
if (!error) {
@ -250,7 +255,7 @@ RCT_EXPORT_METHOD(displayNotification:(NSDictionary*) notification
reject(@"notifications/display_notification_error", @"Failed to display notificaton", error);
}
}];
#endif
}
}
}
@ -295,7 +300,7 @@ RCT_EXPORT_METHOD(getScheduledNotifications:(RCTPromiseResolveBlock)resolve
}
resolve(notifications);
} else {
#if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
if (@available(iOS 10.0, *)) {
[[UNUserNotificationCenter currentNotificationCenter] getPendingNotificationRequestsWithCompletionHandler:^(NSArray<UNNotificationRequest *> * _Nonnull requests) {
NSMutableArray* notifications = [[NSMutableArray alloc] init];
for (UNNotificationRequest *notif in requests){
@ -304,34 +309,39 @@ RCT_EXPORT_METHOD(getScheduledNotifications:(RCTPromiseResolveBlock)resolve
}
resolve(notifications);
}];
#endif
}
}
}
RCT_EXPORT_METHOD(removeAllDeliveredNotifications) {
RCT_EXPORT_METHOD(removeAllDeliveredNotifications:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject) {
if ([self isIOS89]) {
// No such functionality on iOS 8/9
} else {
#if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
if (@available(iOS 10.0, *)) {
UNUserNotificationCenter *notificationCenter = [UNUserNotificationCenter currentNotificationCenter];
if (notificationCenter != nil) {
[[UNUserNotificationCenter currentNotificationCenter] removeAllDeliveredNotifications];
}
#endif
}
}
resolve(nil);
}
RCT_EXPORT_METHOD(removeDeliveredNotification:(NSString*) notificationId) {
RCT_EXPORT_METHOD(removeDeliveredNotification:(NSString*) notificationId
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject) {
if ([self isIOS89]) {
// No such functionality on iOS 8/9
} else {
#if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
if (@available(iOS 10.0, *)) {
UNUserNotificationCenter *notificationCenter = [UNUserNotificationCenter currentNotificationCenter];
if (notificationCenter != nil) {
[[UNUserNotificationCenter currentNotificationCenter] removeDeliveredNotificationsWithIdentifiers:@[notificationId]];
}
#endif
}
}
resolve(nil);
}
RCT_EXPORT_METHOD(scheduleNotification:(NSDictionary*) notification
@ -342,7 +352,7 @@ RCT_EXPORT_METHOD(scheduleNotification:(NSDictionary*) notification
[RCTSharedApplication() scheduleLocalNotification:notif];
resolve(nil);
} else {
#if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
if (@available(iOS 10.0, *)) {
UNNotificationRequest* request = [self buildUNNotificationRequest:notification withSchedule:true];
[[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
if (!error) {
@ -351,13 +361,16 @@ RCT_EXPORT_METHOD(scheduleNotification:(NSDictionary*) notification
reject(@"notification/schedule_notification_error", @"Failed to schedule notificaton", error);
}
}];
#endif
}
}
}
RCT_EXPORT_METHOD(setBadge: (NSInteger) number) {
RCT_EXPORT_METHOD(setBadge:(NSInteger) number
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject) {
dispatch_async(dispatch_get_main_queue(), ^{
[RCTSharedApplication() setApplicationIconBadgeNumber:number];
resolve(nil);
});
}

17
lib/index.d.ts vendored
View File

@ -1149,8 +1149,10 @@ declare module "react-native-firebase" {
readonly app: App;
batch(): WriteBatch;
collection(collectionPath: string): CollectionReference;
disableNetwork(): Promise<void>
doc(documentPath: string): DocumentReference;
enableNetwork(): Promise<void>
runTransaction(updateFunction: (transaction: Transaction) => Promise<any>): Promise<any>;
/** NOT SUPPORTED YET */
// enablePersistence(): Promise<void>;
/** NOT SUPPORTED YET */
@ -1348,6 +1350,19 @@ declare module "react-native-firebase" {
}
}
interface Transaction {
delete(docRef: DocumentReference): WriteBatch;
get(documentRef: DocumentReference): Promise<DocumentSnapshot>;
set(documentRef: DocumentReference, data: Object, options?: Types.WriteOptions): Transaction
// multiple overrides for update() to allow strong-typed var_args
update(docRef: DocumentReference, obj: object): WriteBatch;
update(docRef: DocumentReference, key1: Types.UpdateKey, val1: any): WriteBatch;
update(docRef: DocumentReference, key1: Types.UpdateKey, val1: any, key2: Types.UpdateKey, val2: any): WriteBatch;
update(docRef: DocumentReference, key1: Types.UpdateKey, val1: any, key2: Types.UpdateKey, val2: any, key3: Types.UpdateKey, val3: any): WriteBatch;
update(docRef: DocumentReference, key1: Types.UpdateKey, val1: any, key2: Types.UpdateKey, val2: any, key3: Types.UpdateKey, val3: any, key4: Types.UpdateKey, val4: any): WriteBatch;
update(docRef: DocumentReference, key1: Types.UpdateKey, val1: any, key2: Types.UpdateKey, val2: any, key3: Types.UpdateKey, val3: any, key4: Types.UpdateKey, val4: any, key5: Types.UpdateKey, val5: any): WriteBatch;
}
interface WriteBatch {
commit(): Promise<void>;
delete(docRef: DocumentReference): WriteBatch;

View File

@ -52,6 +52,7 @@ export default class Database extends ModuleBase {
serviceUrl
);
this._serverTimeOffset = 0;
this._serviceUrl = serviceUrl;
this._transactionHandler = new TransactionHandler(this);
@ -64,7 +65,6 @@ export default class Database extends ModuleBase {
// todo move this and persistence to native side, create a db configure() method natively perhaps?
// todo and then native can call setPersistence and then emit offset events
setTimeout(() => {
this._serverTimeOffset = 0;
this._offsetRef = this.ref('.info/serverTimeOffset');
this._offsetRef.on('value', snapshot => {
this._serverTimeOffset = snapshot.val() || this._serverTimeOffset;

View File

@ -16,6 +16,7 @@ import WriteBatch from './WriteBatch';
import TransactionHandler from './TransactionHandler';
import Transaction from './Transaction';
import INTERNALS from '../../utils/internals';
import { getNativeModule } from '../../utils/native';
import type DocumentSnapshot from './DocumentSnapshot';
import type App from '../core/app';
@ -110,6 +111,10 @@ export default class Firestore extends ModuleBase {
return new CollectionReference(this, path);
}
disableNetwork(): void {
return getNativeModule(this).disableNetwork();
}
/**
* Gets a DocumentReference instance that refers to the document at the specified path.
*
@ -125,6 +130,10 @@ export default class Firestore extends ModuleBase {
return new DocumentReference(this, path);
}
enableNetwork(): Promise<void> {
return getNativeModule(this).enableNetwork();
}
/**
* Executes the given updateFunction and then attempts to commit the
* changes applied within the transaction. If any document read within
@ -156,24 +165,6 @@ export default class Firestore extends ModuleBase {
);
}
enableNetwork(): void {
throw new Error(
INTERNALS.STRINGS.ERROR_UNSUPPORTED_MODULE_METHOD(
'firestore',
'enableNetwork'
)
);
}
disableNetwork(): void {
throw new Error(
INTERNALS.STRINGS.ERROR_UNSUPPORTED_MODULE_METHOD(
'firestore',
'disableNetwork'
)
);
}
/**
* -------------
* MISC

View File

@ -142,12 +142,12 @@ export default class Messaging extends ModuleBase {
}
}
subscribeToTopic(topic: string): void {
getNativeModule(this).subscribeToTopic(topic);
subscribeToTopic(topic: string): Promise<void> {
return getNativeModule(this).subscribeToTopic(topic);
}
unsubscribeFromTopic(topic: string): void {
getNativeModule(this).unsubscribeFromTopic(topic);
unsubscribeFromTopic(topic: string): Promise<void> {
return getNativeModule(this).unsubscribeFromTopic(topic);
}
/**

View File

@ -7,6 +7,8 @@ import { BadgeIconType, Category, GroupAlert, Priority } from './types';
import type Notification from './Notification';
import type {
BadgeIconTypeType,
BigPicture,
BigText,
CategoryType,
DefaultsType,
GroupAlertType,
@ -22,6 +24,8 @@ export default class AndroidNotification {
_actions: AndroidAction[];
_autoCancel: boolean | void;
_badgeIconType: BadgeIconTypeType | void;
_bigPicture: BigPicture | void;
_bigText: BigText | void;
_category: CategoryType | void;
_channelId: string;
_clickAction: string | void;
@ -75,6 +79,8 @@ export default class AndroidNotification {
: [];
this._autoCancel = data.autoCancel;
this._badgeIconType = data.badgeIconType;
this._bigPicture = data.bigPicture;
this._bigText = data.bigText;
this._category = data.category;
this._channelId = data.channelId;
this._clickAction = data.clickAction;
@ -128,6 +134,14 @@ export default class AndroidNotification {
return this._badgeIconType;
}
get bigPicture(): ?BigPicture {
return this._bigPicture;
}
get bigText(): ?BigText {
return this._bigText;
}
get category(): ?CategoryType {
return this._category;
}
@ -298,6 +312,34 @@ export default class AndroidNotification {
return this._notification;
}
setBigPicture(
picture: string,
largeIcon?: string,
contentTitle?: string,
summaryText?: string
): Notification {
this._bigPicture = {
contentTitle,
largeIcon,
picture,
summaryText,
};
return this._notification;
}
setBigText(
text: string,
contentTitle?: string,
summaryText?: string
): Notification {
this._bigText = {
contentTitle,
summaryText,
text,
};
return this._notification;
}
/**
*
* @param category
@ -639,6 +681,8 @@ export default class AndroidNotification {
actions: this._actions.map(action => action.build()),
autoCancel: this._autoCancel,
badgeIconType: this._badgeIconType,
bigPicture: this._bigPicture,
bigText: this._bigText,
category: this._category,
channelId: this._channelId,
clickAction: this._clickAction,

View File

@ -128,21 +128,23 @@ export default class Notifications extends ModuleBase {
/**
* Cancel all notifications
*/
cancelAllNotifications(): void {
getNativeModule(this).cancelAllNotifications();
cancelAllNotifications(): Promise<void> {
return getNativeModule(this).cancelAllNotifications();
}
/**
* Cancel a notification by id.
* @param notificationId
*/
cancelNotification(notificationId: string): void {
cancelNotification(notificationId: string): Promise<void> {
if (!notificationId) {
throw new Error(
'Notifications: cancelNotification expects a `notificationId`'
return Promise.reject(
new Error(
'Notifications: cancelNotification expects a `notificationId`'
)
);
}
getNativeModule(this).cancelNotification(notificationId);
return getNativeModule(this).cancelNotification(notificationId);
}
/**
@ -264,21 +266,23 @@ export default class Notifications extends ModuleBase {
/**
* Remove all delivered notifications.
*/
removeAllDeliveredNotifications(): void {
getNativeModule(this).removeAllDeliveredNotifications();
removeAllDeliveredNotifications(): Promise<void> {
return getNativeModule(this).removeAllDeliveredNotifications();
}
/**
* Remove a delivered notification.
* @param notificationId
*/
removeDeliveredNotification(notificationId: string): void {
removeDeliveredNotification(notificationId: string): Promise<void> {
if (!notificationId) {
throw new Error(
'Notifications: removeDeliveredNotification expects a `notificationId`'
return Promise.reject(
new Error(
'Notifications: removeDeliveredNotification expects a `notificationId`'
)
);
}
getNativeModule(this).removeDeliveredNotification(notificationId);
return getNativeModule(this).removeDeliveredNotification(notificationId);
}
/**
@ -306,8 +310,8 @@ export default class Notifications extends ModuleBase {
}
}
setBadge(badge: number): void {
getNativeModule(this).setBadge(badge);
setBadge(badge: number): Promise<void> {
return getNativeModule(this).setBadge(badge);
}
}

View File

@ -85,6 +85,19 @@ export type PriorityType = $Values<typeof Priority>;
export type SemanticActionType = $Values<typeof SemanticAction>;
export type VisibilityType = $Values<typeof Visibility>;
export type BigPicture = {|
contentTitle?: string,
largeIcon?: string,
picture: string,
summaryText?: string,
|};
export type BigText = {|
contentTitle?: string,
summaryText?: string,
text: string,
|};
export type Lights = {|
argb: number,
onMs: number,
@ -129,6 +142,8 @@ export type NativeAndroidNotification = {|
actions?: NativeAndroidAction[],
autoCancel?: boolean,
badgeIconType?: BadgeIconTypeType,
bigPicture?: BigPicture,
bigText?: BigText,
category?: CategoryType,
channelId: string,
clickAction?: string,

View File

@ -32,46 +32,10 @@
"jest": {
"preset": "jest-react-native",
"setupFiles": [],
"unmockedModulePathPatterns": [
"./node_modules/react",
"./node_modules/react-native",
"./node_modues/react-native-mock",
"./node_modules/react-addons-test-utils"
]
"unmockedModulePathPatterns": ["./node_modules/react", "./node_modules/react-native", "./node_modues/react-native-mock", "./node_modules/react-addons-test-utils"]
},
"license": "APACHE-2.0",
"keywords": [
"react",
"admob",
"auth",
"config",
"digits",
"fabric",
"phone-auth",
"sms",
"firestore",
"cloud-firestore",
"datastore",
"remote-config",
"transactions",
"react-native",
"react-native-firebase",
"firebase",
"fcm",
"apn",
"gcm",
"analytics",
"messaging",
"database",
"android",
"ios",
"crash",
"firestack",
"performance",
"firestore",
"dynamic-links",
"crashlytics"
],
"keywords": ["react", "admob", "auth", "config", "digits", "fabric", "phone-auth", "sms", "firestore", "cloud-firestore", "datastore", "remote-config", "transactions", "react-native", "react-native-firebase", "firebase", "fcm", "apn", "gcm", "analytics", "messaging", "database", "android", "ios", "crash", "firestack", "performance", "firestore", "dynamic-links", "crashlytics"],
"peerDependencies": {
"react": "*",
"react-native": ">= 0.48.0",
@ -124,21 +88,11 @@
},
"collective": {
"type": "opencollective",
"url": "https://opencollective.com/react-native-firebase",
"logo": "https://opencollective.com/opencollective/logo.txt"
"url": "https://opencollective.com/react-native-firebase"
},
"lint-staged": {
"lib/**/*.js": [
"eslint --fix",
"git add"
],
"tests/{src|lib}/**/*.js": [
"eslint --fix",
"git add"
],
"*.{json,md,scss}": [
"prettier --write",
"git add"
]
"lib/**/*.js": ["eslint --fix", "git add"],
"tests/{src|lib}/**/*.js": ["eslint --fix", "git add"],
"*.{json,md,scss}": ["prettier --write", "git add"]
}
}

View File

@ -28,7 +28,7 @@ def enableProguardInReleaseBuilds = false
android {
compileSdkVersion 27
buildToolsVersion '27.0.1'
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.reactnativefirebasedemo"
@ -73,28 +73,28 @@ android {
project.ext.firebaseVersion = '12.0.0'
dependencies {
compile project(':react-native-vector-icons')
compile(project(':react-native-firebase')) {
implementation project(':react-native-vector-icons')
implementation(project(':react-native-firebase')) {
transitive = false
}
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.google.android.gms:play-services-base:$firebaseVersion"
compile "com.google.firebase:firebase-ads:$firebaseVersion"
compile "com.google.firebase:firebase-auth:$firebaseVersion"
compile "com.google.firebase:firebase-config:$firebaseVersion"
compile "com.google.firebase:firebase-core:$firebaseVersion"
compile "com.google.firebase:firebase-crash:$firebaseVersion"
compile "com.google.firebase:firebase-database:$firebaseVersion"
compile "com.google.firebase:firebase-messaging:$firebaseVersion"
compile "com.google.firebase:firebase-perf:$firebaseVersion"
compile "com.google.firebase:firebase-storage:$firebaseVersion"
compile "com.google.firebase:firebase-firestore:$firebaseVersion"
compile "com.google.firebase:firebase-invites:$firebaseVersion"
compile('com.crashlytics.sdk.android:crashlytics:2.9.1@aar') {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.google.android.gms:play-services-base:$firebaseVersion"
implementation "com.google.firebase:firebase-ads:$firebaseVersion"
implementation "com.google.firebase:firebase-auth:$firebaseVersion"
implementation "com.google.firebase:firebase-config:$firebaseVersion"
implementation "com.google.firebase:firebase-core:$firebaseVersion"
implementation "com.google.firebase:firebase-crash:$firebaseVersion"
// implementation "com.google.firebase:firebase-database:$firebaseVersion"
implementation "com.google.firebase:firebase-messaging:$firebaseVersion"
implementation "com.google.firebase:firebase-perf:$firebaseVersion"
implementation "com.google.firebase:firebase-storage:$firebaseVersion"
implementation "com.google.firebase:firebase-firestore:$firebaseVersion"
implementation "com.google.firebase:firebase-invites:$firebaseVersion"
implementation('com.crashlytics.sdk.android:crashlytics:2.9.1@aar') {
transitive = true
}
compile "com.android.support:appcompat-v7:27.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
implementation "com.android.support:appcompat-v7:27.0.2"
implementation "com.facebook.react:react-native:+" // From node_modules
}
// Run this once to be able to run the application with BUCK

View File

@ -42,15 +42,6 @@
</intent-filter>
</receiver>
<!-- App Links -->
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="je786.app.goo.gl" android:scheme="http"/>
<data android:host="je786.app.goo.gl" android:scheme="https"/>
</intent-filter>
<activity
android:name=".MainActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
@ -58,8 +49,17 @@
android:launchMode="singleTop"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- App Links -->
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="je786.app.goo.gl" android:scheme="http"/>
<data android:host="je786.app.goo.gl" android:scheme="https"/>
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />

View File

@ -3,12 +3,13 @@
buildscript {
repositories {
jcenter()
google()
maven {
url 'https://maven.fabric.io/public'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.android.tools.build:gradle:3.1.0'
classpath 'com.google.gms:google-services:3.1.2'
classpath 'com.google.firebase:firebase-plugins:1.1.1'
classpath 'io.fabric.tools:gradle:1.25.1'
@ -30,7 +31,7 @@ allprojects {
subprojects {
ext {
compileSdk = 27
buildTools = "27.0.1"
buildTools = "27.0.3"
minSdk = 16
targetSdk = 26
}

View File

@ -3,5 +3,4 @@ distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
#distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

View File

@ -18,7 +18,7 @@ RNfirebase.utils().logLevel = 'warn'; // default
const notifications = async () => {
try {
await RNfirebase.messaging().requestPermission();
const instanceid = await RNfirebase.instanceid().get();
const instanceid = await RNfirebase.iid().get();
console.log('instanceid: ', instanceid);
const token = await RNfirebase.messaging().getToken();
console.log('token: ', token);
@ -40,7 +40,7 @@ const notifications = async () => {
RNfirebase.notifications().onNotificationDisplayed(notification => {
console.log('onNotificationDisplayed: ', notification);
});
// RNfirebase.instanceid().delete();
// RNfirebase.iid().delete();
const channel = new RNfirebase.notifications.Android.Channel(
'test',
'test',

View File

@ -126,23 +126,10 @@ function firestoreTests({ before, describe, it, context, firebase }) {
});
});
context('disableNetwork()', () => {
it('should throw an unsupported error', () => {
(() => {
firebase.native.firestore().disableNetwork();
}).should.throw(
'firebase.firestore().disableNetwork() is unsupported by the native Firebase SDKs.'
);
});
});
context('enableNetwork()', () => {
it('should throw an unsupported error', () => {
(() => {
firebase.native.firestore().enableNetwork();
}).should.throw(
'firebase.firestore().enableNetwork() is unsupported by the native Firebase SDKs.'
);
context('disable/enableNetwork()', () => {
it('should work without error', async () => {
await firebase.native.firestore().disableNetwork();
await firebase.native.firestore().enableNetwork();
});
});