Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
react-native-fcm
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
ym
react-native-fcm
Commits
80b412d9
Commit
80b412d9
authored
Apr 23, 2018
by
Libin Lu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change
parent
9345da2b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
15 deletions
+13
-15
Examples/firebase-migration/app/App.js
Examples/firebase-migration/app/App.js
+6
-9
Examples/firebase-migration/app/Listeners.js
Examples/firebase-migration/app/Listeners.js
+7
-6
No files found.
Examples/firebase-migration/app/App.js
View file @
80b412d9
...
@@ -12,7 +12,8 @@ import {
...
@@ -12,7 +12,8 @@ import {
View
,
View
,
Clipboard
,
Clipboard
,
Platform
,
Platform
,
ScrollView
ScrollView
,
AsyncStorage
}
from
'
react-native
'
;
}
from
'
react-native
'
;
import
{
StackNavigator
}
from
'
react-navigation
'
;
import
{
StackNavigator
}
from
'
react-navigation
'
;
...
@@ -140,14 +141,10 @@ class MainPage extends Component {
...
@@ -140,14 +141,10 @@ class MainPage extends Component {
body
=
{
body
=
{
"
to
"
:
token
,
"
to
"
:
token
,
"
data
"
:{
"
data
"
:{
"
custom_notification
"
:
{
"
title
"
:
"
Simple FCM Client
"
,
"
title
"
:
"
Simple FCM Client
"
,
"
body
"
:
"
Click me to go to detail
"
,
"
body
"
:
"
Click me to go to detail
"
,
data
:
{
targetScreen
:
'
detail
'
,
targetScreen
:
'
detail
'
,
now
:
new
Date
().
toISOString
()
now
:
new
Date
().
toISOString
()
}
}
},
},
"
priority
"
:
10
"
priority
"
:
10
}
}
...
...
Examples/firebase-migration/app/Listeners.js
View file @
80b412d9
...
@@ -3,13 +3,14 @@ import { Platform, AsyncStorage, AppState } from 'react-native';
...
@@ -3,13 +3,14 @@ import { Platform, AsyncStorage, AppState } from 'react-native';
import
firebase
from
'
react-native-firebase
'
;
import
firebase
from
'
react-native-firebase
'
;
function
displayNotificationFromCustomData
(
message
:
RemoteMessage
){
function
displayNotificationFromCustomData
(
message
:
RemoteMessage
){
if
(
message
.
data
&&
message
.
data
.
custom_notification
){
if
(
message
.
data
&&
message
.
data
.
title
){
let
notification
=
new
firebase
.
notifications
.
Notification
();
let
notification
=
new
firebase
.
notifications
.
Notification
();
notification
=
notification
.
setNotificationId
(
new
Date
().
valueOf
().
toString
())
notification
=
notification
.
setTitle
(
message
.
title
)
.
setTitle
(
message
.
data
.
title
)
.
setBody
(
message
.
body
)
.
setBody
(
message
.
data
.
body
)
.
setData
(
message
.
data
)
.
setData
(
message
.
data
)
.
setSound
(
"
bell.mp3
"
)
.
setSound
(
"
bell.mp3
"
)
notification
.
android
.
setPriority
(
firebase
.
notifications
.
Android
.
Priority
.
High
)
notification
.
android
.
setChannelId
(
"
test-channel
"
)
notification
.
android
.
setChannelId
(
"
test-channel
"
)
firebase
.
notifications
().
displayNotification
(
notification
);
firebase
.
notifications
().
displayNotification
(
notification
);
}
}
...
@@ -17,7 +18,7 @@ function displayNotificationFromCustomData(message: RemoteMessage){
...
@@ -17,7 +18,7 @@ function displayNotificationFromCustomData(message: RemoteMessage){
export
async
function
registerKilledListener
(
message
:
RemoteMessage
){
export
async
function
registerKilledListener
(
message
:
RemoteMessage
){
await
AsyncStorage
.
setItem
(
'
lastNotification
'
,
JSON
.
stringify
(
message
.
data
));
await
AsyncStorage
.
setItem
(
'
lastNotification
'
,
JSON
.
stringify
(
message
.
data
));
displayNotificationFromCustomData
();
displayNotificationFromCustomData
(
message
);
}
}
// these callback will be triggered only when app is foreground or background
// these callback will be triggered only when app is foreground or background
...
@@ -43,7 +44,7 @@ export function registerAppListener(navigation){
...
@@ -43,7 +44,7 @@ export function registerAppListener(navigation){
});
});
this
.
messageListener
=
firebase
.
messaging
().
onMessage
((
message
:
RemoteMessage
)
=>
{
this
.
messageListener
=
firebase
.
messaging
().
onMessage
((
message
:
RemoteMessage
)
=>
{
displayNotificationFromCustomData
();
displayNotificationFromCustomData
(
message
);
});
});
}
}
...
...
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