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
4e661458
Commit
4e661458
authored
Sep 09, 2019
by
yogevbd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Split Notification.ts, Fix android example module
parent
36a833fc
Changes
21
Show whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
117 additions
and
111 deletions
+117
-111
example/android/myapplication/build.gradle
example/android/myapplication/build.gradle
+1
-2
example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/MainActivity.java
...va/com/wix/reactnativenotifications/app/MainActivity.java
+3
-25
example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/MainApplication.java
...com/wix/reactnativenotifications/app/MainApplication.java
+6
-1
example/index.js
example/index.js
+17
-14
lib/android/app/build.gradle
lib/android/app/build.gradle
+1
-1
lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotificationProps.java
...otifications/core/notification/PushNotificationProps.java
+0
-10
lib/src/Notifications.ts
lib/src/Notifications.ts
+2
-1
lib/src/adapters/CompletionCallbackWrapper.ts
lib/src/adapters/CompletionCallbackWrapper.ts
+3
-1
lib/src/adapters/NativeCommandsSender.ts
lib/src/adapters/NativeCommandsSender.ts
+4
-1
lib/src/adapters/NativeEventsReceiver.ts
lib/src/adapters/NativeEventsReceiver.ts
+6
-2
lib/src/commands/Commands.test.ts
lib/src/commands/Commands.test.ts
+7
-5
lib/src/commands/Commands.ts
lib/src/commands/Commands.ts
+3
-1
lib/src/events/EventsRegistry.test.ts
lib/src/events/EventsRegistry.test.ts
+10
-9
lib/src/events/EventsRegistry.ts
lib/src/events/EventsRegistry.ts
+2
-1
lib/src/interfaces/Notification.ts
lib/src/interfaces/Notification.ts
+16
-35
lib/src/interfaces/NotificationActionResponse.ts
lib/src/interfaces/NotificationActionResponse.ts
+4
-0
lib/src/interfaces/NotificationCategory.ts
lib/src/interfaces/NotificationCategory.ts
+18
-0
lib/src/interfaces/NotificationCompletion.ts
lib/src/interfaces/NotificationCompletion.ts
+5
-0
lib/src/interfaces/NotificationEvents.ts
lib/src/interfaces/NotificationEvents.ts
+2
-1
lib/src/interfaces/NotificationPermissions.ts
lib/src/interfaces/NotificationPermissions.ts
+5
-0
package.json
package.json
+2
-1
No files found.
example/android/myapplication/build.gradle
View file @
4e661458
...
@@ -13,10 +13,9 @@ apply from: "../../../node_modules/react-native/react.gradle"
...
@@ -13,10 +13,9 @@ apply from: "../../../node_modules/react-native/react.gradle"
android
{
android
{
compileSdkVersion
28
compileSdkVersion
28
buildToolsVersion
"28.0.3"
buildToolsVersion
"28.0.3"
defaultConfig
{
defaultConfig
{
applicationId
"com.wix.reactnativenotifications.app"
applicationId
"com.wix.reactnativenotifications.app"
minSdkVersion
1
9
minSdkVersion
1
6
targetSdkVersion
28
targetSdkVersion
28
versionCode
1
versionCode
1
versionName
"1.0"
versionName
"1.0"
...
...
example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/MainActivity.java
View file @
4e661458
package
com.wix.reactnativenotifications.app
;
package
com.wix.reactnativenotifications.app
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.view.ViewGroup
;
import
android.widget.Toolbar
;
import
com.facebook.react.ReactActivity
;
import
com.facebook.react.ReactActivity
;
import
com.facebook.react.ReactRootView
;
import
static
android
.
os
.
Build
.
VERSION
.
SDK_INT
;
public
class
MainActivity
extends
ReactActivity
{
public
class
MainActivity
extends
ReactActivity
{
private
ReactRootView
mReactRootView
;
@Override
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
super
.
onCreate
(
savedInstanceState
);
ViewGroup
layout
;
if
(
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP
)
{
layout
=
(
ViewGroup
)
getLayoutInflater
().
inflate
(
R
.
layout
.
activity_main
,
null
);
Toolbar
toolbar
=
layout
.
findViewById
(
R
.
id
.
toolbar
);
setActionBar
(
toolbar
);
}
else
{
layout
=
(
ViewGroup
)
getLayoutInflater
().
inflate
(
R
.
layout
.
activity_main_prelollipop
,
null
);
}
}
mReactRootView
=
new
ReactRootView
(
this
);
layout
.
addView
(
mReactRootView
);
setContentView
(
layout
);
startReactApplication
();
@Override
}
protected
String
getMainComponentName
()
{
return
"NotificationsExampleApp"
;
private
void
startReactApplication
()
{
mReactRootView
.
startReactApplication
(
getReactInstanceManager
(),
"NotificationsExampleApp"
,
null
);
}
}
}
}
example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/MainApplication.java
View file @
4e661458
...
@@ -26,6 +26,11 @@ public class MainApplication extends Application implements ReactApplication {
...
@@ -26,6 +26,11 @@ public class MainApplication extends Application implements ReactApplication {
new
RNNotificationsPackage
(
MainApplication
.
this
)
new
RNNotificationsPackage
(
MainApplication
.
this
)
);
);
}
}
@Override
protected
String
getJSMainModuleName
()
{
return
"index"
;
}
};
};
@Override
@Override
...
...
example/index.js
View file @
4e661458
...
@@ -6,7 +6,7 @@ import {
...
@@ -6,7 +6,7 @@ import {
Button
Button
}
from
'
react-native
'
;
}
from
'
react-native
'
;
import
React
,
{
Component
}
from
'
react
'
;
import
React
,
{
Component
}
from
'
react
'
;
import
{
Notifications
}
from
'
react-native-notifications
'
;
import
{
Notifications
}
from
'
react-native-notifications
'
;
class
NotificationsExampleApp
extends
Component
{
class
NotificationsExampleApp
extends
Component
{
constructor
()
{
constructor
()
{
...
@@ -22,7 +22,7 @@ class NotificationsExampleApp extends Component {
...
@@ -22,7 +22,7 @@ class NotificationsExampleApp extends Component {
registerNotificationEvents
()
{
registerNotificationEvents
()
{
Notifications
.
events
().
registerNotificationReceived
((
notification
,
completion
)
=>
{
Notifications
.
events
().
registerNotificationReceived
((
notification
,
completion
)
=>
{
this
.
setState
({
this
.
setState
({
notifications
:
[...
this
.
state
.
notifications
,
notification
.
link
]
notifications
:
[...
this
.
state
.
notifications
,
notification
]
});
});
completion
({
alert
:
true
,
sound
:
false
,
badge
:
false
});
completion
({
alert
:
true
,
sound
:
false
,
badge
:
false
});
...
@@ -30,7 +30,7 @@ class NotificationsExampleApp extends Component {
...
@@ -30,7 +30,7 @@ class NotificationsExampleApp extends Component {
Notifications
.
events
().
registerRemoteNotificationOpened
((
notification
,
completion
)
=>
{
Notifications
.
events
().
registerRemoteNotificationOpened
((
notification
,
completion
)
=>
{
this
.
setState
({
this
.
setState
({
notifications
:
[...
this
.
state
.
notifications
,
`Notification Clicked:
${
notification
.
link
}
`
]
notifications
:
[...
this
.
state
.
notifications
,
notification
]
});
});
completion
();
completion
();
...
@@ -38,7 +38,13 @@ class NotificationsExampleApp extends Component {
...
@@ -38,7 +38,13 @@ class NotificationsExampleApp extends Component {
}
}
renderNotification
(
notification
)
{
renderNotification
(
notification
)
{
return
<
Text
>
{
`
${
notification
}
`
}
<
/Text>
;
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
()
{
requestPermissions
()
{
...
@@ -88,13 +94,10 @@ class NotificationsExampleApp extends Component {
...
@@ -88,13 +94,10 @@ class NotificationsExampleApp extends Component {
async
componentDidMount
()
{
async
componentDidMount
()
{
const
initialNotification
=
await
Notifications
.
getInitialNotification
();
const
initialNotification
=
await
Notifications
.
getInitialNotification
();
if
(
initialNotification
)
{
if
(
initialNotification
)
{
this
.
setState
({
notifications
:
[
initialNotification
.
link
,
...
this
.
state
.
notifications
]});
this
.
setState
({
notifications
:
[
initialNotification
,
...
this
.
state
.
notifications
]});
}
}
}
}
componentWillUnmount
()
{
}
render
()
{
render
()
{
const
notifications
=
this
.
state
.
notifications
.
map
((
notification
,
idx
)
=>
const
notifications
=
this
.
state
.
notifications
.
map
((
notification
,
idx
)
=>
(
(
...
@@ -105,9 +108,9 @@ class NotificationsExampleApp extends Component {
...
@@ -105,9 +108,9 @@ class NotificationsExampleApp extends Component {
return
(
return
(
<
View
style
=
{
styles
.
container
}
>
<
View
style
=
{
styles
.
container
}
>
<
Button
title
=
{
'
Request permissions
'
}
onPress
=
{
this
.
requestPermissions
}
testID
=
{
'
requestPermissions
'
}
/
>
<
Button
title
=
{
'
Request permissions
'
}
onPress
=
{
this
.
requestPermissions
}
testID
=
{
'
requestPermissions
'
}
/
>
<
Button
title
=
{
'
Send local notification
'
}
onPress
=
{
this
.
sendLocalNotification
}
testID
=
{
'
sendLocalNotification
'
}
/
>
<
Button
title
=
{
'
Send local notification
'
}
onPress
=
{
this
.
sendLocalNotification
}
testID
=
{
'
sendLocalNotification
'
}
/
>
<
Button
title
=
{
'
Remove all delivered notifications
'
}
onPress
=
{
this
.
removeAllDeliveredNotifications
}
/
>
<
Button
title
=
{
'
Remove all delivered notifications
'
}
onPress
=
{
this
.
removeAllDeliveredNotifications
}
/
>
{
notifications
}
{
notifications
}
<
/View
>
<
/View
>
);
);
...
...
lib/android/app/build.gradle
View file @
4e661458
...
@@ -6,7 +6,7 @@ android {
...
@@ -6,7 +6,7 @@ android {
buildToolsVersion
'28.0.3'
buildToolsVersion
'28.0.3'
defaultConfig
{
defaultConfig
{
minSdkVersion
1
9
minSdkVersion
1
6
targetSdkVersion
27
targetSdkVersion
27
versionCode
1
versionCode
1
versionName
"1.0"
versionName
"1.0"
...
...
lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotificationProps.java
View file @
4e661458
...
@@ -6,16 +6,6 @@ public class PushNotificationProps {
...
@@ -6,16 +6,6 @@ public class PushNotificationProps {
protected
Bundle
mBundle
;
protected
Bundle
mBundle
;
public
PushNotificationProps
()
{
mBundle
=
new
Bundle
();
}
public
PushNotificationProps
(
String
title
,
String
body
)
{
mBundle
=
new
Bundle
();
mBundle
.
putString
(
"title"
,
title
);
mBundle
.
putString
(
"body"
,
body
);
}
public
PushNotificationProps
(
Bundle
bundle
)
{
public
PushNotificationProps
(
Bundle
bundle
)
{
mBundle
=
bundle
;
mBundle
=
bundle
;
}
}
...
...
lib/src/Notifications.ts
View file @
4e661458
...
@@ -2,9 +2,10 @@ import { NativeCommandsSender } from './adapters/NativeCommandsSender';
...
@@ -2,9 +2,10 @@ import { NativeCommandsSender } from './adapters/NativeCommandsSender';
import
{
NativeEventsReceiver
}
from
'
./adapters/NativeEventsReceiver
'
;
import
{
NativeEventsReceiver
}
from
'
./adapters/NativeEventsReceiver
'
;
import
{
Commands
}
from
'
./commands/Commands
'
;
import
{
Commands
}
from
'
./commands/Commands
'
;
import
{
EventsRegistry
}
from
'
./events/EventsRegistry
'
;
import
{
EventsRegistry
}
from
'
./events/EventsRegistry
'
;
import
{
Notification
,
NotificationCategory
}
from
'
./interfaces/Notification
'
;
import
{
Notification
}
from
'
./interfaces/Notification
'
;
import
{
UniqueIdProvider
}
from
'
./adapters/UniqueIdProvider
'
;
import
{
UniqueIdProvider
}
from
'
./adapters/UniqueIdProvider
'
;
import
{
CompletionCallbackWrapper
}
from
'
./adapters/CompletionCallbackWrapper
'
;
import
{
CompletionCallbackWrapper
}
from
'
./adapters/CompletionCallbackWrapper
'
;
import
{
NotificationCategory
}
from
'
./interfaces/NotificationCategory
'
;
export
class
NotificationsRoot
{
export
class
NotificationsRoot
{
private
readonly
nativeEventsReceiver
:
NativeEventsReceiver
;
private
readonly
nativeEventsReceiver
:
NativeEventsReceiver
;
...
...
lib/src/adapters/CompletionCallbackWrapper.ts
View file @
4e661458
import
{
NativeCommandsSender
}
from
'
./NativeCommandsSender
'
;
import
{
NativeCommandsSender
}
from
'
./NativeCommandsSender
'
;
import
{
NotificationCompletion
,
Notification
}
from
'
../interfaces/Notification
'
;
import
{
Notification
}
from
'
../interfaces/Notification
'
;
import
{
NotificationCompletion
}
from
'
../interfaces/NotificationCompletion
'
;
import
{
Platform
}
from
'
react-native
'
;
import
{
Platform
}
from
'
react-native
'
;
export
class
CompletionCallbackWrapper
{
export
class
CompletionCallbackWrapper
{
constructor
(
constructor
(
...
...
lib/src/adapters/NativeCommandsSender.ts
View file @
4e661458
import
{
NativeModules
}
from
'
react-native
'
;
import
{
NativeModules
}
from
'
react-native
'
;
import
{
Notification
,
NotificationCategory
,
NotificationPermissions
,
NotificationCompletion
}
from
'
../interfaces/Notification
'
;
import
{
Notification
}
from
'
../interfaces/Notification
'
;
import
{
NotificationCompletion
}
from
'
../interfaces/NotificationCompletion
'
;
import
{
NotificationPermissions
}
from
'
../interfaces/NotificationPermissions
'
;
import
{
NotificationCategory
}
from
'
../interfaces/NotificationCategory
'
;
interface
NativeCommandsModule
{
interface
NativeCommandsModule
{
getInitialNotification
():
Promise
<
Notification
>
;
getInitialNotification
():
Promise
<
Notification
>
;
...
...
lib/src/adapters/NativeEventsReceiver.ts
View file @
4e661458
...
@@ -19,7 +19,9 @@ export class NativeEventsReceiver {
...
@@ -19,7 +19,9 @@ export class NativeEventsReceiver {
}
}
public
registerRemoteNotificationReceived
(
callback
:
(
notification
:
Notification
)
=>
void
):
EmitterSubscription
{
public
registerRemoteNotificationReceived
(
callback
:
(
notification
:
Notification
)
=>
void
):
EmitterSubscription
{
return
this
.
emitter
.
addListener
(
'
notificationReceived
'
,
callback
);
return
this
.
emitter
.
addListener
(
'
notificationReceived
'
,
(
payload
)
=>
{
callback
(
new
Notification
(
payload
));
});
}
}
public
registerPushKitNotificationReceived
(
callback
:
(
event
:
object
)
=>
void
):
EmitterSubscription
{
public
registerPushKitNotificationReceived
(
callback
:
(
event
:
object
)
=>
void
):
EmitterSubscription
{
...
@@ -27,7 +29,9 @@ export class NativeEventsReceiver {
...
@@ -27,7 +29,9 @@ export class NativeEventsReceiver {
}
}
public
registerRemoteNotificationOpened
(
callback
:
(
response
:
Notification
,
completion
:
()
=>
void
)
=>
void
):
EmitterSubscription
{
public
registerRemoteNotificationOpened
(
callback
:
(
response
:
Notification
,
completion
:
()
=>
void
)
=>
void
):
EmitterSubscription
{
return
this
.
emitter
.
addListener
(
'
notificationOpened
'
,
callback
);
return
this
.
emitter
.
addListener
(
'
notificationOpened
'
,
(
payload
,
completion
)
=>
{
callback
(
new
Notification
(
payload
),
completion
);
});
}
}
public
registerRemoteNotificationsRegistrationFailed
(
callback
:
(
event
:
RegistrationError
)
=>
void
):
EmitterSubscription
{
public
registerRemoteNotificationsRegistrationFailed
(
callback
:
(
event
:
RegistrationError
)
=>
void
):
EmitterSubscription
{
...
...
lib/src/commands/Commands.test.ts
View file @
4e661458
...
@@ -3,8 +3,10 @@ import { mock, verify, instance, when, anyNumber } from 'ts-mockito';
...
@@ -3,8 +3,10 @@ import { mock, verify, instance, when, anyNumber } from 'ts-mockito';
import
{
Commands
}
from
'
./Commands
'
;
import
{
Commands
}
from
'
./Commands
'
;
import
{
NativeCommandsSender
}
from
'
../adapters/NativeCommandsSender
'
;
import
{
NativeCommandsSender
}
from
'
../adapters/NativeCommandsSender
'
;
import
{
Notification
,
NotificationCategory
,
NotificationPermissions
}
from
'
../interfaces/Notification
'
;
import
{
Notification
}
from
'
../interfaces/Notification
'
;
import
{
UniqueIdProvider
}
from
'
../adapters/UniqueIdProvider
'
;
import
{
UniqueIdProvider
}
from
'
../adapters/UniqueIdProvider
'
;
import
{
NotificationCategory
}
from
'
../interfaces/NotificationCategory
'
;
import
{
NotificationPermissions
}
from
'
../interfaces/NotificationPermissions
'
;
describe
(
'
Commands
'
,
()
=>
{
describe
(
'
Commands
'
,
()
=>
{
let
uut
:
Commands
;
let
uut
:
Commands
;
...
@@ -28,7 +30,7 @@ describe('Commands', () => {
...
@@ -28,7 +30,7 @@ describe('Commands', () => {
});
});
it
(
'
returns a promise with the initial notification
'
,
async
()
=>
{
it
(
'
returns a promise with the initial notification
'
,
async
()
=>
{
const
expectedNotification
:
Notification
=
{
identifier
:
'
id
'
,
data
:
{},
alert
:
'
alert
'
}
;
const
expectedNotification
:
Notification
=
new
Notification
({
identifier
:
'
id
'
})
;
when
(
mockedNativeCommandsSender
.
getInitialNotification
()).
thenResolve
(
when
(
mockedNativeCommandsSender
.
getInitialNotification
()).
thenResolve
(
expectedNotification
expectedNotification
);
);
...
@@ -75,19 +77,19 @@ describe('Commands', () => {
...
@@ -75,19 +77,19 @@ describe('Commands', () => {
describe
(
'
postLocalNotification
'
,
()
=>
{
describe
(
'
postLocalNotification
'
,
()
=>
{
it
(
'
sends to native
'
,
()
=>
{
it
(
'
sends to native
'
,
()
=>
{
const
notification
:
Notification
=
{
identifier
:
'
id
'
,
alert
:
'
alert
'
,
data
:
{}}
;
const
notification
:
Notification
=
new
Notification
({
identifier
:
'
id
'
})
;
uut
.
postLocalNotification
(
notification
);
uut
.
postLocalNotification
(
notification
);
verify
(
mockedNativeCommandsSender
.
postLocalNotification
(
notification
,
anyNumber
())).
called
();
verify
(
mockedNativeCommandsSender
.
postLocalNotification
(
notification
,
anyNumber
())).
called
();
});
});
it
(
'
generates unique identifier
'
,
()
=>
{
it
(
'
generates unique identifier
'
,
()
=>
{
const
notification
:
Notification
=
{
identifier
:
'
id
'
,
data
:
{},
alert
:
'
alert
'
}
;
const
notification
:
Notification
=
new
Notification
({
identifier
:
'
id
'
})
;
uut
.
postLocalNotification
(
notification
);
uut
.
postLocalNotification
(
notification
);
verify
(
mockedNativeCommandsSender
.
postLocalNotification
(
notification
,
anyNumber
())).
called
();
verify
(
mockedNativeCommandsSender
.
postLocalNotification
(
notification
,
anyNumber
())).
called
();
});
});
it
(
'
use passed notification id
'
,
()
=>
{
it
(
'
use passed notification id
'
,
()
=>
{
const
notification
:
Notification
=
{
identifier
:
'
id
'
,
data
:
{},
alert
:
'
alert
'
}
;
const
notification
:
Notification
=
new
Notification
({
identifier
:
'
id
'
})
;
const
passedId
:
number
=
2
;
const
passedId
:
number
=
2
;
uut
.
postLocalNotification
(
notification
,
passedId
);
uut
.
postLocalNotification
(
notification
,
passedId
);
verify
(
mockedNativeCommandsSender
.
postLocalNotification
(
notification
,
passedId
)).
called
();
verify
(
mockedNativeCommandsSender
.
postLocalNotification
(
notification
,
passedId
)).
called
();
...
...
lib/src/commands/Commands.ts
View file @
4e661458
import
*
as
_
from
'
lodash
'
;
import
*
as
_
from
'
lodash
'
;
import
{
NativeCommandsSender
}
from
'
../adapters/NativeCommandsSender
'
;
import
{
NativeCommandsSender
}
from
'
../adapters/NativeCommandsSender
'
;
import
{
Notification
,
NotificationCategory
,
NotificationPermissions
}
from
'
../interfaces/Notification
'
;
import
{
Notification
}
from
'
../interfaces/Notification
'
;
import
{
NotificationCategory
}
from
'
../interfaces/NotificationCategory
'
;
import
{
NotificationPermissions
}
from
'
../interfaces/NotificationPermissions
'
;
import
{
UniqueIdProvider
}
from
'
../adapters/UniqueIdProvider
'
;
import
{
UniqueIdProvider
}
from
'
../adapters/UniqueIdProvider
'
;
export
class
Commands
{
export
class
Commands
{
...
...
lib/src/events/EventsRegistry.test.ts
View file @
4e661458
import
{
EventsRegistry
}
from
'
./EventsRegistry
'
;
import
{
EventsRegistry
}
from
'
./EventsRegistry
'
;
import
{
NativeEventsReceiver
}
from
'
../adapters/NativeEventsReceiver.mock
'
;
import
{
NativeEventsReceiver
}
from
'
../adapters/NativeEventsReceiver.mock
'
;
import
{
Notification
Completion
,
Notification
}
from
'
../interfaces/Notification
'
;
import
{
Notification
}
from
'
../interfaces/Notification
'
;
import
{
CompletionCallbackWrapper
}
from
'
../adapters/CompletionCallbackWrapper
'
;
import
{
CompletionCallbackWrapper
}
from
'
../adapters/CompletionCallbackWrapper
'
;
import
{
NativeCommandsSender
}
from
'
../adapters/NativeCommandsSender.mock
'
;
import
{
NativeCommandsSender
}
from
'
../adapters/NativeCommandsSender.mock
'
;
import
{
NotificationResponse
}
from
'
../interfaces/NotificationEvents
'
;
import
{
NotificationResponse
}
from
'
../interfaces/NotificationEvents
'
;
import
{
Platform
}
from
'
react-native
'
;
import
{
Platform
}
from
'
react-native
'
;
import
{
NotificationCompletion
}
from
'
../interfaces/NotificationCompletion
'
;
describe
(
'
EventsRegistry
'
,
()
=>
{
describe
(
'
EventsRegistry
'
,
()
=>
{
let
uut
:
EventsRegistry
;
let
uut
:
EventsRegistry
;
...
@@ -28,7 +29,7 @@ describe('EventsRegistry', () => {
...
@@ -28,7 +29,7 @@ describe('EventsRegistry', () => {
it
(
'
should wrap callback with completion block
'
,
()
=>
{
it
(
'
should wrap callback with completion block
'
,
()
=>
{
const
wrappedCallback
=
jest
.
fn
();
const
wrappedCallback
=
jest
.
fn
();
const
notification
:
Notification
=
{
identifier
:
'
identifier
'
,
data
:
{},
alert
:
'
alert
'
}
const
notification
:
Notification
=
new
Notification
({
identifier
:
'
identifier
'
});
uut
.
registerNotificationReceived
(
wrappedCallback
);
uut
.
registerNotificationReceived
(
wrappedCallback
);
const
call
=
mockNativeEventsReceiver
.
registerRemoteNotificationReceived
.
mock
.
calls
[
0
][
0
];
const
call
=
mockNativeEventsReceiver
.
registerRemoteNotificationReceived
.
mock
.
calls
[
0
][
0
];
...
@@ -39,7 +40,7 @@ describe('EventsRegistry', () => {
...
@@ -39,7 +40,7 @@ describe('EventsRegistry', () => {
});
});
it
(
'
should wrap callback with completion block
'
,
()
=>
{
it
(
'
should wrap callback with completion block
'
,
()
=>
{
const
expectedNotification
:
Notification
=
{
identifier
:
'
identifier
'
,
data
:
{},
alert
:
'
alert
'
}
const
expectedNotification
:
Notification
=
new
Notification
({
identifier
:
'
identifier
'
});
uut
.
registerNotificationReceived
((
notification
)
=>
{
uut
.
registerNotificationReceived
((
notification
)
=>
{
expect
(
notification
).
toEqual
(
expectedNotification
);
expect
(
notification
).
toEqual
(
expectedNotification
);
...
@@ -49,7 +50,7 @@ describe('EventsRegistry', () => {
...
@@ -49,7 +50,7 @@ describe('EventsRegistry', () => {
});
});
it
(
'
should invoke finishPresentingNotification
'
,
()
=>
{
it
(
'
should invoke finishPresentingNotification
'
,
()
=>
{
const
notification
:
Notification
=
{
identifier
:
'
notificationId
'
,
data
:
{},
alert
:
'
alert
'
}
const
notification
:
Notification
=
new
Notification
({
identifier
:
'
notificationId
'
});
const
response
:
NotificationCompletion
=
{
alert
:
true
}
const
response
:
NotificationCompletion
=
{
alert
:
true
}
uut
.
registerNotificationReceived
((
notification
,
completion
)
=>
{
uut
.
registerNotificationReceived
((
notification
,
completion
)
=>
{
...
@@ -63,7 +64,7 @@ describe('EventsRegistry', () => {
...
@@ -63,7 +64,7 @@ describe('EventsRegistry', () => {
it
(
'
should not invoke finishPresentingNotification on Android
'
,
()
=>
{
it
(
'
should not invoke finishPresentingNotification on Android
'
,
()
=>
{
Platform
.
OS
=
'
android
'
;
Platform
.
OS
=
'
android
'
;
const
expectedNotification
:
Notification
=
{
identifier
:
'
notificationId
'
,
data
:
{},
alert
:
'
alert
'
}
const
expectedNotification
:
Notification
=
new
Notification
({
identifier
:
'
notificationId
'
});
const
response
:
NotificationCompletion
=
{
alert
:
true
}
const
response
:
NotificationCompletion
=
{
alert
:
true
}
uut
.
registerNotificationReceived
((
notification
,
completion
)
=>
{
uut
.
registerNotificationReceived
((
notification
,
completion
)
=>
{
...
@@ -88,7 +89,7 @@ describe('EventsRegistry', () => {
...
@@ -88,7 +89,7 @@ describe('EventsRegistry', () => {
it
(
'
should wrap callback with completion block
'
,
()
=>
{
it
(
'
should wrap callback with completion block
'
,
()
=>
{
const
wrappedCallback
=
jest
.
fn
();
const
wrappedCallback
=
jest
.
fn
();
const
notification
:
Notification
=
{
identifier
:
'
identifier
'
,
data
:
{},
alert
:
'
alert
'
}
;
const
notification
:
Notification
=
new
Notification
({
identifier
:
'
identifier
'
})
;
const
response
:
NotificationResponse
=
{
notification
,
identifier
:
'
responseId
'
};
const
response
:
NotificationResponse
=
{
notification
,
identifier
:
'
responseId
'
};
uut
.
registerRemoteNotificationOpened
(
wrappedCallback
);
uut
.
registerRemoteNotificationOpened
(
wrappedCallback
);
...
@@ -100,7 +101,7 @@ describe('EventsRegistry', () => {
...
@@ -100,7 +101,7 @@ describe('EventsRegistry', () => {
});
});
it
(
'
should wrap callback with completion block
'
,
()
=>
{
it
(
'
should wrap callback with completion block
'
,
()
=>
{
const
notification
:
Notification
=
{
identifier
:
'
identifier
'
,
data
:
{},
alert
:
'
alert
'
}
const
notification
:
Notification
=
new
Notification
({
identifier
:
'
identifier
'
});
const
expectedResponse
:
NotificationResponse
=
{
notification
,
identifier
:
'
responseId
'
}
const
expectedResponse
:
NotificationResponse
=
{
notification
,
identifier
:
'
responseId
'
}
uut
.
registerRemoteNotificationOpened
((
response
)
=>
{
uut
.
registerRemoteNotificationOpened
((
response
)
=>
{
...
@@ -111,7 +112,7 @@ describe('EventsRegistry', () => {
...
@@ -111,7 +112,7 @@ describe('EventsRegistry', () => {
});
});
it
(
'
calling completion should invoke finishHandlingAction
'
,
()
=>
{
it
(
'
calling completion should invoke finishHandlingAction
'
,
()
=>
{
const
expectedNotification
:
Notification
=
{
identifier
:
'
notificationId
'
,
data
:
{},
alert
:
'
alert
'
}
const
expectedNotification
:
Notification
=
new
Notification
({
identifier
:
'
notificationId
'
});
uut
.
registerRemoteNotificationOpened
((
notification
,
completion
)
=>
{
uut
.
registerRemoteNotificationOpened
((
notification
,
completion
)
=>
{
completion
();
completion
();
...
@@ -125,7 +126,7 @@ describe('EventsRegistry', () => {
...
@@ -125,7 +126,7 @@ describe('EventsRegistry', () => {
it
(
'
should not invoke finishHandlingAction on Android
'
,
()
=>
{
it
(
'
should not invoke finishHandlingAction on Android
'
,
()
=>
{
Platform
.
OS
=
'
android
'
;
Platform
.
OS
=
'
android
'
;
const
expectedNotification
:
Notification
=
{
identifier
:
'
notificationId
'
,
data
:
{},
alert
:
'
alert
'
}
const
expectedNotification
:
Notification
=
new
Notification
({
identifier
:
'
notificationId
'
});
uut
.
registerRemoteNotificationOpened
((
notification
,
completion
)
=>
{
uut
.
registerRemoteNotificationOpened
((
notification
,
completion
)
=>
{
completion
();
completion
();
...
...
lib/src/events/EventsRegistry.ts
View file @
4e661458
...
@@ -7,7 +7,8 @@ import {
...
@@ -7,7 +7,8 @@ import {
NotificationResponse
NotificationResponse
}
from
'
../interfaces/NotificationEvents
'
;
}
from
'
../interfaces/NotificationEvents
'
;
import
{
CompletionCallbackWrapper
}
from
'
../adapters/CompletionCallbackWrapper
'
;
import
{
CompletionCallbackWrapper
}
from
'
../adapters/CompletionCallbackWrapper
'
;
import
{
NotificationCompletion
,
Notification
}
from
'
../interfaces/Notification
'
;
import
{
Notification
}
from
'
../interfaces/Notification
'
;
import
{
NotificationCompletion
}
from
'
../interfaces/NotificationCompletion
'
;
export
class
EventsRegistry
{
export
class
EventsRegistry
{
constructor
(
constructor
(
...
...
lib/src/interfaces/Notification.ts
View file @
4e661458
export
interface
Notification
{
export
class
Notification
{
identifier
:
string
;
identifier
:
string
;
data
:
object
;
private
_data
?:
any
;
alert
:
string
sound
?:
string
;
sound
?:
string
;
badge
?:
number
;
badge
?:
number
;
type
?:
string
;
type
?:
string
;
thread
?:
string
;
thread
?:
string
;
}
export
interface
NotificationPermissions
{
badge
:
boolean
;
alert
:
boolean
;
sound
:
boolean
;
}
export
interface
NotificationCategory
{
identifier
:
string
actions
:
[
NotificationAction
?];
}
constructor
(
payload
:
object
)
{
this
.
_data
=
payload
;
this
.
identifier
=
this
.
_data
.
identifier
;
}
export
interface
NotificationTextInput
{
get
data
():
any
{
buttonTitle
:
string
;
return
this
.
_data
;
placeholder
:
string
;
}
}
export
interface
NotificationAction
{
identifier
:
string
;
activationMode
:
'
foreground
'
|
'
authenticationRequired
'
|
'
destructive
'
;
title
:
string
;
authenticationRequired
:
boolean
;
textInput
:
NotificationTextInput
}
export
interface
NotificationActionResponse
{
get
title
():
string
{
identifier
:
string
;
return
this
.
_data
.
title
;
text
:
string
;
}
}
export
interface
NotificationCompletion
{
get
body
():
string
{
badge
?:
boolean
;
return
this
.
_data
.
body
;
alert
?:
boolean
;
}
sound
?:
boolean
;
}
}
lib/src/interfaces/NotificationActionResponse.ts
0 → 100644
View file @
4e661458
export
interface
NotificationActionResponse
{
identifier
:
string
;
text
:
string
;
}
lib/src/interfaces/NotificationCategory.ts
0 → 100644
View file @
4e661458
export
interface
NotificationCategory
{
identifier
:
string
actions
:
[
NotificationAction
?];
}
export
interface
NotificationTextInput
{
buttonTitle
:
string
;
placeholder
:
string
;
}
export
interface
NotificationAction
{
identifier
:
string
;
activationMode
:
'
foreground
'
|
'
authenticationRequired
'
|
'
destructive
'
;
title
:
string
;
authenticationRequired
:
boolean
;
textInput
:
NotificationTextInput
}
\ No newline at end of file
lib/src/interfaces/NotificationCompletion.ts
0 → 100644
View file @
4e661458
export
interface
NotificationCompletion
{
badge
?:
boolean
;
alert
?:
boolean
;
sound
?:
boolean
;
}
lib/src/interfaces/NotificationEvents.ts
View file @
4e661458
import
{
Notification
,
NotificationActionResponse
}
from
'
./Notification
'
;
import
{
Notification
}
from
'
./Notification
'
;
import
{
NotificationActionResponse
}
from
'
./NotificationActionResponse
'
;
export
interface
Registered
{
export
interface
Registered
{
deviceToken
:
string
;
deviceToken
:
string
;
...
...
lib/src/interfaces/NotificationPermissions.ts
0 → 100644
View file @
4e661458
export
interface
NotificationPermissions
{
badge
:
boolean
;
alert
:
boolean
;
sound
:
boolean
;
}
\ No newline at end of file
package.json
View file @
4e661458
...
@@ -33,7 +33,8 @@
...
@@ -33,7 +33,8 @@
"test-unit-ios"
:
"node ./scripts/test-unit --ios"
,
"test-unit-ios"
:
"node ./scripts/test-unit --ios"
,
"test-unit-android"
:
"node ./scripts/test-unit --android"
,
"test-unit-android"
:
"node ./scripts/test-unit --android"
,
"test-js"
:
"node ./scripts/test-js"
,
"test-js"
:
"node ./scripts/test-js"
,
"xcode"
:
"open example/ios/NotificationsExampleApp.xcodeproj"
"xcode"
:
"open example/ios/NotificationsExampleApp.xcodeproj"
,
"androidStudio"
:
"open -a /Applications/Android
\\
Studio.app ./example/android"
},
},
"nativePackage"
:
true
,
"nativePackage"
:
true
,
"dependencies"
:
{
"dependencies"
:
{
...
...
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