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
97803877
Commit
97803877
authored
Sep 12, 2019
by
yogevbd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix e2e
parent
c4fa09da
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
48 additions
and
27 deletions
+48
-27
e2e/Notifications.test.js
e2e/Notifications.test.js
+9
-3
example/index.js
example/index.js
+31
-14
lib/src/adapters/NativeCommandsSender.ts
lib/src/adapters/NativeCommandsSender.ts
+2
-2
lib/src/commands/Commands.test.ts
lib/src/commands/Commands.test.ts
+1
-1
lib/src/commands/Commands.ts
lib/src/commands/Commands.ts
+5
-4
package.json
package.json
+0
-3
No files found.
e2e/Notifications.test.js
View file @
97803877
...
...
@@ -9,7 +9,7 @@ describe('Notifications', () => {
describe
(
'
Foreground
'
,
()
=>
{
it
(
'
Should receive notification
'
,
async
()
=>
{
await
device
.
sendUserNotification
(
createNotification
({
link
:
'
foreground/notification
'
}));
await
expect
(
elementByLabel
(
'
foreground/notification
'
)).
toBeVisible
(
);
await
linkShouldBeVisible
(
'
foreground/notification
'
);
});
it
(
'
Should open notification
'
,
async
()
=>
{
...
...
@@ -28,13 +28,19 @@ describe('Notifications', () => {
});
describe
(
'
Dead state
'
,
()
=>
{
it
(
'
Should receive notification
'
,
async
()
=>
{
it
.
only
(
'
Should receive notification
'
,
async
()
=>
{
await
device
.
launchApp
({
newInstance
:
true
,
userNotification
:
createNotification
({
link
:
'
deadState/notification
'
})});
await
expect
(
elementByLabel
(
'
deadState/notification
'
)).
toBeVisible
(
);
await
linkShouldBeVisible
(
'
deadState/notification
'
);
});
});
async
function
linkShouldBeVisible
(
link
)
{
return
await
expect
(
elementByLabel
(
`Extra Link Param:
${
link
}
`
)).
toBeVisible
();
}
});
function
createNotification
({
link
,
showAlert
})
{
return
{
trigger
:
{
...
...
example/index.js
View file @
97803877
...
...
@@ -12,7 +12,8 @@ class NotificationsExampleApp extends Component {
constructor
()
{
super
();
this
.
state
=
{
notifications
:
[]
notifications
:
[],
openedNotifications
:
[],
};
this
.
registerNotificationEvents
();
...
...
@@ -25,28 +26,18 @@ class NotificationsExampleApp extends Component {
notifications
:
[...
this
.
state
.
notifications
,
notification
]
});
completion
({
alert
:
true
,
sound
:
false
,
badge
:
false
});
completion
({
alert
:
notification
.
data
.
showAlert
,
sound
:
false
,
badge
:
false
});
});
Notifications
.
events
().
registerRemoteNotificationOpened
((
notification
,
completion
)
=>
{
this
.
setState
({
notifications
:
[...
this
.
state
.
n
otifications
,
notification
]
openedNotifications
:
[...
this
.
state
.
openedN
otifications
,
notification
]
});
completion
();
});
}
renderNotification
(
notification
)
{
return
(
<
View
style
=
{{
backgroundColor
:
'
lightgray
'
,
margin
:
10
}}
>
<
Text
>
{
`Title:
${
notification
.
title
}
`
}
<
/Text
>
<
Text
>
{
`Body:
${
notification
.
body
}
`
}
<
/Text
>
<
Text
>
{
`Extra Link Param:
${
notification
.
data
.
link
}
`
}
<
/Text
>
<
/View
>
);
}
requestPermissions
()
{
Notifications
.
ios
.
requestPermissions
();
}
...
...
@@ -98,6 +89,26 @@ class NotificationsExampleApp extends Component {
}
}
renderNotification
(
notification
)
{
return
(
<
View
style
=
{{
backgroundColor
:
'
lightgray
'
,
margin
:
10
}}
>
<
Text
>
{
`Title:
${
notification
.
title
}
`
}
<
/Text
>
<
Text
>
{
`Body:
${
notification
.
body
}
`
}
<
/Text
>
<
Text
>
{
`Extra Link Param:
${
notification
.
data
.
link
}
`
}
<
/Text
>
<
/View
>
);
}
renderOpenedNotification
(
notification
)
{
return
(
<
View
style
=
{{
backgroundColor
:
'
lightgray
'
,
margin
:
10
}}
>
<
Text
>
{
`Title:
${
notification
.
title
}
`
}
<
/Text
>
<
Text
>
{
`Body:
${
notification
.
body
}
`
}
<
/Text
>
<
Text
>
{
`Notification Clicked:
${
notification
.
data
.
link
}
`
}
<
/Text
>
<
/View
>
);
}
render
()
{
const
notifications
=
this
.
state
.
notifications
.
map
((
notification
,
idx
)
=>
(
...
...
@@ -105,13 +116,19 @@ class NotificationsExampleApp extends Component {
{
this
.
renderNotification
(
notification
)}
<
/View
>
));
const
openedNotifications
=
this
.
state
.
openedNotifications
.
map
((
notification
,
idx
)
=>
(
<
View
key
=
{
`notification_
${
idx
}
`
}
>
{
this
.
renderOpenedNotification
(
notification
)}
<
/View
>
));
return
(
<
View
style
=
{
styles
.
container
}
>
<
Button
title
=
{
'
Request permissions
'
}
onPress
=
{
this
.
requestPermissions
}
testID
=
{
'
requestPermissions
'
}
/
>
<
Button
title
=
{
'
Send local notification
'
}
onPress
=
{
this
.
sendLocalNotification
}
testID
=
{
'
sendLocalNotification
'
}
/
>
<
Button
title
=
{
'
Remove all delivered notifications
'
}
onPress
=
{
this
.
removeAllDeliveredNotifications
}
/
>
{
notifications
}
{
openedNotifications
}
<
/View
>
);
}
...
...
lib/src/adapters/NativeCommandsSender.ts
View file @
97803877
...
...
@@ -5,7 +5,7 @@ import { NotificationPermissions } from '../interfaces/NotificationPermissions';
import
{
NotificationCategory
}
from
'
../interfaces/NotificationCategory
'
;
interface
NativeCommandsModule
{
getInitialNotification
():
Promise
<
Notification
>
;
getInitialNotification
():
Promise
<
Object
>
;
postLocalNotification
(
notification
:
Notification
,
id
:
number
):
void
;
requestPermissions
():
void
;
abandonPermissions
():
void
;
...
...
@@ -35,7 +35,7 @@ export class NativeCommandsSender {
return
this
.
nativeCommandsModule
.
postLocalNotification
(
notification
,
id
);
}
getInitialNotification
():
Promise
<
Notification
>
{
getInitialNotification
():
Promise
<
Object
>
{
return
this
.
nativeCommandsModule
.
getInitialNotification
();
}
...
...
lib/src/commands/Commands.test.ts
View file @
97803877
...
...
@@ -32,7 +32,7 @@ describe('Commands', () => {
it
(
'
returns a promise with the initial notification
'
,
async
()
=>
{
const
expectedNotification
:
Notification
=
new
Notification
({
identifier
:
'
id
'
});
when
(
mockedNativeCommandsSender
.
getInitialNotification
()).
thenResolve
(
expectedNotification
{
identifier
:
'
id
'
}
);
const
result
=
await
uut
.
getInitialNotification
();
expect
(
result
).
toEqual
(
expectedNotification
);
...
...
lib/src/commands/Commands.ts
View file @
97803877
...
...
@@ -17,9 +17,10 @@ export class Commands {
return
result
;
}
public
getInitialNotification
():
Promise
<
Notification
>
{
const
result
=
this
.
nativeCommandsSender
.
getInitialNotification
();
return
result
;
public
async
getInitialNotification
():
Promise
<
Notification
>
{
return
this
.
nativeCommandsSender
.
getInitialNotification
().
then
((
payload
)
=>
{
return
new
Notification
(
payload
);
});
}
public
requestPermissions
()
{
...
...
package.json
View file @
97803877
...
...
@@ -37,9 +37,6 @@
"androidStudio"
:
"open -a /Applications/Android
\\
Studio.app ./example/android"
},
"nativePackage"
:
true
,
"dependencies"
:
{
"
uuid
"
:
"
^2.0.3
"
},
"peerDependencies"
:
{
"react"
:
"
>=0.14.5
"
,
"react-native"
:
"
>=0.25.1
"
...
...
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