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
5df5dad4
Commit
5df5dad4
authored
Dec 11, 2018
by
Yogev Ben David
Committed by
GitHub
Dec 11, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #271 from wix/foregroundListener
Foreground listener
parents
4a3efcd6
24bab8ab
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
1 deletion
+25
-1
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
+4
-1
index.android.js
index.android.js
+12
-0
No files found.
android/src/main/java/com/wix/reactnativenotifications/Defs.java
View file @
5df5dad4
...
...
@@ -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"
;
}
android/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java
View file @
5df5dad4
...
...
@@ -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_RECEIVED_EVENT_NAME
;
import
static
com
.
wix
.
reactnativenotifications
.
Defs
.
NOTIFICATION_RECEIVED_FOREGROUND_EVENT_NAME
;
public
class
PushNotification
implements
IPushNotification
{
...
...
@@ -61,6 +62,9 @@ public class PushNotification implements IPushNotification {
public
void
onReceived
()
throws
InvalidNotificationException
{
postNotification
(
null
);
notifyReceivedToJS
();
if
(
mAppLifecycleFacade
.
isAppVisible
())
{
notifiyReceivedForegroundNotificationToJS
();
}
}
@Override
...
...
@@ -186,6 +190,10 @@ public class PushNotification implements IPushNotification {
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
()
{
mJsIOHelper
.
sendEventToJS
(
NOTIFICATION_OPENED_EVENT_NAME
,
mNotificationProps
.
asBundle
(),
mAppLifecycleFacade
.
getRunningReactContext
());
}
...
...
docs/notificationsEvents.md
View file @
5df5dad4
...
...
@@ -70,7 +70,10 @@ import {NotificationsAndroid} from 'react-native-notifications';
// On Android, we allow for only one (global) listener per each event type.
NotificationsAndroid
.
setNotificationReceivedListener
((
notification
)
=>
{
console
.
log
(
"
Notification received on device
"
,
notification
.
getData
());
console
.
log
(
"
Notification received on device in background or foreground
"
,
notification
.
getData
());
});
NotificationsAndroid
.
setNotificationReceivedInForegroundListener
((
notification
)
=>
{
console
.
log
(
"
Notification received on device in foreground
"
,
notification
.
getData
());
});
NotificationsAndroid
.
setNotificationOpenedListener
((
notification
)
=>
{
console
.
log
(
"
Notification opened by device user
"
,
notification
.
getData
());
...
...
index.android.js
View file @
5df5dad4
...
...
@@ -4,6 +4,7 @@ import NotificationAndroid from "./notification";
const
RNNotifications
=
NativeModules
.
WixRNNotifications
;
let
notificationReceivedListener
;
let
notificationReceivedInForegroundListener
;
let
notificationOpenedListener
;
let
registrationTokenUpdateListener
;
...
...
@@ -23,6 +24,10 @@ export class NotificationsAndroid {
notificationReceivedListener
=
DeviceEventEmitter
.
addListener
(
"
notificationReceived
"
,
(
notification
)
=>
listener
(
new
NotificationAndroid
(
notification
)));
}
static
setNotificationReceivedInForegroundListener
(
listener
)
{
notificationReceivedInForegroundListener
=
DeviceEventEmitter
.
addListener
(
"
notificationReceivedInForeground
"
,
(
notification
)
=>
listener
(
new
NotificationAndroid
(
notification
)));
}
static
clearNotificationReceivedListener
()
{
if
(
notificationReceivedListener
)
{
notificationReceivedListener
.
remove
();
...
...
@@ -30,6 +35,13 @@ export class NotificationsAndroid {
}
}
static
clearNotificationReceivedInForegroundListener
()
{
if
(
notificationReceivedInForegroundListener
)
{
notificationReceivedInForegroundListener
.
remove
();
notificationReceivedInForegroundListener
=
null
;
}
}
static
setRegistrationTokenUpdateListener
(
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