Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
react-native-notifications
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Jira
Jira
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
冷佳娟
react-native-notifications
Commits
6cc55f7b
"lib/android/.project" did not exist on "7aa1eba632d659d38e4dd9657f25701c1df019c2"
Commit
6cc55f7b
authored
Dec 10, 2018
by
yogevbd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add notification received in foreground listener
parent
4a3efcd6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
0 deletions
+24
-0
android/src/main/java/com/wix/reactnativenotifications/Defs.java
.../src/main/java/com/wix/reactnativenotifications/Defs.java
+1
-0
android/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java
...tivenotifications/core/notification/PushNotification.java
+8
-0
docs/notificationsEvents.md
docs/notificationsEvents.md
+3
-0
index.android.js
index.android.js
+12
-0
No files found.
android/src/main/java/com/wix/reactnativenotifications/Defs.java
View file @
6cc55f7b
...
@@ -7,5 +7,6 @@ public interface Defs {
...
@@ -7,5 +7,6 @@ public interface Defs {
String
TOKEN_RECEIVED_EVENT_NAME
=
"remoteNotificationsRegistered"
;
String
TOKEN_RECEIVED_EVENT_NAME
=
"remoteNotificationsRegistered"
;
String
NOTIFICATION_RECEIVED_EVENT_NAME
=
"notificationReceived"
;
String
NOTIFICATION_RECEIVED_EVENT_NAME
=
"notificationReceived"
;
String
NOTIFICATION_RECEIVED_FOREGROUND_EVENT_NAME
=
"notificationReceivedInForeground"
;
String
NOTIFICATION_OPENED_EVENT_NAME
=
"notificationOpened"
;
String
NOTIFICATION_OPENED_EVENT_NAME
=
"notificationOpened"
;
}
}
android/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java
View file @
6cc55f7b
...
@@ -21,6 +21,7 @@ import com.wix.reactnativenotifications.core.ProxyService;
...
@@ -21,6 +21,7 @@ import com.wix.reactnativenotifications.core.ProxyService;
import
static
com
.
wix
.
reactnativenotifications
.
Defs
.
NOTIFICATION_OPENED_EVENT_NAME
;
import
static
com
.
wix
.
reactnativenotifications
.
Defs
.
NOTIFICATION_OPENED_EVENT_NAME
;
import
static
com
.
wix
.
reactnativenotifications
.
Defs
.
NOTIFICATION_RECEIVED_EVENT_NAME
;
import
static
com
.
wix
.
reactnativenotifications
.
Defs
.
NOTIFICATION_RECEIVED_EVENT_NAME
;
import
static
com
.
wix
.
reactnativenotifications
.
Defs
.
NOTIFICATION_RECEIVED_FOREGROUND_EVENT_NAME
;
public
class
PushNotification
implements
IPushNotification
{
public
class
PushNotification
implements
IPushNotification
{
...
@@ -61,6 +62,9 @@ public class PushNotification implements IPushNotification {
...
@@ -61,6 +62,9 @@ public class PushNotification implements IPushNotification {
public
void
onReceived
()
throws
InvalidNotificationException
{
public
void
onReceived
()
throws
InvalidNotificationException
{
postNotification
(
null
);
postNotification
(
null
);
notifyReceivedToJS
();
notifyReceivedToJS
();
if
(
mAppLifecycleFacade
.
isAppVisible
())
{
notifiyReceivedForegroundNotificationToJS
();
}
}
}
@Override
@Override
...
@@ -186,6 +190,10 @@ public class PushNotification implements IPushNotification {
...
@@ -186,6 +190,10 @@ public class PushNotification implements IPushNotification {
mJsIOHelper
.
sendEventToJS
(
NOTIFICATION_RECEIVED_EVENT_NAME
,
mNotificationProps
.
asBundle
(),
mAppLifecycleFacade
.
getRunningReactContext
());
mJsIOHelper
.
sendEventToJS
(
NOTIFICATION_RECEIVED_EVENT_NAME
,
mNotificationProps
.
asBundle
(),
mAppLifecycleFacade
.
getRunningReactContext
());
}
}
private
void
notifiyReceivedForegroundNotificationToJS
()
{
mJsIOHelper
.
sendEventToJS
(
NOTIFICATION_RECEIVED_FOREGROUND_EVENT_NAME
,
mNotificationProps
.
asBundle
(),
mAppLifecycleFacade
.
getRunningReactContext
());
}
private
void
notifyOpenedToJS
()
{
private
void
notifyOpenedToJS
()
{
mJsIOHelper
.
sendEventToJS
(
NOTIFICATION_OPENED_EVENT_NAME
,
mNotificationProps
.
asBundle
(),
mAppLifecycleFacade
.
getRunningReactContext
());
mJsIOHelper
.
sendEventToJS
(
NOTIFICATION_OPENED_EVENT_NAME
,
mNotificationProps
.
asBundle
(),
mAppLifecycleFacade
.
getRunningReactContext
());
}
}
...
...
docs/notificationsEvents.md
View file @
6cc55f7b
...
@@ -72,6 +72,9 @@ import {NotificationsAndroid} from 'react-native-notifications';
...
@@ -72,6 +72,9 @@ import {NotificationsAndroid} from 'react-native-notifications';
NotificationsAndroid
.
setNotificationReceivedListener
((
notification
)
=>
{
NotificationsAndroid
.
setNotificationReceivedListener
((
notification
)
=>
{
console
.
log
(
"
Notification received on device
"
,
notification
.
getData
());
console
.
log
(
"
Notification received on device
"
,
notification
.
getData
());
});
});
NotificationsAndroid
.
setNotificationReceivedInForegroundListener
((
notification
)
=>
{
console
.
log
(
"
Notification received on device
"
,
notification
.
getData
());
});
NotificationsAndroid
.
setNotificationOpenedListener
((
notification
)
=>
{
NotificationsAndroid
.
setNotificationOpenedListener
((
notification
)
=>
{
console
.
log
(
"
Notification opened by device user
"
,
notification
.
getData
());
console
.
log
(
"
Notification opened by device user
"
,
notification
.
getData
());
});
});
...
...
index.android.js
View file @
6cc55f7b
...
@@ -4,6 +4,7 @@ import NotificationAndroid from "./notification";
...
@@ -4,6 +4,7 @@ import NotificationAndroid from "./notification";
const
RNNotifications
=
NativeModules
.
WixRNNotifications
;
const
RNNotifications
=
NativeModules
.
WixRNNotifications
;
let
notificationReceivedListener
;
let
notificationReceivedListener
;
let
notificationReceivedInForegroundListener
;
let
notificationOpenedListener
;
let
notificationOpenedListener
;
let
registrationTokenUpdateListener
;
let
registrationTokenUpdateListener
;
...
@@ -23,6 +24,10 @@ export class NotificationsAndroid {
...
@@ -23,6 +24,10 @@ export class NotificationsAndroid {
notificationReceivedListener
=
DeviceEventEmitter
.
addListener
(
"
notificationReceived
"
,
(
notification
)
=>
listener
(
new
NotificationAndroid
(
notification
)));
notificationReceivedListener
=
DeviceEventEmitter
.
addListener
(
"
notificationReceived
"
,
(
notification
)
=>
listener
(
new
NotificationAndroid
(
notification
)));
}
}
static
setNotificationReceivedInForegroundListener
(
listener
)
{
notificationReceivedInForegroundListener
=
DeviceEventEmitter
.
addListener
(
"
notificationReceivedInForeground
"
,
(
notification
)
=>
listener
(
new
NotificationAndroid
(
notification
)));
}
static
clearNotificationReceivedListener
()
{
static
clearNotificationReceivedListener
()
{
if
(
notificationReceivedListener
)
{
if
(
notificationReceivedListener
)
{
notificationReceivedListener
.
remove
();
notificationReceivedListener
.
remove
();
...
@@ -30,6 +35,13 @@ export class NotificationsAndroid {
...
@@ -30,6 +35,13 @@ export class NotificationsAndroid {
}
}
}
}
static
clearNotificationReceivedInForegroundListener
()
{
if
(
notificationReceivedInForegroundListener
)
{
notificationReceivedInForegroundListener
.
remove
();
notificationReceivedInForegroundListener
=
null
;
}
}
static
setRegistrationTokenUpdateListener
(
listener
)
{
static
setRegistrationTokenUpdateListener
(
listener
)
{
registrationTokenUpdateListener
=
DeviceEventEmitter
.
addListener
(
"
remoteNotificationsRegistered
"
,
listener
);
registrationTokenUpdateListener
=
DeviceEventEmitter
.
addListener
(
"
remoteNotificationsRegistered
"
,
listener
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment