Skip to content

Commit 006e4ab

Browse files
yogevbdwixmobileartald
authored
V3 (wix#437)
* Add typescript support * Add unit tests * Splits requestPermissionsWithCategories to two functions * Done converting the js part to typescript * typescript WIP * Fix unit * Fix e2e * Identical API for Android and iOS * Fix bundle * build typescript before test-e2e-ios * build typescript before test-e2e-ios * Add docousaurus documentation * Fix rebase from master * Move android and ios folders into lib folder * Split Notification.ts, Fix android example module * Add test coverage for Notification.ts, clean old js files * Updated docs * Move ios and android commands to designated classes * Remove package.json unused packages * Fix e2e * Fix docs, remove circleci config file * 3.0.0-alpha.0 * Update README.md * Fix js tests * Add missing flavors * Update release script * Add pretest scripts * Update release script * Revert manual version change * Fix release build * Gradle resolve react-native version flavor * Fix documentation website * Add identical registerRemoteNotifications api for iOS and Android * Finish API documentation * Merge from master branch * Fix build * Remove NOTIFICATION_RECEIVED_FOREGROUND_EVENT_NAME * Fix iOS example project * Split specific iOS events, Update docs * Add subscription documentation guide * Add Local Notifications documentation guide * Fix handling actions, Add event handling documentation guide * Fix platforms logo * Fix iOS unit tests * Update package.json version to 3.0.0-beta.0 and generate CHANGELOG.gren.md [ci skip] * Fix documentation * Add prerelease script * Update package.json version to 3.0.0-beta.1 and generate CHANGELOG.gren.md [ci skip] * Add npm run docusaurus * Add removeAllDeliveredNotifications support for both iOS and Android * Add CI tag support * Fix podspec * Update iOS installation * Fix android installation * fix build.gradle rn package.json path * Fix iOS * Add NotificationFactory * Fix tests * Fix resolving gradle react native version * find rn package.json by checking if the file exists instead of an exception in JsonSlurper * Fix e2e * Update package.json version to 3.0.0-beta.2 and generate CHANGELOG.gren.md [ci skip] * Rename setBadgesCount to setBadgeCount * add ios and android Notifications object getters * Update package.json version to 3.0.0-beta.3 and generate CHANGELOG.gren.md [ci skip] * Fix android token registration * Update package.json version to 3.0.0-beta.4 and generate CHANGELOG.gren.md [ci skip] Co-authored-by: wixmobile <[email protected]> Co-authored-by: Artal Druk <[email protected]>
1 parent a6a5472 commit 006e4ab

File tree

207 files changed

+3453
-1649
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

207 files changed

+3453
-1649
lines changed

.circleci/config.yml

-40
This file was deleted.

.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*/node_modules
2+
*.log

.gitignore

+9-5
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ npm-debug.log
1515
#####
1616
# Android
1717

18-
android/local.properties
19-
android/*.iml
18+
lib/android/local.properties
19+
lib/android/*.iml
20+
lib/android/.idea
21+
lib/android/build
22+
lib/android/.gradle
23+
*.gradle
2024

2125
#####
2226
# OS X temporary files that should never be committed
@@ -187,6 +191,6 @@ coverage/
187191
package-lock.json
188192

189193
.history
190-
android/.idea
191-
android/build
192-
android/.gradle
194+
195+
# Typescript build
196+
lib/dist/

.npmignore

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
example/
22
test/
3-
RNNotifications/DerivedData
43
node_modules/
4+
website/
5+
docs/
6+
docs_old/
7+
scripts/
8+
e2e/
59

610
.eslintrc
711
*.yml
@@ -10,4 +14,5 @@ coverage/
1014
android/.idea
1115
android/build/
1216
.idea
13-
.history/
17+
.history/
18+
.github/

CHANGELOG.gren.md

+15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# Changelog
22

3+
## 3.0.0-beta.4 (14/01/2020)
4+
*No changelog for this release.*
5+
6+
---
7+
8+
## 3.0.0-beta.3 (13/01/2020)
9+
*No changelog for this release.*
10+
11+
---
12+
13+
## 3.0.0-beta.2 (13/01/2020)
14+
*No changelog for this release.*
15+
16+
---
17+
318
## 2.1.7 (14/12/2019)
419
*No changelog for this release.*
520

Dockerfile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM node:8.11.4
2+
3+
WORKDIR /app/website
4+
5+
EXPOSE 3000 35729
6+
COPY ./docs /app/docs
7+
COPY ./website /app/website
8+
RUN yarn install
9+
10+
CMD ["yarn", "start"]

README.md

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
# React Native Notifications [![CircleCI](https://circleci.com/gh/wix/react-native-notifications/tree/master.svg?style=svg)](https://circleci.com/gh/wix/react-native-notifications/tree/master)
1+
# React Native Notifications
2+
![npm](https://img.shields.io/npm/dw/react-native-notifications.svg)
3+
[![Build Status](https://img.shields.io/jenkins/s/http/jenkins-oss.wixpress.com:8080/job/multi-react-native-notifications-master.svg)](https://jenkins-oss.wixpress.com/job/multi-react-native-notifications-master/)
4+
[![npm (tag)](https://img.shields.io/npm/v/react-native-notifications/snapshot.svg)](https://github.com/wix/react-native-navigation/tree/master)
25

36
Handle all the aspects of push notifications for your app, including remote and local notifications, interactive notifications, silent notifications, and more.
47

@@ -27,14 +30,8 @@ _For information regarding proper integration with [react-native-navigation](htt
2730
_Upcoming: local notifications, background-state Rx queue (iOS equivalent)_
2831

2932

30-
# Table of Content
31-
32-
- [Installation and setup](./docs/installation.md) - Setting up the library in your app
33-
- [Subscription](./docs/subscription.md) - Signing in to push notifications vendors (e.g. GCM)
34-
- [Notification Events (notfications core)](./docs/notificationsEvents.md) - Handling push notification arrival, notification opening by users
35-
- [Local notifications](./docs/localNotifications.md) - Manually triggering notifications (i.e. not via push)
36-
- [Advanced iOS topics](./docs/advancedIos.md) - e.g. managed notifications, PushKit API, Notifications actions
37-
- [Notifications layout control - Android (wiki page)](https://github.com/wix/react-native-notifications/wiki/Android:-Layout-Customization) - Learn how to fully customize your notifications layout on Android!
33+
# Quick Links
34+
- [Documentation](https://wix.github.io/react-native-notifications/)
3835

3936
# License
4037
The MIT License.

RNNotifications/RNEventEmitter.h

-15
This file was deleted.

docker-compose.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
version: "3"
2+
3+
services:
4+
docusaurus:
5+
build: .
6+
ports:
7+
- 3000:3000
8+
- 35729:35729
9+
volumes:
10+
- ./docs:/app/docs
11+
- ./website/blog:/app/website/blog
12+
- ./website/core:/app/website/core
13+
- ./website/i18n:/app/website/i18n
14+
- ./website/pages:/app/website/pages
15+
- ./website/static:/app/website/static
16+
- ./website/sidebars.json:/app/website/sidebars.json
17+
- ./website/siteConfig.js:/app/website/siteConfig.js
18+
working_dir: /app/website

docs/advanced-ios.md

+165
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
---
2+
id: advanced-ios
3+
title: iOS Advanced API
4+
sidebar_label: iOS
5+
---
6+
7+
## PushKit API
8+
9+
The PushKit framework provides the classes for your iOS apps to receive background pushes from remote servers. it has better support for background notifications compared to regular push notifications with `content-available: 1`. More info in [iOS PushKit documentation](https://developer.apple.com/library/ios/documentation/NetworkingInternet/Reference/PushKit_Framework/).
10+
11+
### Register to PushKit
12+
[Prepare your app to receive VoIP push notifications](https://developer.apple.com/library/ios/documentation/Performance/Conceptual/EnergyGuide-iOS/OptimizeVoIP.html)
13+
14+
### Listen to PushKit notifications
15+
On receiving PushKit notification, a `pushKitNotificationReceived` event will be fired with the notification payload.
16+
17+
```js
18+
Notifications.ios.events().registerPushKitNotificationReceived((payload: object) => {
19+
console.log(JSON.stringify(payload));
20+
});
21+
```
22+
23+
In your ReactNative code, add event handler for `pushKitRegistered` event and call to `registerPushKit()`:
24+
25+
```javascript
26+
constructor() {
27+
Notifications.ios.events().registerPushKitRegistered((event: RegisteredPushKit) => {
28+
console.log("PushKit Token Received: " + event.pushKitToken);
29+
});
30+
31+
Notifications.ios.events().registerPushKitNotificationReceived((payload: object) => {
32+
console.log('PushKit notification Received: ' + JSON.stringify(payload));
33+
});
34+
35+
Notifications.ios.registerPushKit();
36+
}
37+
```
38+
39+
> 1. Notice that PushKit device token and regular notifications device token are different, so you must handle two different tokens in the server side in order to support this feature.
40+
> 2. PushKit will not request permissions from the user for push notifications.
41+
42+
43+
---
44+
45+
## Interactive / Actionable Notifications
46+
47+
> This section provides description for iOS. For notifications customization on Android, refer to [our wiki](https://github.com/wix/react-native-notifications/wiki/Android-Customizations#customizing-notifications-layout).
48+
49+
Interactive notifications allow you to reply to a message right from the notification banner or take action right from the lock screen.
50+
51+
On the Lock screen and within Notification Center, you swipe from right to left
52+
to reveal actions. Destructive actions, like trashing an email, are color-coded red. Relatively neutral actions, like dismissing an alert or declining an invitation, are color-coded gray.
53+
54+
For banners, you pull down to reveal actions as buttons. For popups, the actions are immediately visible — the buttons are right there.
55+
56+
You can find more info about interactive notifications [here](http://www.imore.com/interactive-notifications-ios-8-explained).
57+
58+
![Interactive Notifications](http://i.imgur.com/XrVzy9w.gif)
59+
60+
61+
Notification **actions** allow the user to interact with a given notification.
62+
63+
Notification **categories** allow you to group multiple actions together, and to connect the actions with the push notification itself.
64+
65+
Follow the basic workflow of adding interactive notifications to your app:
66+
67+
1. Config the actions.
68+
2. Group actions together into categories.
69+
3. Register to push notifications with the configured categories.
70+
4. Push a notification (or trigger a [local](#triggering-local-notifications) one) with the configured category name.
71+
72+
### Example
73+
#### Config the Actions
74+
We will config two actions: upvote and reply.
75+
76+
```javascript
77+
import { Notifications, NotificationAction, NotificationCategory } from 'react-native-notifications';
78+
79+
let upvoteAction = new NotificationAction({
80+
activationMode: "background",
81+
title: String.fromCodePoint(0x1F44D),
82+
identifier: "UPVOTE_ACTION",
83+
textInput: {
84+
buttonTitle: 'title',
85+
placeholder: 'placeholder text'
86+
}
87+
});
88+
89+
let replyAction = new NotificationAction({
90+
activationMode: "background",
91+
title: "Reply",
92+
authenticationRequired: true,
93+
identifier: "REPLY_ACTION"
94+
});
95+
96+
```
97+
98+
#### Config the Category
99+
We will group `upvote` action and `reply` action into a single category: `EXAMPLE_CATEGORY `. If the notification contains `EXAMPLE_CATEGORY ` under `category` field, those actions will appear.
100+
101+
```javascript
102+
let exampleCategory = new NotificationCategory({
103+
identifier: "EXAMPLE_CATEGORY",
104+
actions: [upvoteAction, replyAction]
105+
});
106+
```
107+
108+
#### Register to Push Notifications
109+
Instead of basic registration like we've done before, we will register the device to push notifications with the category we've just created.
110+
111+
```javascript
112+
Notifications.setCategories([exampleCategory]);
113+
```
114+
115+
#### Push an Interactive Notification
116+
Notification payload should look like this:
117+
118+
```javascript
119+
{
120+
aps: {
121+
// ... (alert, sound, badge, etc)
122+
category: "EXAMPLE_CATEGORY"
123+
}
124+
}
125+
```
126+
127+
The [example app](https://github.com/wix/react-native-notifications/tree/master/example) contains this interactive notification example, you can follow there.
128+
129+
### `NotificationAction` Payload
130+
131+
- `title` - Action button title.
132+
- `identifier` - Action identifier (must be unique).
133+
- `activationMode` - Indicating whether the app should activate to the foreground or background.
134+
- `foreground` (default) - Activate the app and put it in the foreground.
135+
- `background` - Activate the app and put it in the background. If the app is already in the foreground, it remains in the foreground.
136+
- `textInput` - `TextInput` payload, when supplied, the system will present text input in this action.
137+
- `destructive` - A Boolean value indicating whether the action is destructive. When the value of this property is `true`, the system displays the corresponding button differently to indicate that the action is destructive.
138+
- `authenticationRequired` - A Boolean value indicating whether the user must unlock the device before the action is performed.
139+
140+
### `NotificationCategory` Payload
141+
142+
- `identifier` - The name of the action group (must be unique).
143+
- `actions` - An array of `NotificationAction` objects, which related to this category.
144+
145+
### `TextInput` Payload
146+
147+
- `buttonTitle` - Title of the `send` button.
148+
- `placeholder` - Placeholder for the `textInput`.
149+
150+
151+
#### Get and set application icon badges count (iOS only)
152+
153+
Get the current number:
154+
```javascript
155+
Notifications.ios.getBadgeCount((count) => console.log(count));
156+
```
157+
158+
Set to specific number:
159+
```javascript
160+
Notifications.ios.setBadgeCount(2);
161+
```
162+
Clear badges icon:
163+
```javascript
164+
Notifications.ios.setBadgeCount(0);
165+
```

docs/android-api.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
id: android-api
3+
title: Android Specific Commands
4+
sidebar_label: Android specific
5+
---
6+
7+
## refreshToken()
8+
Request a new token for sending push notifications.
9+
10+
```js
11+
Notifications.android.refreshToken();
12+
```

0 commit comments

Comments
 (0)