Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
134 commits
Select commit Hold shift + click to select a range
db965b0
Typ-o manully
pennersr Jan 16, 2017
f37671a
Merge pull request #22 from convoyinc/jonathan/add-podspec
Jan 16, 2017
36a20a4
Merge pull request #26 from pennersr/patch-1
Jan 16, 2017
4452be9
Expose registration failure event
pennersr Jan 16, 2017
0d3e043
Merge pull request #27 from pennersr/registration-failed
Jan 17, 2017
6cb7dd1
1.1.6
Jan 17, 2017
89ba511
Typ-o regsitered
pennersr Jan 20, 2017
7cbf9f6
Issue #21: Change getInitialNotification() to work like iOS when no n…
d4vidi Jan 23, 2017
1571c0d
Merge pull request #31 from pennersr/patch-2
d4vidi Jan 23, 2017
89620c4
1.1.7
Jan 23, 2017
a83c578
Fix broken android API test
d4vidi Feb 15, 2017
c0227c5
Update README.md
sportnak Mar 2, 2017
53df690
Add the (unprotected) VIBRATE permission on Android to support vibrat…
d4vidi Mar 7, 2017
ac05812
1.1.8
d4vidi Mar 7, 2017
da0c4e5
Merge remote-tracking branch 'upstream/master'
gperdomor Mar 20, 2017
fb2111c
Add support to RN 0.40
gperdomor Feb 14, 2017
275cc12
Merge pull request #47 from gperdomor/feature/support-rn-0.40
d4vidi Mar 21, 2017
c9e349f
Fix rn-0.40 support PR's usage of __has_include
d4vidi Mar 22, 2017
e4cd4b9
1.1.9
d4vidi Mar 22, 2017
8024bb2
Merge remote-tracking branch 'upstream/master'
gperdomor Mar 22, 2017
a15e038
Initial support of UNUserNotification
gperdomor Mar 22, 2017
9856f12
Add setBadgesCount function (for iOS)
Apr 24, 2017
a83cfb3
1.1.10
Apr 24, 2017
babfd9f
Accept string device tokens
Benjamin-Dobell May 6, 2017
cad255d
Missing bracket on example
asessa May 7, 2017
b3b57d9
Add ref to RNN wiki
d4vidi May 18, 2017
3dd4e46
Remove android WIP notice
d4vidi May 18, 2017
a1911b3
Fix: Handling first push notification (when opening app with push) w…
Jun 1, 2017
43a4c89
1.1.11
bruchim Jun 1, 2017
2fd4556
Fix flow errors
mlanter Jun 15, 2017
baac919
add isRegisteredForRemoteNotifications to iOS native side
Jul 12, 2017
e5feb9f
add isRegisteredForRemoteNotifications to JS API
Jul 12, 2017
f048829
remove async await
Jul 12, 2017
cb2ec05
add test
Jul 12, 2017
4567efc
Merge pull request #87 from wix/isRegisteredForRemoteNotifications
gran33 Jul 13, 2017
de8a6cb
1.1.12
Jul 13, 2017
1838e42
Merge pull request #75 from opendoor-labs/flow_fix
gran33 Jul 20, 2017
f3c4b0a
1.1.13
Jul 20, 2017
3ed3cfc
Merge pull request #41 from sportnak/patch-2
rotemmiz Jul 20, 2017
9dbc726
Merge pull request #63 from asessa/patch-1
rotemmiz Jul 20, 2017
1ece028
Add iOS checkPermissions
Aug 1, 2017
24eee3b
Fix tests
Aug 2, 2017
b3214e9
Remove depreciated createJSModules @ovveride marker
radko93 Aug 2, 2017
a6de8b3
Fix comment
radko93 Aug 7, 2017
77bce6a
Merge pull request #95 from reberhardt7/master
gran33 Aug 15, 2017
6b7bb9c
Merge branch 'feature/remove-delivered-notifications' into dismiss-no…
reberhardt7 Aug 16, 2017
d945506
Use UserNotifications to create local notifications
Aug 10, 2017
e4921f3
Merge pull request #103 from reberhardt7/dismiss-notifications
gran33 Aug 16, 2017
26da9c9
1.1.14
Aug 19, 2017
7784008
Added support for checking permissions on android
yedidyak Aug 22, 2017
7f1845d
Merge pull request #111 from wix/android_permission_check
guyca Aug 22, 2017
449c2f7
1.1.15
yedidyak Aug 22, 2017
358c1ec
Add silent option to iOS localNotification
Aug 24, 2017
aa1a7b9
Merge pull request #116 from reberhardt7/add-silent-option
gran33 Aug 26, 2017
15798eb
1.1.16
Aug 26, 2017
0cff626
Remove @providesModule
eliperkins Oct 3, 2017
c459345
Merge pull request #62 from Benjamin-Dobell/fcm-ios
gran33 Oct 24, 2017
0a350a1
Merge pull request #96 from radko93/patch-2
d4vidi Oct 26, 2017
83d1386
v1.1.17
d4vidi Oct 26, 2017
0048968
Merge pull request #132 from eliperkins/patch-1
d4vidi Oct 26, 2017
fe30ae5
Break README into sub-sections in separate files with a ToC
d4vidi Oct 26, 2017
2cb5d47
Merge pull request #147 from wix/readme_segmentation
d4vidi Oct 26, 2017
bd4d6b7
Remove old (broken) refs in README
d4vidi Oct 26, 2017
d8a3d25
Fix setting of the `openedLocalNotification` to use the `userInfo` fr…
davidstoker Oct 27, 2017
9a47c85
Add iOS version checks to prevent crashes on iOS 8
davidstoker Nov 16, 2017
816b09e
Revert "Add iOS version checks to prevent crashes on iOS 8"
davidstoker Nov 16, 2017
28a2811
Upgrade lib and demo projects to RN 0.51
d4vidi Jan 11, 2018
80a18f9
Update notificationsEvents.md
Feb 1, 2018
2aaaad9
Added method for getting the current badge count.
lucasgladding Feb 16, 2018
5c796bf
getInitialNotification implemented on iOS
yedidyak Feb 25, 2018
3f13f6f
Get local notification too
yedidyak Feb 25, 2018
2643b66
Merge pull request #148 from KnackTech/open-local-fix
yedidyak Feb 25, 2018
ade806e
Merge pull request #191 from wix/initial_notification_ios
yedidyak Feb 25, 2018
3c170df
Merge pull request #186 from vehikl/feature/get-badge-count
yedidyak Feb 25, 2018
93f257c
Merge pull request #182 from tiborkr/patch-1
yedidyak Feb 25, 2018
072db20
1.1.18
yedidyak Feb 25, 2018
161650d
1.1.19
yedidyak Feb 25, 2018
2c71cd9
Upgrade ios example proj deployment target
d4vidi Feb 27, 2018
cb77df5
Update to SDK 27
diegolmello Jul 25, 2018
0e86357
Merge pull request #244 from RocketChat/master
ButtersHub Aug 16, 2018
254539e
Update example app
guyca Nov 4, 2018
a4ff26d
Update aslant
guyca Nov 4, 2018
e76b6dd
update example app to RN 0.57
guyca Nov 4, 2018
07f7275
1.1.20
guyca Nov 4, 2018
c62ca0f
Remove package lock
d4vidi Nov 4, 2018
6cc14df
1.1.21
d4vidi Nov 4, 2018
aa7625c
fix background PN is received as foreground
doronpr Dec 9, 2018
17dfab5
Merge pull request #270 from wix/fix-bg-pn-treated-as-fg
yogevbd Dec 10, 2018
4a3efcd
1.1.22
yogevbd Dec 10, 2018
b064d81
bump version to 1.1.5-convoyv1
cpirich Dec 10, 2018
6cc55f7
Add notification received in foreground listener
yogevbd Dec 10, 2018
24bab8a
update docs
yogevbd Dec 10, 2018
5df5dad
Merge pull request #271 from wix/foregroundListener
yogevbd Dec 11, 2018
77f672c
1.1.23
yogevbd Dec 11, 2018
a87f4a2
Migrate GCM to FCM
yogevbd Dec 12, 2018
a67664d
Update package.json
yogevbd Dec 12, 2018
a4fd0b6
Guard against null
Jan 9, 2019
18f0d5f
Bump the version
Jan 9, 2019
8f1e010
add fLog
Jan 10, 2019
ac72447
Fixes two issues when multiple notifications were available while app…
Jan 10, 2019
d001a08
Merge pull request #1 from convoyinc/nathaniel/4245_push_notification…
NathanielWaggoner Jan 10, 2019
ffad44a
Merge pull request #2 from convoyinc/jzhu/logging
NathanielWaggoner Jan 10, 2019
979f45e
Version bump from v2 -> v3.
Jan 10, 2019
eac3274
Merge pull request #3 from convoyinc/nathaniel/version_bump
NathanielWaggoner Jan 10, 2019
361f323
Merge branch 'master' into yuit/mergeLatestMasterFromWix
Jan 24, 2019
6012eef
Update version
Jan 24, 2019
afce79a
Merge pull request #4 from convoyinc/yuit/mergeLatestMasterFromWix
yuit Jan 25, 2019
f3c23df
Merge branch 'master' into yuit/mergeLatestMasterFromWix
Jan 25, 2019
3eac7d5
Merge pull request #5 from convoyinc/yuit/BringInFCM
yuit Jan 25, 2019
79b48d0
Update gradle
Jan 25, 2019
4dc2b18
Fix collision of naming
Jan 25, 2019
5907626
Merge pull request #6 from convoyinc/yuit/FixBuildErrors
yuit Jan 25, 2019
162d53d
bump convoy version
JAStanton Jan 29, 2019
dbf19e1
fix bundle logging when rawData doesn't have data key
cpirich Feb 15, 2019
d55bff2
add RNNotificationsNativeCallback so native can track PN events that …
cpirich Feb 28, 2019
b554d7e
bump version to 1.2.0-convoyv4
cpirich Feb 28, 2019
1f628be
Merge pull request #7 from convoyinc/cpirich/add-nativeCallback-onEve…
cpirich Feb 28, 2019
2f34cf9
treat null rawData like empty rawData - still pass the bundle up for …
cpirich Mar 1, 2019
9a78802
remove references to already declares categories
JAStanton Mar 5, 2019
640f400
remove references to already declares categories
JAStanton Mar 5, 2019
ae42522
bump convoy version
JAStanton Mar 5, 2019
d1d0ced
Merge branch 'convoy/latest' of https://github.com/convoyinc/react-na…
JAStanton Mar 5, 2019
c88ea1c
Add headers for UILocalNotification and UIBackgroundFetchResult
JAStanton Mar 5, 2019
3455ca8
Bump gradle build tools and move to implementation and api keywords t…
Mar 6, 2019
da4c0fa
Merge pull request #8 from convoyinc/nathaniel/ch-5073/fix-android-bu…
NathanielWaggoner Mar 8, 2019
4bbd6af
Say when! -- For notifications N and above we need to set a "when" time
JAStanton Jul 16, 2019
3c22624
Merge pull request #9 from convoyinc/jonathan/say-when
JAStanton Jul 16, 2019
125406a
bump version
JAStanton Jul 16, 2019
b37b057
Merge pull request #10 from convoyinc/jonathan/say-when
JAStanton Jul 16, 2019
718317c
Updates the FcmToken method sendTokenToJS to always post a runnable t…
NathanielWaggoner Jul 19, 2019
4271b16
Merge pull request #11 from convoyinc/nathaniel/fix_background_crash_…
NathanielWaggoner Jul 19, 2019
8fa4213
Use BigText style for Android push notifiactions
gfoltz Aug 30, 2019
e6ef896
Merge pull request #12 from convoyinc/gfoltz/big_text
gfoltz Sep 3, 2019
c01d8da
Bump package version
gfoltz Sep 5, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
language: node_js
node_js:
- "6"
- "7"
611 changes: 16 additions & 595 deletions README.md

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions RNNotifications/RNNotifications.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,28 @@
#import <React/RCTBridgeModule.h>
#endif

#if __has_include(<React/RCTConvert.h>)
#import <React/RCTConvert.h>
#elif __has_include("React/RCTConvert.h")
#import "React/RCTConvert.h"
#else
#import "RCTConvert.h"
#endif

@interface RCTConvert (UILocalNotification)
+ (UILocalNotification *)UILocalNotification:(id)json;
@end

@interface RCTConvert (UIBackgroundFetchResult)
+(UIBackgroundFetchResult *)UIBackgroundFetchResult:(id)json;
@end

@interface RNNotifications : NSObject <RCTBridgeModule>

typedef void (^RCTRemoteNotificationCallback)(UIBackgroundFetchResult result);

+ (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;
+ (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error;
+ (void)didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings;
+ (void)didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type;

Expand Down
224 changes: 182 additions & 42 deletions RNNotifications/RNNotifications.m

Large diffs are not rendered by default.

33 changes: 23 additions & 10 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
buildscript {
repositories {
maven {
url "https://maven.google.com"
}
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

apply plugin: 'com.android.library'

android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
compileSdkVersion 27

defaultConfig {
minSdkVersion 16
targetSdkVersion 26
targetSdkVersion 27
versionCode 1
versionName "1.0"
}
Expand All @@ -20,13 +34,12 @@ android {

dependencies {
// Google's GCM.
compile 'com.google.android.gms:play-services-gcm:11.6.0'

compile 'com.facebook.react:react-native:+'
api "com.google.firebase:firebase-messaging:17.3.4"
implementation 'com.facebook.react:react-native:+'

compile 'me.leolin:ShortcutBadger:1.1.8@aar'
implementation 'me.leolin:ShortcutBadger:1.1.8@aar'

testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.+'
testCompile 'org.robolectric:robolectric:3.1.4'
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.+'
testImplementation 'org.robolectric:robolectric:3.1.4'
}
36 changes: 8 additions & 28 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,26 @@
android:protectionLevel="signature" />
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />

<!-- Ref: http://stackoverflow.com/questions/13602190/java-lang-securityexception-requires-vibrate-permission-on-jelly-bean-4-2 -->
<uses-permission android:name="android.permission.VIBRATE" android:maxSdkVersion="18" />

<application>

<!--
A proxy-service that gives the library an opportunity to do some work before launching/resuming the actual application task.
-->
<service android:name=".core.ProxyService"/>

<!--
Google's ready-to-use GcmReceiver.
1. Awaits actual GCM messages (e.g. push notifications) and invokes the GCM service with the concrete content.
2. Awaits instance-ID/token refresh requests from the GCM and invokes the Instance-ID listener service.
-->
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="${applicationId}" />
</intent-filter>
</receiver>
<!-- Dispatched by the GcmReceiver when messages are received. -->
<service
android:name="com.wix.reactnativenotifications.gcm.GcmMessageHandlerService"
android:exported="false">
android:name=".gcm.FcmInstanceIdListenerService">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<!-- Dispatched by the GcmReceiver. Starts the designated refresh-handling service. -->
<service
android:name=".gcm.GcmInstanceIdListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID" />
<action android:name="com.google.firebase.MESSAGING_EVENT" />
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>

<service
android:name=".gcm.GcmInstanceIdRefreshHandlerService"
android:name=".gcm.FcmInstanceIdRefreshHandlerService"
android:exported="false" />
</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ public interface Defs {
String TOKEN_RECEIVED_EVENT_NAME = "remoteNotificationsRegistered";

String NOTIFICATION_RECEIVED_EVENT_NAME = "notificationReceived";
String NOTIFICATION_RECEIVED_FOREGROUND_EVENT_NAME = "notificationReceivedInForeground";
String NOTIFICATION_OPENED_EVENT_NAME = "notificationOpened";
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.NotificationManagerCompat;
import android.util.Log;

import com.facebook.react.bridge.Arguments;
Expand All @@ -22,18 +23,18 @@
import com.wix.reactnativenotifications.core.notificationdrawer.IPushNotificationsDrawer;
import com.wix.reactnativenotifications.core.notificationdrawer.PushNotificationsDrawer;
import com.wix.reactnativenotifications.core.ReactAppLifecycleFacade;
import com.wix.reactnativenotifications.gcm.GcmInstanceIdRefreshHandlerService;
import com.wix.reactnativenotifications.gcm.FcmInstanceIdRefreshHandlerService;
import com.wix.reactnativenotifications.helpers.ApplicationBadgeHelper;

import static com.wix.reactnativenotifications.Defs.LOGTAG;

public class RNNotificationsModule extends ReactContextBaseJavaModule implements AppLifecycleFacade.AppVisibilityListener, Application.ActivityLifecycleCallbacks {

public RNNotificationsModule(Application application, ReactApplicationContext reactContext) {
public RNNotificationsModule(Application application, RNNotificationsNativeCallback nativeCallback, ReactApplicationContext reactContext) {
super(reactContext);

if (AppLifecycleFacadeHolder.get() instanceof ReactAppLifecycleFacade) {
((ReactAppLifecycleFacade) AppLifecycleFacadeHolder.get()).init(reactContext);
((ReactAppLifecycleFacade) AppLifecycleFacadeHolder.get()).init(reactContext, nativeCallback);
}
AppLifecycleFacadeHolder.get().addVisibilityListener(this);
application.registerActivityLifecycleCallbacks(this);
Expand All @@ -47,7 +48,7 @@ public String getName() {
@Override
public void initialize() {
Log.d(LOGTAG, "Native module init");
startGcmIntentService(GcmInstanceIdRefreshHandlerService.EXTRA_IS_APP_INIT);
startGcmIntentService(FcmInstanceIdRefreshHandlerService.EXTRA_IS_APP_INIT);

final IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(getReactApplicationContext().getApplicationContext());
notificationsDrawer.onAppInit();
Expand All @@ -56,7 +57,7 @@ public void initialize() {
@ReactMethod
public void refreshToken() {
Log.d(LOGTAG, "Native method invocation: refreshToken()");
startGcmIntentService(GcmInstanceIdRefreshHandlerService.EXTRA_MANUAL_REFRESH);
startGcmIntentService(FcmInstanceIdRefreshHandlerService.EXTRA_MANUAL_REFRESH);
}

@ReactMethod
Expand Down Expand Up @@ -99,6 +100,12 @@ public void cancelLocalNotification(int notificationId) {
notificationsDrawer.onNotificationClearRequest(notificationId);
}

@ReactMethod
public void isRegisteredForRemoteNotifications(Promise promise) {
boolean hasPermission = NotificationManagerCompat.from(getReactApplicationContext()).areNotificationsEnabled();
promise.resolve(new Boolean(hasPermission));
}

@Override
public void onAppVisible() {
final IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(getReactApplicationContext().getApplicationContext());
Expand Down Expand Up @@ -141,7 +148,7 @@ public void onActivityDestroyed(Activity activity) {

protected void startGcmIntentService(String extraFlag) {
final Context appContext = getReactApplicationContext().getApplicationContext();
final Intent tokenFetchIntent = new Intent(appContext, GcmInstanceIdRefreshHandlerService.class);
final Intent tokenFetchIntent = new Intent(appContext, FcmInstanceIdRefreshHandlerService.class);
tokenFetchIntent.putExtra(extraFlag, true);
appContext.startService(tokenFetchIntent);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.wix.reactnativenotifications;

import com.facebook.react.bridge.WritableMap;

public interface RNNotificationsNativeCallback {
void onEventNotSentToJS(String eventName, WritableMap data);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.app.Application;

import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
Expand All @@ -14,21 +13,20 @@

public class RNNotificationsPackage implements ReactPackage {


final Application mApplication;
private final Application mApplication;
private RNNotificationsNativeCallback mNativeCallback;

public RNNotificationsPackage(Application application) {
mApplication = application;
}

@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
return Arrays.<NativeModule>asList(new RNNotificationsModule(mApplication, reactContext));
public void addNativeCallback(RNNotificationsNativeCallback rnNotificationsNativeCallback) {
mNativeCallback = rnNotificationsNativeCallback;
}

// Deprecated RN 0.47
public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
return Arrays.<NativeModule>asList(new RNNotificationsModule(mApplication, mNativeCallback, reactContext));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.wix.reactnativenotifications.core;

import com.wix.reactnativenotifications.RNNotificationsNativeCallback;
import com.facebook.react.bridge.ReactContext;

public interface AppLifecycleFacade {
Expand All @@ -11,6 +12,7 @@ interface AppVisibilityListener {

boolean isReactInitialized();
ReactContext getRunningReactContext();
RNNotificationsNativeCallback getNativeCallback();
boolean isAppVisible();
void addVisibilityListener(AppVisibilityListener listener);
void removeVisibilityListener(AppVisibilityListener listener);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.wix.reactnativenotifications.core;

import com.wix.reactnativenotifications.RNNotificationsNativeCallback;
import android.os.Bundle;

import com.facebook.react.bridge.Arguments;
Expand All @@ -8,18 +9,18 @@
import com.facebook.react.modules.core.DeviceEventManagerModule;

public class JsIOHelper {
public boolean sendEventToJS(String eventName, Bundle data, ReactContext reactContext) {
if (reactContext != null) {
sendEventToJS(eventName, Arguments.fromBundle(data), reactContext);
return true;
}
return false;
public boolean sendEventToJS(String eventName, Bundle data, AppLifecycleFacade appLifecycleFacade) {
return sendEventToJS(eventName, Arguments.fromBundle(data), appLifecycleFacade);
}

public boolean sendEventToJS(String eventName, WritableMap data, ReactContext reactContext) {
if (reactContext != null) {
public boolean sendEventToJS(String eventName, WritableMap data, AppLifecycleFacade appLifecycleFacade) {
RNNotificationsNativeCallback nativeCallback = appLifecycleFacade.getNativeCallback();
ReactContext reactContext = appLifecycleFacade.getRunningReactContext();
if (appLifecycleFacade.isReactInitialized() && reactContext != null) {
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName, data);
return true;
} else if (nativeCallback != null) {
nativeCallback.onEventNotSentToJS(eventName, data);
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
import com.wix.reactnativenotifications.core.notification.PushNotificationProps;

public class NotificationIntentAdapter {
private static final int PENDING_INTENT_CODE = 0;
private static final String PUSH_NOTIFICATION_EXTRA_NAME = "pushNotification";

public static PendingIntent createPendingNotificationIntent(Context appContext, Intent intent, PushNotificationProps notification) {
intent.putExtra(PUSH_NOTIFICATION_EXTRA_NAME, notification.asBundle());
return PendingIntent.getService(appContext, PENDING_INTENT_CODE, intent, PendingIntent.FLAG_ONE_SHOT);
// a unique action, data, type, class, or category must be set, otherwise the intent matcher
// gets confused see https://developer.android.com/reference/android/app/PendingIntent
intent.setAction(String.valueOf(System.currentTimeMillis()));
return PendingIntent.getService(appContext, (int) System.currentTimeMillis(), intent, PendingIntent.FLAG_ONE_SHOT);
}

public static Bundle extractPendingNotificationDataFromIntent(Intent intent) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.wix.reactnativenotifications.core;

import com.wix.reactnativenotifications.RNNotificationsNativeCallback;
import android.util.Log;

import com.facebook.react.bridge.LifecycleEventListener;
Expand All @@ -14,10 +15,12 @@ public class ReactAppLifecycleFacade implements AppLifecycleFacade {

private ReactContext mReactContext;
private boolean mIsVisible;
private RNNotificationsNativeCallback mNativeCallback;
private Set<AppVisibilityListener> mListeners = new CopyOnWriteArraySet<>();

public void init(ReactContext reactContext) {
public void init(ReactContext reactContext, RNNotificationsNativeCallback nativeCallback) {
mReactContext = reactContext;
mNativeCallback = nativeCallback;
reactContext.addLifecycleEventListener(new LifecycleEventListener() {
@Override
public void onHostResume() {
Expand Down Expand Up @@ -58,6 +61,11 @@ public ReactContext getRunningReactContext() {
return mReactContext;
}

@Override
public RNNotificationsNativeCallback getNativeCallback() {
return mNativeCallback;
}

@Override
public boolean isAppVisible() {
return mIsVisible;
Expand Down
Loading