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
25b5baf8
Commit
25b5baf8
authored
Jul 10, 2019
by
yogevbd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add e2e tests and final adjustments
parent
296c9cbf
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
76 additions
and
54 deletions
+76
-54
RNNotifications/RNBridgeModule.m
RNNotifications/RNBridgeModule.m
+4
-2
RNNotifications/RNCommandsHandler.m
RNNotifications/RNCommandsHandler.m
+4
-3
RNNotifications/RNNotifications.h
RNNotifications/RNNotifications.h
+0
-6
RNNotifications/RNNotifications.m
RNNotifications/RNNotifications.m
+1
-15
RNNotifications/RNNotificationsStore.h
RNNotifications/RNNotificationsStore.h
+3
-1
RNNotifications/RNNotificationsStore.m
RNNotifications/RNNotificationsStore.m
+12
-3
e2e/Notifications.test.js
e2e/Notifications.test.js
+36
-19
example/index.ios.js
example/index.ios.js
+15
-4
lib/src/index.ios.js
lib/src/index.ios.js
+1
-1
No files found.
RNNotifications/RNBridgeModule.m
View file @
25b5baf8
#import "RNBridgeModule.h"
#import "RNCommandsHandler.h"
#import "RCTConvert+Notifications.h"
#import "RNNotifications.h"
#import "RNNotifications
Store
.h"
#import <React/RCTBridgeDelegate.h>
@implementation
RNBridgeModule
{
...
...
@@ -24,7 +24,9 @@ RCT_EXPORT_MODULE();
-
(
void
)
setBridge
:(
RCTBridge
*
)
bridge
{
_bridge
=
bridge
;
[[
RNNotifications
sharedInstance
]
setInitialNotification
:[
_bridge
.
launchOptions
objectForKey
:
UIApplicationLaunchOptionsRemoteNotificationKey
]];
if
([
_bridge
.
launchOptions
objectForKey
:
UIApplicationLaunchOptionsRemoteNotificationKey
])
{
[[
RNNotificationsStore
sharedInstance
]
setInitialNotification
:[
_bridge
.
launchOptions
objectForKey
:
UIApplicationLaunchOptionsRemoteNotificationKey
]];
}
}
#pragma mark - JS interface
...
...
RNNotifications/RNCommandsHandler.m
View file @
25b5baf8
#import "RNCommandsHandler.h"
#import "RNNotifications.h"
#import "RNNotificationsStore.h"
#import "RCTConvert+Notifications.h"
@implementation
RNCommandsHandler
{
...
...
@@ -17,15 +18,15 @@
}
-
(
void
)
getInitialNotification
:(
RCTPromiseResolveBlock
)
resolve
reject
:(
RCTPromiseRejectBlock
)
reject
{
resolve
([[
RNNotifications
sharedInstance
]
initialNotification
]);
resolve
([[
RNNotifications
Store
sharedInstance
]
initialNotification
]);
}
-
(
void
)
finishHandlingAction
:(
NSString
*
)
completionKey
{
[[
RNNotifications
sharedInstance
]
finishHandleActionKey
:
completionKey
];
[[
RNNotifications
Store
sharedInstance
]
completeAction
:
completionKey
];
}
-
(
void
)
finishPresentingNotification
:(
NSString
*
)
completionKey
presentingOptions
:(
NSDictionary
*
)
presentingOptions
{
[[
RNNotifications
sharedInstance
]
finishHandleNotificationKey
:
completionKey
presenting
Options
:[
RCTConvert
UNNotificationPresentationOptions
:
presentingOptions
]];
[[
RNNotifications
Store
sharedInstance
]
completePresentation
:
completionKey
withPresentation
Options
:[
RCTConvert
UNNotificationPresentationOptions
:
presentingOptions
]];
}
-
(
void
)
abandonPermissions
{
...
...
RNNotifications/RNNotifications.h
View file @
25b5baf8
...
...
@@ -4,8 +4,6 @@
@interface
RNNotifications
:
NSObject
@property
(
nonatomic
,
retain
)
NSDictionary
*
initialNotification
;
+
(
instancetype
)
sharedInstance
;
+
(
void
)
startMonitorNotifications
;
...
...
@@ -14,8 +12,4 @@
+
(
void
)
didRegisterForRemoteNotificationsWithDeviceToken
:(
id
)
deviceToken
;
+
(
void
)
didFailToRegisterForRemoteNotificationsWithError
:(
NSError
*
)
error
;
-
(
void
)
finishHandleNotificationKey
:(
NSString
*
)
notificationKey
presentingOptions
:(
UNNotificationPresentationOptions
)
presentingOptions
;
-
(
void
)
finishHandleActionKey
:(
NSString
*
)
actionKey
;
@end
RNNotifications/RNNotifications.m
View file @
25b5baf8
...
...
@@ -12,13 +12,11 @@
RNNotificationEventHandler
*
_notificationEventHandler
;
RNPushKitEventHandler
*
_pushKitEventHandler
;
RNEventEmitter
*
_eventEmitter
;
RNNotificationsStore
*
_store
;
}
-
(
instancetype
)
init
{
self
=
[
super
init
];
_store
=
[
RNNotificationsStore
new
];
_notificationEventHandler
=
[[
RNNotificationEventHandler
alloc
]
initWithStore
:
_store
];
_notificationEventHandler
=
[[
RNNotificationEventHandler
alloc
]
initWithStore
:[
RNNotificationsStore
new
]];
return
self
;
}
...
...
@@ -65,16 +63,4 @@
[
_notificationEventHandler
didFailToRegisterForRemoteNotificationsWithError
:
error
];
}
-
(
void
)
setInitialNotification
:(
NSDictionary
*
)
notification
{
[
_store
setInitialNotification
:
notification
];
}
-
(
void
)
finishHandleActionKey
:(
NSString
*
)
actionKey
{
[
_store
completeAction
:
actionKey
];
}
-
(
void
)
finishHandleNotificationKey
:(
NSString
*
)
notificationKey
presentingOptions
:(
UNNotificationPresentationOptions
)
presentingOptions
{
[
_store
completePresentation
:
notificationKey
withPresentationOptions
:
presentingOptions
];
}
@end
RNNotifications/RNNotificationsStore.h
View file @
25b5baf8
...
...
@@ -3,7 +3,9 @@
@interface
RNNotificationsStore
:
NSObject
@property
NSDictionary
*
initialNotification
;
@property
(
nonatomic
,
retain
)
NSDictionary
*
initialNotification
;
+
(
instancetype
)
sharedInstance
;
-
(
void
)
completeAction
:(
NSString
*
)
completionKey
;
-
(
void
)
completePresentation
:(
NSString
*
)
completionKey
withPresentationOptions
:(
UNNotificationPresentationOptions
)
presentationOptions
;
...
...
RNNotifications/RNNotificationsStore.m
View file @
25b5baf8
#import "RNNotificationsStore.h"
@implementation
RNNotificationsStore
{
NSMutableDictionary
*
_actionCompletionHandlers
;
NSMutableDictionary
*
_presentationCompletionHandlers
;
@implementation
RNNotificationsStore
NSMutableDictionary
*
_actionCompletionHandlers
;
NSMutableDictionary
*
_presentationCompletionHandlers
;
+
(
instancetype
)
sharedInstance
{
static
RNNotificationsStore
*
sharedInstance
=
nil
;
static
dispatch_once_t
onceToken
;
dispatch_once
(
&
onceToken
,
^
{
sharedInstance
=
[[
RNNotificationsStore
alloc
]
init
];
});
return
sharedInstance
;
}
-
(
instancetype
)
init
{
...
...
e2e/Notifications.test.js
View file @
25b5baf8
...
...
@@ -2,20 +2,43 @@ const Utils = require('./Utils');
const
{
elementByLabel
,
elementById
}
=
Utils
;
describe
(
'
Notifications
'
,
()
=>
{
beforeEach
(
async
()
=>
{
await
device
.
relaunchApp
({
permissions
:
{
notifications
:
'
YES
'
}});
describe
(
'
Foreground
'
,
()
=>
{
beforeEach
(
async
()
=>
{
await
device
.
relaunchApp
({
permissions
:
{
notifications
:
'
YES
'
}});
});
it
(
'
Receive notification
'
,
async
()
=>
{
await
device
.
sendUserNotification
(
createNotification
({
link
:
'
foreground/notification
'
}));
await
expect
(
elementByLabel
(
'
foreground/notification
'
)).
toBeVisible
();
});
it
.
only
(
'
Click notification
'
,
async
()
=>
{
await
device
.
sendUserNotification
(
createNotification
({
link
:
'
foreground/notification/click
'
,
showAlert
:
true
}));
await
expect
(
elementByLabel
(
'
Notification Clicked: foreground/notification/click
'
)).
toBeVisible
();
});
});
describe
(
'
Background
'
,
()
=>
{
beforeEach
(
async
()
=>
{
await
device
.
relaunchApp
({
permissions
:
{
notifications
:
'
YES
'
}});
});
it
(
'
Receive notification
'
,
async
()
=>
{
device
.
sendToHome
();
device
.
launchApp
({
newInstance
:
false
,
userNotification
:
createNotification
({
link
:
'
background/notification
'
})});
await
expect
(
elementByLabel
(
'
background/notification
'
)).
toBeVisible
();
});
});
it
(
'
Receive foreground notification
'
,
async
()
=>
{
await
device
.
sendUserNotification
(
getNotification
(
'
explicit/external/link/test_parameter
'
));
// await device.launchApp({newInstance: true, userNotification: getNotification('unknown/link', 'test/category', {parameter: 'test_body_param'})});
// await elementById(TestIDs.SWITCH_TAB_BY_INDEX_BTN).tap();
// await expect(elementByLabel('First Tab')).toBeNotVisible();
// await expect(elementByLabel('Second Tab')).toBeVisible();
describe
(
'
Dead state
'
,
()
=>
{
it
(
'
Receive notification
'
,
async
()
=>
{
await
device
.
launchApp
({
newInstance
:
true
,
userNotification
:
createNotification
({
link
:
'
deadState/notification
'
})});
await
expect
(
elementByLabel
(
'
deadState/notification
'
)).
toBeVisible
();
});
});
});
function
getNotification
(
link
,
category
=
'
com.example.category
'
,
params
=
{
})
{
function
createNotification
({
link
,
showAlert
})
{
return
{
trigger
:
{
type
:
'
push
'
...
...
@@ -26,14 +49,8 @@ function getNotification(link, category = 'com.example.category', params = {}) {
badge
:
1
,
payload
:
{
appId
:
'
14517e1a-3ff0-af98-408e-2bd6953c36a2
'
,
aps
:
{
alert
:
'
this is alert
'
,
sound
:
'
chime.aiff
'
},
category
,
link
,
...
params
},
'
content-available
'
:
0
,
'
action-identifier
'
:
'
default
'
link
,
showAlert
}
};
}
\ No newline at end of file
}
example/index.ios.js
View file @
25b5baf8
...
...
@@ -45,6 +45,14 @@ class NotificationsExampleApp extends Component {
NotificationsIOS
.
addEventListener
(
'
pushKitNotificationReceived
'
,
this
.
onPushKitNotificationReceived
.
bind
(
this
));
}
async
componentDidMount
()
{
const
initialNotification
=
await
NotificationsIOS
.
getInitialNotification
();
if
(
initialNotification
)
{
this
.
setState
({
notifications
:
[
initialNotification
.
getData
().
link
,
...
this
.
state
.
notifications
]});
}
}
onPushRegistered
(
deviceToken
)
{
console
.
log
(
'
Device Token Received:
'
+
deviceToken
);
}
...
...
@@ -62,21 +70,24 @@ class NotificationsExampleApp extends Component {
}
onNotificationReceivedForeground
(
notification
,
completion
)
{
console
.
log
(
'
Notification Received Foreground:
'
+
JSON
.
stringify
(
notification
));
console
.
log
(
'
Notification Received Foreground
with title
:
'
+
JSON
.
stringify
(
notification
));
this
.
setState
({
notifications
:
[...
this
.
state
.
notifications
,
notification
]
notifications
:
[...
this
.
state
.
notifications
,
notification
.
getData
().
link
]
});
completion
({
alert
:
true
,
sound
:
false
,
badge
:
false
});
completion
({
alert
:
notification
.
getData
().
showAlert
,
sound
:
false
,
badge
:
false
});
}
onNotificationOpened
(
notification
,
completion
,
action
)
{
console
.
log
(
'
Notification Opened:
'
+
JSON
.
stringify
(
notification
)
+
JSON
.
stringify
(
action
));
this
.
setState
({
notifications
:
[...
this
.
state
.
notifications
,
`Notification Clicked:
${
notification
.
getData
().
link
}
`
]
});
completion
();
}
renderNotification
(
notification
)
{
return
<
Text
>
{
`
${
''
}
|
${
JSON
.
stringify
(
notification
)
}
`
}
<
/Text>
;
return
<
Text
>
{
`
${
notification
}
`
}
<
/Text>
;
}
render
()
{
...
...
lib/src/index.ios.js
View file @
25b5baf8
...
...
@@ -84,7 +84,7 @@ export default class NotificationsIOS {
}
else
if
(
type
===
DEVICE_NOTIFICATION_OPENED_EVENT
)
{
listener
=
DeviceEventEmitter
.
addListener
(
type
,
(
payload
,
identifier
,
action
)
=>
handler
(
new
IOSNotification
(
payload
),
()
=>
{
(
{
payload
,
identifier
,
action
}
)
=>
handler
(
new
IOSNotification
(
payload
),
()
=>
{
NativeRNNotifications
.
finishHandlingAction
(
identifier
);
},
action
)
);
...
...
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