From 0fdabd3e43226f6743faae9772001fdca1743818 Mon Sep 17 00:00:00 2001 From: Yogev Ben David Date: Sat, 14 Sep 2019 22:28:33 +0300 Subject: [PATCH 001/191] React Native 0.60 Support (#375) * Add react-native@0.60.* support * Change variant name * Update installation docs * Fix example project * Update installation.md --- android/app/build.gradle | 13 ++++ .../RNNotificationsModule.java | 3 +- .../core/InitialNotificationHolder.java | 2 - .../NotificationManagerCompatFacade.java | 12 ++++ .../NotificationManagerCompatFacade.java | 12 ++++ docs/installation.md | 65 +++++++++++++++++++ example/android/gradle.properties | 5 +- example/android/myapplication/build.gradle | 19 +++--- .../app/MainActivity.java | 33 +--------- .../app/MainApplication.java | 6 ++ .../src/main/res/layout/activity_main.xml | 24 ------- .../res/layout/activity_main_prelollipop.xml | 10 --- package.json | 2 +- scripts/test-unit.js | 2 +- 14 files changed, 125 insertions(+), 83 deletions(-) create mode 100644 android/app/src/reactNative59/java/com/wix/reactnativenotifications/NotificationManagerCompatFacade.java create mode 100644 android/app/src/reactNative60/java/com/wix/reactnativenotifications/NotificationManagerCompatFacade.java delete mode 100644 example/android/myapplication/src/main/res/layout/activity_main.xml delete mode 100644 example/android/myapplication/src/main/res/layout/activity_main_prelollipop.xml diff --git a/android/app/build.gradle b/android/app/build.gradle index 9ea834b29..c707029cf 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -16,6 +16,9 @@ android { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } + debug { + debuggable true + } } testOptions { unitTests.all { t -> @@ -36,6 +39,16 @@ android { } } } + + flavorDimensions "RNNotifications.reactNativeVersion" + productFlavors { + reactNative59 { + dimension "RNNotifications.reactNativeVersion" + } + reactNative60 { + dimension "RNNotifications.reactNativeVersion" + } + } } dependencies { diff --git a/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java b/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java index 61dddec58..4ac880787 100644 --- a/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java +++ b/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java @@ -5,7 +5,6 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; -import android.support.v4.app.NotificationManagerCompat; import android.util.Log; import com.facebook.react.bridge.ActivityEventListener; @@ -108,7 +107,7 @@ public void cancelLocalNotification(int notificationId) { @ReactMethod public void isRegisteredForRemoteNotifications(Promise promise) { - boolean hasPermission = NotificationManagerCompat.from(getReactApplicationContext()).areNotificationsEnabled(); + boolean hasPermission = NotificationManagerCompatFacade.from(getReactApplicationContext()).areNotificationsEnabled(); promise.resolve(new Boolean(hasPermission)); } diff --git a/android/app/src/main/java/com/wix/reactnativenotifications/core/InitialNotificationHolder.java b/android/app/src/main/java/com/wix/reactnativenotifications/core/InitialNotificationHolder.java index 3636f41f7..948d80eda 100644 --- a/android/app/src/main/java/com/wix/reactnativenotifications/core/InitialNotificationHolder.java +++ b/android/app/src/main/java/com/wix/reactnativenotifications/core/InitialNotificationHolder.java @@ -1,6 +1,5 @@ package com.wix.reactnativenotifications.core; -import android.support.annotation.Nullable; import com.wix.reactnativenotifications.core.notification.PushNotificationProps; @@ -32,7 +31,6 @@ public void clear() { mNotification = null; } - @Nullable public PushNotificationProps get() { return mNotification; } diff --git a/android/app/src/reactNative59/java/com/wix/reactnativenotifications/NotificationManagerCompatFacade.java b/android/app/src/reactNative59/java/com/wix/reactnativenotifications/NotificationManagerCompatFacade.java new file mode 100644 index 000000000..f527a5d5a --- /dev/null +++ b/android/app/src/reactNative59/java/com/wix/reactnativenotifications/NotificationManagerCompatFacade.java @@ -0,0 +1,12 @@ + +package com.wix.reactnativenotifications; + +import android.content.Context; +import android.support.annotation.Nullable; +import android.support.v4.app.NotificationManagerCompat; + +public abstract class NotificationManagerCompatFacade { + public static NotificationManagerCompat from(@NonNull Context context) { + return NotificationManagerCompat.from(context); + } +} diff --git a/android/app/src/reactNative60/java/com/wix/reactnativenotifications/NotificationManagerCompatFacade.java b/android/app/src/reactNative60/java/com/wix/reactnativenotifications/NotificationManagerCompatFacade.java new file mode 100644 index 000000000..94ea1884c --- /dev/null +++ b/android/app/src/reactNative60/java/com/wix/reactnativenotifications/NotificationManagerCompatFacade.java @@ -0,0 +1,12 @@ + +package com.wix.reactnativenotifications; + +import android.content.Context; +import androidx.annotation.NonNull; +import androidx.core.app.NotificationManagerCompat; + +public abstract class NotificationManagerCompatFacade { + public static NotificationManagerCompat from(@NonNull Context context) { + return NotificationManagerCompat.from(context); + } +} diff --git a/docs/installation.md b/docs/installation.md index fea49f869..eee414aab 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -119,3 +119,68 @@ dependencies { apply plugin: 'com.google.gms.google-services' ``` + +#### Step #5: RNNotifications and React Native version +This step is required only for `react-native-notifications` version `3.1.0` and above.
+ +react-native-notifications supports multiple React Native versions. Target the React Native version required by your project by specifying the RNN build flavor in `android/app/build.gradle`. + +```diff +android { + ... + defaultConfig { + applicationId "com.yourproject" + minSdkVersion rootProject.ext.minSdkVersion + targetSdkVersion rootProject.ext.targetSdkVersion ++ missingDimensionStrategy "RNNotifications.reactNativeVersion", "reactNative60" // See note below! + versionCode 1 + versionName "1.0" + ... + } + ... +} +``` + +!>Important note about `missingDimensionStrategy`
+>`reactNative59` - RN 0.59.x and below
+>`reactNative60` - RN 0.60.0 and above + +Now we need to instruct gradle how to build that flavor. To do so here two solutions: + +#### 5.1 Build app with gradle command + +**prefered solution** The RNNotification flavor you would like to build is specified in `app/build.gradle`. Therefore in order to compile only that flavor, instead of building your entire project using `./gradlew assembleDebug`, you should instruct gradle to build the app module: `./gradlew app:assembleDebug`. The easiest way is to add a package.json command to build and install your debug Android APK . + +``` +"scripts": { + ... + "android": "cd ./android && ./gradlew app:assembleDebug && ./gradlew installDebug" +} +``` + +Now run `npm run android` to build your application + +#### 5.2 Ignore other RNN flavors + +If you don't want to run `npm run android` and want to keep the default `react-native run-android` command, you need to specify to graddle to ignore the other flavors RNNotifications provides. + +To do so edit `android/build.gradle` and add: + +```diff ++subprojects { subproject -> ++ afterEvaluate { ++ if ((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) { ++ android { ++ variantFilter { variant -> ++ def names = variant.flavors*.name ++ if (names.contains("reactNative59")) { ++ setIgnore(true) ++ } ++ } ++ } ++ } ++ } ++} +``` + +**Note**: As more build variants come available in the future, you will need to adjust the list (`names.contains("reactNative59")`). This is why we recommend the first solution. \ No newline at end of file diff --git a/example/android/gradle.properties b/example/android/gradle.properties index 1d3591c8a..ccb748f58 100644 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -15,4 +15,7 @@ # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true \ No newline at end of file +# org.gradle.parallel=true + +android.useAndroidX=true +android.enableJetifier=true \ No newline at end of file diff --git a/example/android/myapplication/build.gradle b/example/android/myapplication/build.gradle index b354d5a61..8fe1c839c 100644 --- a/example/android/myapplication/build.gradle +++ b/example/android/myapplication/build.gradle @@ -24,6 +24,7 @@ android { ndk { abiFilters "armeabi-v7a", "x86" } + missingDimensionStrategy "RNNotifications.reactNativeVersion", "reactNative60" } buildTypes { release { @@ -35,17 +36,13 @@ android { sourceCompatibility 1.8 targetCompatibility 1.8 } -} - -configurations.all { - resolutionStrategy.eachDependency { DependencyResolveDetails details -> - def requested = details.requested - if (requested.group == 'com.android.support') { - details.useVersion "28.0.0" - } + packagingOptions { + pickFirst '**/libjsc.so' + pickFirst '**/libc++_shared.so' } } + configurations.all { resolutionStrategy { force 'org.webkit:android-jsc:r236355' @@ -53,12 +50,12 @@ configurations.all { } dependencies { -// compile fileTree(dir: 'libs', include: ['*.jar']) + implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.google.firebase:firebase-core:16.0.0' - implementation 'com.android.support:appcompat-v7:28.0.0' - implementation 'com.android.support:design:28.0.0' + implementation 'androidx.appcompat:appcompat:1.0.2' implementation 'com.facebook.react:react-native:+' + implementation 'org.webkit:android-jsc-intl:+' implementation project(':react-native-notifications') testImplementation'junit:junit:4.12' diff --git a/example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/MainActivity.java b/example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/MainActivity.java index 4459a6a3e..48f4dabc7 100644 --- a/example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/MainActivity.java +++ b/example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/MainActivity.java @@ -1,40 +1,11 @@ package com.wix.reactnativenotifications.app; -import android.os.Build; -import android.os.Bundle; -import android.view.ViewGroup; -import android.widget.Toolbar; - import com.facebook.react.ReactActivity; -import com.facebook.react.ReactRootView; -import static android.os.Build.VERSION.SDK_INT; public class MainActivity extends ReactActivity { - - private ReactRootView mReactRootView; - @Override - protected void onCreate(Bundle 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(); - } - - private void startReactApplication() { - mReactRootView.startReactApplication(getReactInstanceManager(), "WixRNNotifications", null); + protected String getMainComponentName() { + return "WixRNNotifications"; } } diff --git a/example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/MainApplication.java b/example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/MainApplication.java index 87b0d3a6e..110f09a93 100644 --- a/example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/MainApplication.java +++ b/example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/MainApplication.java @@ -6,12 +6,18 @@ import com.facebook.react.ReactNativeHost; import com.facebook.react.ReactPackage; import com.facebook.react.shell.MainReactPackage; +import com.facebook.soloader.SoLoader; import com.wix.reactnativenotifications.RNNotificationsPackage; import java.util.Arrays; import java.util.List; public class MainApplication extends Application implements ReactApplication { + @Override + public void onCreate() { + super.onCreate(); + SoLoader.init(this, false); + } private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { @Override diff --git a/example/android/myapplication/src/main/res/layout/activity_main.xml b/example/android/myapplication/src/main/res/layout/activity_main.xml deleted file mode 100644 index 3f5177974..000000000 --- a/example/android/myapplication/src/main/res/layout/activity_main.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - diff --git a/example/android/myapplication/src/main/res/layout/activity_main_prelollipop.xml b/example/android/myapplication/src/main/res/layout/activity_main_prelollipop.xml deleted file mode 100644 index 75a78a5f3..000000000 --- a/example/android/myapplication/src/main/res/layout/activity_main_prelollipop.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - diff --git a/package.json b/package.json index 780e2bc75..a84764e74 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "sinon": "^1.17.3", "sinon-chai": "^2.8.0", "shell-utils": "1.x.x", - "react-native": "0.59.5", + "react-native": "0.60.5", "react": "16.8.6", "detox": "13.x.x", "jsc-android": "236355.x.x", diff --git a/scripts/test-unit.js b/scripts/test-unit.js index dcc8f8896..01b85f666 100644 --- a/scripts/test-unit.js +++ b/scripts/test-unit.js @@ -13,7 +13,7 @@ function run() { } function runAndroidUnitTests() { - const conf = release ? 'testReleaseUnitTest' : 'testDebugUnitTest'; + const conf = release ? 'testReactNative60ReleaseUnitTest' : 'testReactNative60DebugUnitTest'; if (android && process.env.JENKINS_CI) { const sdkmanager = '/usr/local/share/android-sdk/tools/bin/sdkmanager'; exec.execSync(`yes | ${sdkmanager} --licenses`); From 711963449ce1ca754f398b6b35967418be9f1280 Mon Sep 17 00:00:00 2001 From: yogevbd Date: Sat, 14 Sep 2019 22:37:49 +0300 Subject: [PATCH 002/191] Update CHANGELOG.md --- CHANGELOG.md | 7 +++++++ docs/installation.md | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0212ae560..988f3842e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,11 @@ # Changelog +# 2.1.0 +## Added +* react-native 0.60 Support + +### Breaking Change +This version requires an additional installation step in order to identify the correct build flavor on android, as described in our [Installation docs](https://github.com/wix/react-native-notifications/blob/master/docs/installation.md#step-5-rnnotifications-and-react-native-version). + # 2.0.6 ## Fixed ### Android diff --git a/docs/installation.md b/docs/installation.md index eee414aab..56f1aba29 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -121,7 +121,7 @@ apply plugin: 'com.google.gms.google-services' ``` #### Step #5: RNNotifications and React Native version -This step is required only for `react-native-notifications` version `3.1.0` and above.
+This step is required only for `react-native-notifications` version `2.1.0` and above.
react-native-notifications supports multiple React Native versions. Target the React Native version required by your project by specifying the RNN build flavor in `android/app/build.gradle`. From 09dd16d68a27b239c42a9263a2283c620497c413 Mon Sep 17 00:00:00 2001 From: wixmobile Date: Sat, 14 Sep 2019 16:01:39 -0400 Subject: [PATCH 003/191] Update package.json version to 2.1.0 [ci skip] --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a84764e74..57640269d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-notifications", - "version": "2.0.6", + "version": "2.1.0", "description": "Advanced Push Notifications (Silent, interactive notifications) for iOS & Android", "author": "Lidan Hifi ", "license": "MIT", @@ -132,4 +132,4 @@ "html" ] } -} +} \ No newline at end of file From ee9e798dc4295b91990fc724f190fd96ec5d53e7 Mon Sep 17 00:00:00 2001 From: yogevbd Date: Sun, 15 Sep 2019 16:41:31 +0300 Subject: [PATCH 004/191] Fix realese script --- scripts/release.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/scripts/release.js b/scripts/release.js index d04c6c2af..d5ad74514 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -8,7 +8,7 @@ const path = require('path'); // Workaround JS const isRelease = process.env.RELEASE_BUILD === 'true'; -const ONLY_ON_BRANCH = 'origin/master'; +const BRANCH = process.env.BRANCH; const VERSION_TAG = isRelease ? 'latest' : 'snapshot'; const VERSION_INC = 'patch'; @@ -31,11 +31,6 @@ function validateEnv() { return false; } - if (process.env.GIT_BRANCH !== ONLY_ON_BRANCH) { - console.log(`not publishing on branch ${process.env.GIT_BRANCH}`); - return false; - } - return true; } @@ -121,13 +116,13 @@ function readPackageJson() { } function updatePackageJsonGit(version) { - exec.execSync(`git checkout master`); + exec.execSync(`git checkout ${BRANCH}`); const packageJson = readPackageJson(); packageJson.version = version; writePackageJson(packageJson); exec.execSync(`git add package.json`); exec.execSync(`git commit -m"Update package.json version to ${version} [ci skip]"`); - exec.execSync(`git push deploy master`); + exec.execSync(`git push deploy ${BRANCH}`); } run(); From 258d9386a7d8d1f827396880eeec33089b2ce9b3 Mon Sep 17 00:00:00 2001 From: Yogev Ben David Date: Sun, 15 Sep 2019 20:13:05 +0300 Subject: [PATCH 005/191] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 988f3842e..4865ffefe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ * react-native 0.60 Support ### Breaking Change -This version requires an additional installation step in order to identify the correct build flavor on android, as described in our [Installation docs](https://github.com/wix/react-native-notifications/blob/master/docs/installation.md#step-5-rnnotifications-and-react-native-version). +This version requires an additional installation step in order to identify the correct build flavor on android, as described in our [Installation doc](https://github.com/wix/react-native-notifications/blob/master/docs/installation.md#step-5-rnnotifications-and-react-native-version). # 2.0.6 ## Fixed From 6e726d1dc22108e415499811e2cec31f51ee0479 Mon Sep 17 00:00:00 2001 From: Yogev Ben David Date: Fri, 20 Sep 2019 03:48:59 +0300 Subject: [PATCH 006/191] Update and rename main.yml to require-label.yml --- .github/workflows/require-label.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .github/workflows/require-label.yml diff --git a/.github/workflows/require-label.yml b/.github/workflows/require-label.yml new file mode 100644 index 000000000..f434ccc10 --- /dev/null +++ b/.github/workflows/require-label.yml @@ -0,0 +1,11 @@ +name: Require PR label + +on: [pull_request] + +jobs: + require-label: + runs-on: ubuntu-latest + steps: + - uses: yogevbd/require-label-action@master + with: + valid-labels: ["bug", "enhancement", "feature"] From 2a5a492bd7d26d1909f4ad1aa9f82ae3565c041d Mon Sep 17 00:00:00 2001 From: yogevbd Date: Fri, 20 Sep 2019 18:23:14 +0300 Subject: [PATCH 007/191] Add .github/main.workflow --- .github/main.workflow | 12 ++++++++++++ .github/workflows/require-label.yml | 11 ----------- 2 files changed, 12 insertions(+), 11 deletions(-) create mode 100644 .github/main.workflow delete mode 100644 .github/workflows/require-label.yml diff --git a/.github/main.workflow b/.github/main.workflow new file mode 100644 index 000000000..8fddb9d76 --- /dev/null +++ b/.github/main.workflow @@ -0,0 +1,12 @@ +workflow "Verify labels" { + on = "pull_request" + resolves = "VerifyLabels" +} + +action "VerifyLabels" { + uses = "yogevbd/enforce-label-action@test" + secrets = ["GITHUB_TOKEN"] + env = { + VALID_LABELS = "bug,enhancement,feature" + } +} \ No newline at end of file diff --git a/.github/workflows/require-label.yml b/.github/workflows/require-label.yml deleted file mode 100644 index f434ccc10..000000000 --- a/.github/workflows/require-label.yml +++ /dev/null @@ -1,11 +0,0 @@ -name: Require PR label - -on: [pull_request] - -jobs: - require-label: - runs-on: ubuntu-latest - steps: - - uses: yogevbd/require-label-action@master - with: - valid-labels: ["bug", "enhancement", "feature"] From ccc188581be10281fc20f8dd53ff8f99084952ff Mon Sep 17 00:00:00 2001 From: yogevbd Date: Fri, 20 Sep 2019 18:29:04 +0300 Subject: [PATCH 008/191] Fix main.workflow --- .github/main.workflow | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/main.workflow b/.github/main.workflow index 8fddb9d76..162c8ac82 100644 --- a/.github/main.workflow +++ b/.github/main.workflow @@ -4,7 +4,7 @@ workflow "Verify labels" { } action "VerifyLabels" { - uses = "yogevbd/enforce-label-action@test" + uses = "yogevbd/enforce-label-action@1.0.0" secrets = ["GITHUB_TOKEN"] env = { VALID_LABELS = "bug,enhancement,feature" From f421c5127eb5b0fc702954230a076f058301dfd5 Mon Sep 17 00:00:00 2001 From: Yogev Ben David Date: Sun, 22 Sep 2019 12:51:56 +0300 Subject: [PATCH 009/191] Autogenerate changelog using github-release-notes (#382) * Auto generate changelog * Update .github/main.workflow * Add skip-changelog as a valid PR label --- .github/main.workflow | 6 +++--- .grenrc.js | 28 ++++++++++++++++++++++++++++ package.json | 3 ++- scripts/release.js | 20 +++++++++++++++----- 4 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 .grenrc.js diff --git a/.github/main.workflow b/.github/main.workflow index 162c8ac82..24ebfb24e 100644 --- a/.github/main.workflow +++ b/.github/main.workflow @@ -1,12 +1,12 @@ workflow "Verify labels" { on = "pull_request" - resolves = "VerifyLabels" + resolves = "Enforce PR label" } -action "VerifyLabels" { +action "Enforce PR label" { uses = "yogevbd/enforce-label-action@1.0.0" secrets = ["GITHUB_TOKEN"] env = { - VALID_LABELS = "bug,enhancement,feature" + VALID_LABELS = "bug,enhancement,feature,skip-changelog" } } \ No newline at end of file diff --git a/.grenrc.js b/.grenrc.js new file mode 100644 index 000000000..b0bad8ad2 --- /dev/null +++ b/.grenrc.js @@ -0,0 +1,28 @@ +module.exports = { + template: { + commit: ({message, url, author, name}) => `- [${message}](${url}) - ${author ? `@${author}` : name}`, + issue: "- {{name}} [{{text}}]({{url}})", + label: "[**{{label}}**]", + noLabel: "closed", + group: "\n#### {{heading}}\n", + changelogTitle: "# Changelog\n\n", + release: "## {{release}} ({{date}})\n{{body}}", + releaseSeparator: "\n---\n\n" + }, + groupBy: { + "Enhancements:": ["enhancement", "internal"], + "Bug Fixes:": ["bug"], + "Features": ["feature"] + }, + ignoreIssuesWith: [ + "skip-changelog" + ], + ignoreTagsWith: [ + "snapshot" + ], + dataSource: "prs", + changelogFileName: "CHANGELOG.gren.md", + tags: "all", + override: true, + generate: true +} \ No newline at end of file diff --git a/package.json b/package.json index 57640269d..91532a398 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,8 @@ "detox": "13.x.x", "jsc-android": "236355.x.x", "jest": "24.8.0", - "metro-react-native-babel-preset": "0.55.x" + "metro-react-native-babel-preset": "0.55.x", + "github-release-notes": "0.17.0" }, "publishConfig": { "registry": "https://registry.npmjs.org/" diff --git a/scripts/release.js b/scripts/release.js index d5ad74514..3d3067cd4 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -3,7 +3,7 @@ const exec = require('shell-utils').exec; const semver = require('semver'); const fs = require('fs'); const _ = require('lodash'); -const path = require('path'); +const grenrc = require('../.grenrc'); // Workaround JS const isRelease = process.env.RELEASE_BUILD === 'true'; @@ -99,7 +99,7 @@ function tagAndPublish(newVersion) { exec.execSync(`git tag -a ${newVersion} -m "${newVersion}"`); exec.execSyncSilent(`git push deploy ${newVersion} || true`); if (isRelease) { - updatePackageJsonGit(newVersion); + updateGit(newVersion); } } @@ -115,14 +115,24 @@ function readPackageJson() { return JSON.parse(fs.readFileSync(getPackageJsonPath())); } -function updatePackageJsonGit(version) { +function updateGit(version) { exec.execSync(`git checkout ${BRANCH}`); + updatePackageJson(version); + generateChangelog(); + exec.execSync(`git commit -m "Update package.json version to ${version} and generate CHANGELOG.gren.md [ci skip]"`); + exec.execSync(`git push deploy ${BRANCH}`); +} + +function updatePackageJson(version) { const packageJson = readPackageJson(); packageJson.version = version; writePackageJson(packageJson); exec.execSync(`git add package.json`); - exec.execSync(`git commit -m"Update package.json version to ${version} [ci skip]"`); - exec.execSync(`git push deploy ${BRANCH}`); +} + +function generateChangelog() { + exec.execSync('gren changelog'); + exec.execSync(`git add ${grenrc.changelogFileName}`); } run(); From a1510bae1b4ab495187d6a4a3595032b3548208a Mon Sep 17 00:00:00 2001 From: Carlos Alcazar Date: Sun, 22 Sep 2019 05:57:23 -0400 Subject: [PATCH 010/191] Fixing white square icon and annotation error (#379) * Fixing issue with notification showing as a white square for application icons that do not follow the notification icon Standard. Should be a non breaking change as the fall back should pull the application icon if it's not defined * Not sure how long this error has been here but we are importing the wrong thing. We should be importing NonNull as importing Nullable causes a build error. The RN 60 flavor of the file is importing the NonNull * Updating documentation for the Icon * Fixing image name and updating documentation * Update installation.md Forgot one more place to update the file name --- .../core/notification/PushNotification.java | 9 ++++++++- .../NotificationManagerCompatFacade.java | 2 +- docs/installation.md | 11 ++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java b/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java index 5e4e3d2ba..524ff0772 100644 --- a/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java +++ b/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java @@ -151,11 +151,18 @@ protected Notification.Builder getNotificationBuilder(PendingIntent intent) { final Notification.Builder notification = new Notification.Builder(mContext) .setContentTitle(mNotificationProps.getTitle()) .setContentText(mNotificationProps.getBody()) - .setSmallIcon(mContext.getApplicationInfo().icon) .setContentIntent(intent) .setDefaults(Notification.DEFAULT_ALL) .setAutoCancel(true); + + int resourceID = mContext.getResources().getIdentifier("notification_icon", "drawable", mContext.getPackageName()); + if (resourceID != 0) { + notification.setSmallIcon(resourceID); + } else { + notification.setSmallIcon(mContext.getApplicationInfo().icon); + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, diff --git a/android/app/src/reactNative59/java/com/wix/reactnativenotifications/NotificationManagerCompatFacade.java b/android/app/src/reactNative59/java/com/wix/reactnativenotifications/NotificationManagerCompatFacade.java index f527a5d5a..f9c858b06 100644 --- a/android/app/src/reactNative59/java/com/wix/reactnativenotifications/NotificationManagerCompatFacade.java +++ b/android/app/src/reactNative59/java/com/wix/reactnativenotifications/NotificationManagerCompatFacade.java @@ -2,7 +2,7 @@ package com.wix.reactnativenotifications; import android.content.Context; -import android.support.annotation.Nullable; +import android.support.annotation.NonNull; import android.support.v4.app.NotificationManagerCompat; public abstract class NotificationManagerCompatFacade { diff --git a/docs/installation.md b/docs/installation.md index 56f1aba29..968ac9788 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -183,4 +183,13 @@ To do so edit `android/build.gradle` and add: +} ``` -**Note**: As more build variants come available in the future, you will need to adjust the list (`names.contains("reactNative59")`). This is why we recommend the first solution. \ No newline at end of file +**Note**: As more build variants come available in the future, you will need to adjust the list (`names.contains("reactNative59")`). This is why we recommend the first solution. + +#### Step #6: Set your notification Icon. + +By default, the package will use your native application icon. If your icon is not notification friendly, you may have to set and use a different icon. To do this, create a notification_icon.png and add it to your drawable folders. Once that is done add the following line to your AndroidManifest.xml + +```diff ++ +``` + From 8de8983a4c514b11fc7862d85585ea972087193a Mon Sep 17 00:00:00 2001 From: yogevbd Date: Sun, 22 Sep 2019 13:11:07 +0300 Subject: [PATCH 011/191] Fix changelog fileName --- .grenrc.js | 2 +- package.json | 3 ++- scripts/release.js | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.grenrc.js b/.grenrc.js index b0bad8ad2..8e8cf2555 100644 --- a/.grenrc.js +++ b/.grenrc.js @@ -21,7 +21,7 @@ module.exports = { "snapshot" ], dataSource: "prs", - changelogFileName: "CHANGELOG.gren.md", + changelogFilename: "CHANGELOG.gren.md", tags: "all", override: true, generate: true diff --git a/package.json b/package.json index 91532a398..d8310f819 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,8 @@ "test-unit-ios": "node ./scripts/test-unit --ios", "test-unit-android": "node ./scripts/test-unit --android", "test-js": "node ./scripts/test-js", - "release": "node ./scripts/release" + "release": "node ./scripts/release", + "generate-changelog": "gren changelog" }, "nativePackage": true, "dependencies": { diff --git a/scripts/release.js b/scripts/release.js index 3d3067cd4..92a8d65c4 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -131,7 +131,7 @@ function updatePackageJson(version) { } function generateChangelog() { - exec.execSync('gren changelog'); + exec.execSync('npm run generate-changelog'); exec.execSync(`git add ${grenrc.changelogFileName}`); } From 88bc7c127fa6c7b1c3cdf17d278b7aabaddd7756 Mon Sep 17 00:00:00 2001 From: yogevbd Date: Sun, 22 Sep 2019 14:26:56 +0300 Subject: [PATCH 012/191] Fix release script --- scripts/release.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/release.js b/scripts/release.js index 92a8d65c4..3f26bc42c 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -132,7 +132,7 @@ function updatePackageJson(version) { function generateChangelog() { exec.execSync('npm run generate-changelog'); - exec.execSync(`git add ${grenrc.changelogFileName}`); + exec.execSync(`git add ${grenrc.changelogFilename}`); } run(); From d65dc4f60f512a157f1cd012c21916126771fd68 Mon Sep 17 00:00:00 2001 From: wixmobile Date: Sun, 22 Sep 2019 07:54:28 -0400 Subject: [PATCH 013/191] Update package.json version to 2.1.3 and generate CHANGELOG.gren.md [ci skip] --- CHANGELOG.gren.md | 40 ++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 CHANGELOG.gren.md diff --git a/CHANGELOG.gren.md b/CHANGELOG.gren.md new file mode 100644 index 000000000..95d385f98 --- /dev/null +++ b/CHANGELOG.gren.md @@ -0,0 +1,40 @@ +# Changelog + +## 2.1.3 (22/09/2019) + +#### Enhancements: + +- Autogenerate changelog using github-release-notes [#382](https://github.com/wix/react-native-notifications/pull/382) + +#### Bug Fixes: + +- Fixing white square icon and annotation error [#379](https://github.com/wix/react-native-notifications/pull/379) + +--- + +## 3.0.0-alpha.0 (15/09/2019) +*No changelog for this release.* + +--- + +## 2.1.0 (14/09/2019) + +#### Enhancements: + +- React Native 0.60 Support [#375](https://github.com/wix/react-native-notifications/pull/375) +- New api changes ios [#342](https://github.com/wix/react-native-notifications/pull/342) + +--- + +## v1.4.0 (18/04/2019) +*No changelog for this release.* + +--- + +## v1.1.17 (26/10/2017) +*No changelog for this release.* + +--- + +## v1.1.12 (13/07/2017) +*No changelog for this release.* diff --git a/package.json b/package.json index d8310f819..d3098bfcf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-notifications", - "version": "2.1.0", + "version": "2.1.3", "description": "Advanced Push Notifications (Silent, interactive notifications) for iOS & Android", "author": "Lidan Hifi ", "license": "MIT", From 51097b28ad0832b038ee5ad0f2d4d0b1ce1a3295 Mon Sep 17 00:00:00 2001 From: Yogev Ben David Date: Wed, 25 Sep 2019 21:39:21 +0300 Subject: [PATCH 014/191] Xcode 11 support in CI (#384) * Run detox e2e tests on iPhone 11 * Run detox e2e tests on iPhone 11 * Run detox e2e tests on iPhone 11 * Link CallKit framework for iOS 11 * Upgrade detox@14.x.x * Add CallKit to example project frameworks --- .../RNNotifications.xcodeproj/project.pbxproj | 1 + .../project.pbxproj | 35 +++---------------- package.json | 10 +++--- scripts/test-unit.js | 2 +- 4 files changed, 12 insertions(+), 36 deletions(-) diff --git a/RNNotifications/RNNotifications.xcodeproj/project.pbxproj b/RNNotifications/RNNotifications.xcodeproj/project.pbxproj index fe2bba152..566e82af6 100644 --- a/RNNotifications/RNNotifications.xcodeproj/project.pbxproj +++ b/RNNotifications/RNNotifications.xcodeproj/project.pbxproj @@ -409,6 +409,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, ); mainGroup = 58B511D21A9E6C8500147676; diff --git a/example/ios/NotificationsExampleApp.xcodeproj/project.pbxproj b/example/ios/NotificationsExampleApp.xcodeproj/project.pbxproj index cbd028911..c9a99bb41 100644 --- a/example/ios/NotificationsExampleApp.xcodeproj/project.pbxproj +++ b/example/ios/NotificationsExampleApp.xcodeproj/project.pbxproj @@ -11,6 +11,7 @@ 13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB11A68108700A75B9A /* LaunchScreen.xib */; }; 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; }; 13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; }; + 5004AC02233BE75A00490132 /* CallKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5004ABE1233BE75A00490132 /* CallKit.framework */; }; 50F1F0CC22CE3B4700FD5829 /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 50F1F06022CE3A6100FD5829 /* libReact.a */; }; 50F1F0CD22CE3B6300FD5829 /* libRCTActionSheet.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 50F1F08A22CE3AA000FD5829 /* libRCTActionSheet.a */; }; 50F1F0CF22CE3B6300FD5829 /* libRCTImage.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 50F1F09522CE3ABE00FD5829 /* libRCTImage.a */; }; @@ -244,20 +245,6 @@ remoteGlobalIDString = 2D2A28881D9B049200D4039D; remoteInfo = "RCTWebSocket-tvOS"; }; - 50F1F0C822CE3B2E00FD5829 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 3DBE0D001F3B181A0099AA32; - remoteInfo = fishhook; - }; - 50F1F0CA22CE3B2E00FD5829 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 3DBE0D0D1F3B181C0099AA32; - remoteInfo = "fishhook-tvOS"; - }; D85498D01D97B31100DEEE06 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = D85498C21D97B31100DEEE06 /* RNNotifications.xcodeproj */; @@ -283,6 +270,7 @@ 13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = NotificationsExampleApp/Info.plist; sourceTree = ""; }; 13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = NotificationsExampleApp/main.m; sourceTree = ""; }; 146833FF1AC3E56700842450 /* React.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = React.xcodeproj; path = "../../node_modules/react-native/React/React.xcodeproj"; sourceTree = ""; }; + 5004ABE1233BE75A00490132 /* CallKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CallKit.framework; path = System/Library/Frameworks/CallKit.framework; sourceTree = SDKROOT; }; 50F1F08522CE3A9F00FD5829 /* RCTActionSheet.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTActionSheet.xcodeproj; path = "../../node_modules/react-native/Libraries/ActionSheetIOS/RCTActionSheet.xcodeproj"; sourceTree = ""; }; 50F1F0A022CE3B0600FD5829 /* RCTNetwork.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTNetwork.xcodeproj; path = "../../node_modules/react-native/Libraries/Network/RCTNetwork.xcodeproj"; sourceTree = ""; }; 78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = "../../node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeproj"; sourceTree = ""; }; @@ -305,6 +293,7 @@ 50F1F0D222CE3B6300FD5829 /* libRCTSettings.a in Frameworks */, 50F1F0D322CE3B6300FD5829 /* libRCTText.a in Frameworks */, 50F1F0D422CE3B6300FD5829 /* libRCTVibration.a in Frameworks */, + 5004AC02233BE75A00490132 /* CallKit.framework in Frameworks */, 50F1F0D522CE3B6300FD5829 /* libRCTWebSocket.a in Frameworks */, 50F1F0CC22CE3B4700FD5829 /* libReact.a in Frameworks */, D84861182267695100E9103D /* JavaScriptCore.framework in Frameworks */, @@ -435,8 +424,6 @@ children = ( 50F1F0C522CE3B2E00FD5829 /* libRCTWebSocket.a */, 50F1F0C722CE3B2E00FD5829 /* libRCTWebSocket-tvOS.a */, - 50F1F0C922CE3B2E00FD5829 /* libfishhook.a */, - 50F1F0CB22CE3B2E00FD5829 /* libfishhook-tvOS.a */, ); name = Products; sourceTree = ""; @@ -482,6 +469,7 @@ D84860E82267695100E9103D /* Frameworks */ = { isa = PBXGroup; children = ( + 5004ABE1233BE75A00490132 /* CallKit.framework */, D84861172267695100E9103D /* JavaScriptCore.framework */, ); name = Frameworks; @@ -531,6 +519,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -804,20 +793,6 @@ remoteRef = 50F1F0C622CE3B2E00FD5829 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; - 50F1F0C922CE3B2E00FD5829 /* libfishhook.a */ = { - isa = PBXReferenceProxy; - fileType = archive.ar; - path = libfishhook.a; - remoteRef = 50F1F0C822CE3B2E00FD5829 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 50F1F0CB22CE3B2E00FD5829 /* libfishhook-tvOS.a */ = { - isa = PBXReferenceProxy; - fileType = archive.ar; - path = "libfishhook-tvOS.a"; - remoteRef = 50F1F0CA22CE3B2E00FD5829 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; D85498D11D97B31100DEEE06 /* libRNNotifications.a */ = { isa = PBXReferenceProxy; fileType = archive.ar; diff --git a/package.json b/package.json index d3098bfcf..a96cf20a2 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "shell-utils": "1.x.x", "react-native": "0.60.5", "react": "16.8.6", - "detox": "13.x.x", + "detox": "14.x.x", "jsc-android": "236355.x.x", "jest": "24.8.0", "metro-react-native-babel-preset": "0.55.x", @@ -85,7 +85,7 @@ "ios.none": { "binaryPath": "playground/ios/DerivedData/playground/Build/Products/Debug-iphonesimulator/playground.app", "type": "ios.none", - "name": "iPhone X", + "name": "iPhone 11", "session": { "server": "ws://localhost:8099", "sessionId": "playground" @@ -95,13 +95,13 @@ "binaryPath": "example/ios/DerivedData/NotificationsExampleApp/Build/Products/Debug-iphonesimulator/NotificationsExampleApp.app", "build": "RCT_NO_LAUNCH_PACKAGER=true xcodebuild build -scheme NotificationsExampleApp -project example/ios/NotificationsExampleApp.xcodeproj -sdk iphonesimulator -configuration Debug -derivedDataPath example/ios/DerivedData/NotificationsExampleApp ONLY_ACTIVE_ARCH=YES -quiet -UseModernBuildSystem=NO", "type": "ios.simulator", - "name": "iPhone X" + "name": "iPhone 11" }, "ios.sim.release": { "binaryPath": "example/ios/DerivedData/NotificationsExampleApp/Build/Products/Release-iphonesimulator/NotificationsExampleApp.app", "build": "RCT_NO_LAUNCH_PACKAGER=true xcodebuild build -scheme NotificationsExampleApp_release -project example/ios/NotificationsExampleApp.xcodeproj -sdk iphonesimulator -configuration Release -derivedDataPath example/ios/DerivedData/NotificationsExampleApp ONLY_ACTIVE_ARCH=YES -quiet -UseModernBuildSystem=NO", "type": "ios.simulator", - "name": "iPhone X" + "name": "iPhone 11" } } }, @@ -134,4 +134,4 @@ "html" ] } -} \ No newline at end of file +} diff --git a/scripts/test-unit.js b/scripts/test-unit.js index 01b85f666..dec650f67 100644 --- a/scripts/test-unit.js +++ b/scripts/test-unit.js @@ -44,7 +44,7 @@ function runIosUnitTests() { -project NotificationsExampleApp.xcodeproj -sdk iphonesimulator -configuration ${conf} - -destination 'platform=iOS Simulator,name=iPhone X' + -destination 'platform=iOS Simulator,name=iPhone 11' -derivedDataPath ./example/ios/DerivedData/NotificationsExampleApp ONLY_ACTIVE_ARCH=YES`); } From 95d1a399deb8fd05cbf27ec430e3eb8d6c50c584 Mon Sep 17 00:00:00 2001 From: Yogev Ben David Date: Wed, 2 Oct 2019 13:29:20 +0300 Subject: [PATCH 015/191] Remove vibrate permissions maxSdkVersion, fix example project on android (#388) --- android/app/src/main/AndroidManifest.xml | 4 +--- example/android/build.gradle | 2 +- example/android/myapplication/build.gradle | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index b6dad7c76..7053040ec 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -10,9 +10,7 @@ android:name="${applicationId}.permission.C2D_MESSAGE" android:protectionLevel="signature" /> - - - + diff --git a/example/android/build.gradle b/example/android/build.gradle index 194ad63e7..77dc62dc1 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -16,7 +16,7 @@ buildscript { } dependencies { classpath 'com.android.tools.build:gradle:3.3.1' - classpath 'com.google.gms:google-services:4.0.0' + classpath 'com.google.gms:google-services:4.0.1' } } diff --git a/example/android/myapplication/build.gradle b/example/android/myapplication/build.gradle index 8fe1c839c..af1baf57e 100644 --- a/example/android/myapplication/build.gradle +++ b/example/android/myapplication/build.gradle @@ -2,7 +2,7 @@ apply plugin: "com.android.application" project.ext.react = [ root : "../../../", - entryFile: "index.js", + entryFile: "index.android.js", bundleAssetName: "index.android.bundle", bundleInAlpha: true, bundleInBeta: true From feec43139a9ba14308ad0fd1f045f2b471063957 Mon Sep 17 00:00:00 2001 From: Yogev Ben David Date: Mon, 28 Oct 2019 00:17:30 +0200 Subject: [PATCH 016/191] Remove all delivered notifications support for android (#401) --- .../wix/reactnativenotifications/RNNotificationsModule.java | 5 +++++ .../core/notificationdrawer/IPushNotificationsDrawer.java | 1 + .../core/notificationdrawer/PushNotificationsDrawer.java | 6 ++++++ lib/src/index.android.js | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java b/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java index 4ac880787..960b1c7bc 100644 --- a/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java +++ b/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java @@ -111,6 +111,11 @@ public void isRegisteredForRemoteNotifications(Promise promise) { promise.resolve(new Boolean(hasPermission)); } + @ReactMethod void removeAllDeliveredNotifications() { + IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(getReactApplicationContext().getApplicationContext()); + notificationsDrawer.onAllNotificationsClearRequest(); + } + protected void startFcmIntentService(String extraFlag) { final Context appContext = getReactApplicationContext().getApplicationContext(); final Intent tokenFetchIntent = new Intent(appContext, FcmInstanceIdRefreshHandlerService.class); diff --git a/android/app/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/IPushNotificationsDrawer.java b/android/app/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/IPushNotificationsDrawer.java index 3be3dc1e5..5efa21682 100644 --- a/android/app/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/IPushNotificationsDrawer.java +++ b/android/app/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/IPushNotificationsDrawer.java @@ -9,4 +9,5 @@ public interface IPushNotificationsDrawer { void onNotificationOpened(); void onNotificationClearRequest(int id); + void onAllNotificationsClearRequest(); } diff --git a/android/app/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/PushNotificationsDrawer.java b/android/app/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/PushNotificationsDrawer.java index 7b320e16d..89da9ec76 100644 --- a/android/app/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/PushNotificationsDrawer.java +++ b/android/app/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/PushNotificationsDrawer.java @@ -60,6 +60,12 @@ public void onNotificationClearRequest(int id) { notificationManager.cancel(id); } + @Override + public void onAllNotificationsClearRequest() { + final NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); + notificationManager.cancelAll(); + } + protected void clearAll() { final NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancelAll(); diff --git a/lib/src/index.android.js b/lib/src/index.android.js index 51376bf83..6abdcda2d 100644 --- a/lib/src/index.android.js +++ b/lib/src/index.android.js @@ -70,6 +70,10 @@ export class NotificationsAndroid { static cancelLocalNotification(id) { RNNotifications.cancelLocalNotification(id); } + + static removeAllDeliveredNotifications() { + RNNotifications.removeAllDeliveredNotifications(); + } } export class PendingNotifications { From 232d10fe3d474a09ca7f7d08d17bb1f61bd7faf8 Mon Sep 17 00:00:00 2001 From: wixmobile Date: Sun, 27 Oct 2019 18:58:13 -0400 Subject: [PATCH 017/191] Update package.json version to 2.1.4-beta.0 and generate CHANGELOG.gren.md [ci skip] --- CHANGELOG.gren.md | 18 ++++++++++++++++++ package.json | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.gren.md b/CHANGELOG.gren.md index 95d385f98..c3d9fcdc6 100644 --- a/CHANGELOG.gren.md +++ b/CHANGELOG.gren.md @@ -1,5 +1,23 @@ # Changelog +## 2.1.4-beta.0 (27/10/2019) +*No changelog for this release.* + +--- + +## 3.0.0-beta.1 (07/10/2019) +*No changelog for this release.* + +--- + +## 3.0.0-beta.0 (02/10/2019) + +#### Bug Fixes: + +- Remove vibrate permissions maxSdkVersion, fix example project on android [#388](https://github.com/wix/react-native-notifications/pull/388) + +--- + ## 2.1.3 (22/09/2019) #### Enhancements: diff --git a/package.json b/package.json index a96cf20a2..3f75feb1e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-notifications", - "version": "2.1.3", + "version": "2.1.4-beta.0", "description": "Advanced Push Notifications (Silent, interactive notifications) for iOS & Android", "author": "Lidan Hifi ", "license": "MIT", @@ -134,4 +134,4 @@ "html" ] } -} +} \ No newline at end of file From 319c567600166545fe667d0b485dfdddd7ffbb39 Mon Sep 17 00:00:00 2001 From: wixmobile Date: Mon, 28 Oct 2019 05:04:46 -0400 Subject: [PATCH 018/191] Update package.json version to 2.1.4 and generate CHANGELOG.gren.md [ci skip] --- CHANGELOG.gren.md | 5 +++++ package.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.gren.md b/CHANGELOG.gren.md index c3d9fcdc6..903a962dd 100644 --- a/CHANGELOG.gren.md +++ b/CHANGELOG.gren.md @@ -1,5 +1,10 @@ # Changelog +## 2.1.4 (27/10/2019) +*No changelog for this release.* + +--- + ## 2.1.4-beta.0 (27/10/2019) *No changelog for this release.* diff --git a/package.json b/package.json index 3f75feb1e..ccdf6c522 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-notifications", - "version": "2.1.4-beta.0", + "version": "2.1.4", "description": "Advanced Push Notifications (Silent, interactive notifications) for iOS & Android", "author": "Lidan Hifi ", "license": "MIT", From cdddf35ff25a0b15f0e5e24791eef85ed61622b3 Mon Sep 17 00:00:00 2001 From: Yogev Ben David Date: Mon, 28 Oct 2019 13:42:56 +0200 Subject: [PATCH 019/191] Allow cancel delivered notification with tag (#402) * Allow cancel local notification with tag * Rename to cancelDeliveredNotification --- .../wix/reactnativenotifications/RNNotificationsModule.java | 6 ++++++ .../core/notificationdrawer/IPushNotificationsDrawer.java | 1 + .../core/notificationdrawer/PushNotificationsDrawer.java | 6 ++++++ lib/src/index.android.js | 4 ++++ 4 files changed, 17 insertions(+) diff --git a/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java b/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java index 960b1c7bc..7b47aedd8 100644 --- a/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java +++ b/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java @@ -105,6 +105,12 @@ public void cancelLocalNotification(int notificationId) { notificationsDrawer.onNotificationClearRequest(notificationId); } + @ReactMethod + public void cancelDeliveredNotification(String tag, int notificationId) { + IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(getReactApplicationContext().getApplicationContext()); + notificationsDrawer.onNotificationClearRequest(tag, notificationId); + } + @ReactMethod public void isRegisteredForRemoteNotifications(Promise promise) { boolean hasPermission = NotificationManagerCompatFacade.from(getReactApplicationContext()).areNotificationsEnabled(); diff --git a/android/app/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/IPushNotificationsDrawer.java b/android/app/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/IPushNotificationsDrawer.java index 5efa21682..e22cd6283 100644 --- a/android/app/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/IPushNotificationsDrawer.java +++ b/android/app/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/IPushNotificationsDrawer.java @@ -9,5 +9,6 @@ public interface IPushNotificationsDrawer { void onNotificationOpened(); void onNotificationClearRequest(int id); + void onNotificationClearRequest(String tag, int id); void onAllNotificationsClearRequest(); } diff --git a/android/app/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/PushNotificationsDrawer.java b/android/app/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/PushNotificationsDrawer.java index 89da9ec76..dea695898 100644 --- a/android/app/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/PushNotificationsDrawer.java +++ b/android/app/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/PushNotificationsDrawer.java @@ -60,6 +60,12 @@ public void onNotificationClearRequest(int id) { notificationManager.cancel(id); } + @Override + public void onNotificationClearRequest(String tag, int id) { + final NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); + notificationManager.cancel(tag, id); + } + @Override public void onAllNotificationsClearRequest() { final NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); diff --git a/lib/src/index.android.js b/lib/src/index.android.js index 6abdcda2d..ac2fe5c4c 100644 --- a/lib/src/index.android.js +++ b/lib/src/index.android.js @@ -71,6 +71,10 @@ export class NotificationsAndroid { RNNotifications.cancelLocalNotification(id); } + static cancelDeliveredNotification(tag, id) { + RNNotifications.cancelDeliveredNotification(tag, id); + } + static removeAllDeliveredNotifications() { RNNotifications.removeAllDeliveredNotifications(); } From 9145155dd9844bd21e5cc79ed0ff26ce75f1cc52 Mon Sep 17 00:00:00 2001 From: wixmobile Date: Mon, 28 Oct 2019 07:56:01 -0400 Subject: [PATCH 020/191] Update package.json version to 2.1.5 and generate CHANGELOG.gren.md [ci skip] --- CHANGELOG.gren.md | 5 +++++ package.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.gren.md b/CHANGELOG.gren.md index 903a962dd..835ad72c5 100644 --- a/CHANGELOG.gren.md +++ b/CHANGELOG.gren.md @@ -1,5 +1,10 @@ # Changelog +## 2.1.5 (28/10/2019) +*No changelog for this release.* + +--- + ## 2.1.4 (27/10/2019) *No changelog for this release.* diff --git a/package.json b/package.json index ccdf6c522..6a7c6f840 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-notifications", - "version": "2.1.4", + "version": "2.1.5", "description": "Advanced Push Notifications (Silent, interactive notifications) for iOS & Android", "author": "Lidan Hifi ", "license": "MIT", From c4535d682e8f47a29586d0aca85a82ee5a5c3606 Mon Sep 17 00:00:00 2001 From: roiberlin <46101561+roiberlin@users.noreply.github.com> Date: Wed, 20 Nov 2019 17:43:57 +0200 Subject: [PATCH 021/191] add RNNotificationCenterMulticast (#411) --- .../RNNotificationCenterListener.m | 1 - .../RNNotificationCenterMulticast.h | 10 ++++ .../RNNotificationCenterMulticast.m | 52 +++++++++++++++++++ RNNotifications/RNNotifications.h | 3 ++ RNNotifications/RNNotifications.m | 23 ++++++++ .../RNNotifications.xcodeproj/project.pbxproj | 8 +++ 6 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 RNNotifications/RNNotificationCenterMulticast.h create mode 100644 RNNotifications/RNNotificationCenterMulticast.m diff --git a/RNNotifications/RNNotificationCenterListener.m b/RNNotifications/RNNotificationCenterListener.m index 97243b276..5c35ef2f3 100644 --- a/RNNotifications/RNNotificationCenterListener.m +++ b/RNNotifications/RNNotificationCenterListener.m @@ -8,7 +8,6 @@ @implementation RNNotificationCenterListener { - (instancetype)initWithNotificationEventHandler:(RNNotificationEventHandler *)notificationEventHandler { self = [super init]; _notificationEventHandler = notificationEventHandler; - [[UNUserNotificationCenter currentNotificationCenter] setDelegate:self]; return self; } diff --git a/RNNotifications/RNNotificationCenterMulticast.h b/RNNotifications/RNNotificationCenterMulticast.h new file mode 100644 index 000000000..eed67977a --- /dev/null +++ b/RNNotifications/RNNotificationCenterMulticast.h @@ -0,0 +1,10 @@ +#import +#import + +@interface RNNotificationCenterMulticast : NSObject + +- (void)addNativeDelegate:(id)delegate; +- (void)removeNativeDelegate:(id)delegate; + +@end + diff --git a/RNNotifications/RNNotificationCenterMulticast.m b/RNNotifications/RNNotificationCenterMulticast.m new file mode 100644 index 000000000..c1c6addb0 --- /dev/null +++ b/RNNotifications/RNNotificationCenterMulticast.m @@ -0,0 +1,52 @@ +#import "RNNotificationCenterMulticast.h" + +@implementation RNNotificationCenterMulticast { + NSHashTable *delegates; +} + +- (id)init { + self = [super init]; + if (self) { + delegates = [NSHashTable weakObjectsHashTable]; + } + return self; +} + +- (void)addNativeDelegate:(id)delegate { + [delegates addObject:delegate]; +} + +- (void)removeNativeDelegate:(id)delegate { + [delegates removeObject:delegate]; +} + +- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler +{ + for (id delegate in delegates) { + if ([delegate respondsToSelector:@selector(userNotificationCenter:willPresentNotification:withCompletionHandler:)]) { + [delegate userNotificationCenter:center willPresentNotification:notification withCompletionHandler:completionHandler]; + } + } +} + +- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler +{ + for (id delegate in delegates) { + if ([delegate respondsToSelector:@selector(userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:)]) { + [delegate userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler]; + } + } +} + +- (void)userNotificationCenter:(UNUserNotificationCenter *)center openSettingsForNotification:(nullable UNNotification *)notification +{ + for (id delegate in delegates) { + if ([delegate respondsToSelector:@selector(userNotificationCenter:openSettingsForNotification:)]) { + if (@available(iOS 12.0, *)) { + [delegate userNotificationCenter:center openSettingsForNotification:notification]; + } + } + } +} + +@end diff --git a/RNNotifications/RNNotifications.h b/RNNotifications/RNNotifications.h index 2e277393e..5e0a093da 100644 --- a/RNNotifications/RNNotifications.h +++ b/RNNotifications/RNNotifications.h @@ -12,4 +12,7 @@ + (void)didRegisterForRemoteNotificationsWithDeviceToken:(id)deviceToken; + (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error; ++ (void)addNativeDelegate:(id)delegate; ++ (void)removeNativeDelegate:(id)delegate; + @end diff --git a/RNNotifications/RNNotifications.m b/RNNotifications/RNNotifications.m index 501410be8..9404319c0 100644 --- a/RNNotifications/RNNotifications.m +++ b/RNNotifications/RNNotifications.m @@ -4,6 +4,7 @@ #import "RNNotifications.h" #import "RNNotificationCenterListener.h" #import "RNPushKit.h" +#import "RNNotificationCenterMulticast.h" @implementation RNNotifications { RNPushKit* _pushKit; @@ -11,6 +12,7 @@ @implementation RNNotifications { RNNotificationEventHandler* _notificationEventHandler; RNPushKitEventHandler* _pushKitEventHandler; RNEventEmitter* _eventEmitter; + RNNotificationCenterMulticast* _notificationCenterMulticast; } - (instancetype)init { @@ -45,8 +47,21 @@ + (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { [[self sharedInstance] didFailToRegisterForRemoteNotificationsWithError:error]; } ++ (void)addNativeDelegate:(id)delegate { + [[self sharedInstance] addNativeDelegate:delegate]; +} + ++ (void)removeNativeDelegate:(id)delegate { + [[self sharedInstance] removeNativeDelegate:delegate]; +} + - (void)startMonitorNotifications { _notificationCenterListener = [[RNNotificationCenterListener alloc] initWithNotificationEventHandler:_notificationEventHandler]; + + _notificationCenterMulticast = [[RNNotificationCenterMulticast alloc] init]; + [[UNUserNotificationCenter currentNotificationCenter] setDelegate:_notificationCenterMulticast]; + + [_notificationCenterMulticast addNativeDelegate:_notificationCenterListener]; } - (void)startMonitorPushKitNotifications { @@ -62,4 +77,12 @@ - (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { [_notificationEventHandler didFailToRegisterForRemoteNotificationsWithError:error]; } +- (void)addNativeDelegate:(id)delegate { + [_notificationCenterMulticast addNativeDelegate:delegate]; +} + +- (void)removeNativeDelegate:(id)delegate { + [_notificationCenterMulticast removeNativeDelegate:delegate]; +} + @end diff --git a/RNNotifications/RNNotifications.xcodeproj/project.pbxproj b/RNNotifications/RNNotifications.xcodeproj/project.pbxproj index 566e82af6..c62a9d418 100644 --- a/RNNotifications/RNNotifications.xcodeproj/project.pbxproj +++ b/RNNotifications/RNNotifications.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 3000AE4023857F1D00DD26E9 /* RNNotificationCenterMulticast.m in Sources */ = {isa = PBXBuildFile; fileRef = 3000AE3E23857F1C00DD26E9 /* RNNotificationCenterMulticast.m */; }; + 3000AE4123857F1D00DD26E9 /* RNNotificationCenterMulticast.h in Headers */ = {isa = PBXBuildFile; fileRef = 3000AE3F23857F1D00DD26E9 /* RNNotificationCenterMulticast.h */; }; 50002A4D22E88266008F6742 /* RNCommandsHandlerIntegrationTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 50002A4C22E88266008F6742 /* RNCommandsHandlerIntegrationTest.m */; }; 50002A8022E8885A008F6742 /* libOCMock.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 50002A7F22E8885A008F6742 /* libOCMock.a */; }; 50002AC822E9D5EA008F6742 /* RNNotificationsStoreTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 50002AC722E9D5EA008F6742 /* RNNotificationsStoreTests.m */; }; @@ -82,6 +84,8 @@ /* Begin PBXFileReference section */ 134814201AA4EA6300B7C361 /* libRNNotifications.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNNotifications.a; sourceTree = BUILT_PRODUCTS_DIR; }; + 3000AE3E23857F1C00DD26E9 /* RNNotificationCenterMulticast.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNotificationCenterMulticast.m; sourceTree = ""; }; + 3000AE3F23857F1D00DD26E9 /* RNNotificationCenterMulticast.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNNotificationCenterMulticast.h; sourceTree = ""; }; 50002A4C22E88266008F6742 /* RNCommandsHandlerIntegrationTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNCommandsHandlerIntegrationTest.m; sourceTree = ""; }; 50002A7F22E8885A008F6742 /* libOCMock.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libOCMock.a; sourceTree = ""; }; 50002AC722E9D5EA008F6742 /* RNNotificationsStoreTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNotificationsStoreTests.m; sourceTree = ""; }; @@ -286,6 +290,8 @@ 508CE81F22D1371700357815 /* Helpers */ = { isa = PBXGroup; children = ( + 3000AE3F23857F1D00DD26E9 /* RNNotificationCenterMulticast.h */, + 3000AE3E23857F1C00DD26E9 /* RNNotificationCenterMulticast.m */, 508CE82022D1372E00357815 /* RNNotificationUtils.h */, 508CE82122D1372E00357815 /* RNNotificationUtils.m */, 50351F9322CD7FF1000713B3 /* RCTConvert+RNNotifications.h */, @@ -333,6 +339,7 @@ 508CE81D22D1337200357815 /* RNPushKit.h in Headers */, 50AD1FCA22D13ADB00E12362 /* RNPushKitEventHandler.h in Headers */, 508CE7D522D12CCA00357815 /* RNNotificationEventHandler.h in Headers */, + 3000AE4123857F1D00DD26E9 /* RNNotificationCenterMulticast.h in Headers */, 50FED76622D3E06500DDD516 /* RNNotificationCenter.h in Headers */, 508CE81922D130B900357815 /* RNPushKitEventListener.h in Headers */, 50E49F0722D1E4E0007160C1 /* RNNotificationsStore.h in Headers */, @@ -453,6 +460,7 @@ 50351F9822CD8604000713B3 /* RNCommandsHandler.m in Sources */, D8A2F7551CB57F1A002CC8F5 /* RNNotifications.m in Sources */, 50351F8F22CD782F000713B3 /* RNEventEmitter.m in Sources */, + 3000AE4023857F1D00DD26E9 /* RNNotificationCenterMulticast.m in Sources */, 508CE81A22D130B900357815 /* RNPushKitEventListener.m in Sources */, 50351F9222CD7DF4000713B3 /* RNBridgeModule.m in Sources */, 50FED76722D3E06500DDD516 /* RNNotificationCenter.m in Sources */, From fbd964e70be7ec634c6ef017dfae4c5ea9fb37c2 Mon Sep 17 00:00:00 2001 From: wixmobile Date: Thu, 21 Nov 2019 06:43:53 -0500 Subject: [PATCH 022/191] Update package.json version to 2.1.6 and generate CHANGELOG.gren.md [ci skip] --- CHANGELOG.gren.md | 5 +++++ package.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.gren.md b/CHANGELOG.gren.md index 835ad72c5..516398d36 100644 --- a/CHANGELOG.gren.md +++ b/CHANGELOG.gren.md @@ -1,5 +1,10 @@ # Changelog +## 2.1.6 (20/11/2019) +*No changelog for this release.* + +--- + ## 2.1.5 (28/10/2019) *No changelog for this release.* diff --git a/package.json b/package.json index 6a7c6f840..eb85cc6e3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-notifications", - "version": "2.1.5", + "version": "2.1.6", "description": "Advanced Push Notifications (Silent, interactive notifications) for iOS & Android", "author": "Lidan Hifi ", "license": "MIT", From e980745d918d150d433d4d6ecdb46fd81a71a13e Mon Sep 17 00:00:00 2001 From: Rotem Mizrachi-Meidan Date: Sat, 14 Dec 2019 19:21:28 +0200 Subject: [PATCH 023/191] Update Robolectric setup (#422) * Update dependencies and specifically robolectric setup to stop leaking the setup script to dependant projects. * deleted deprecated script prepare-robolectric --- android/app/build.gradle | 11 +++-- android/app/local.properties | 8 ---- android/build.gradle | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 4 +- android/prepare-robolectric.gradle | 43 ------------------- example/android/build.gradle | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 4 +- package.json | 2 +- 8 files changed, 14 insertions(+), 62 deletions(-) delete mode 100644 android/app/local.properties delete mode 100644 android/prepare-robolectric.gradle diff --git a/android/app/build.gradle b/android/app/build.gradle index c707029cf..7e937ca35 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -1,8 +1,7 @@ apply plugin: 'com.android.library' -apply from: '../prepare-robolectric.gradle' android { - compileSdkVersion 27 + compileSdkVersion 28 buildToolsVersion '28.0.3' defaultConfig { @@ -38,6 +37,10 @@ android { } } } + + unitTests { + includeAndroidResources = true + } } flavorDimensions "RNNotifications.reactNativeVersion" @@ -57,8 +60,8 @@ dependencies { // tests testImplementation 'junit:junit:4.12' - testImplementation 'org.robolectric:robolectric:3.5.1' + testImplementation 'org.robolectric:robolectric:4.3' testImplementation 'org.assertj:assertj-core:3.8.0' testImplementation 'com.squareup.assertj:assertj-android:1.1.1' - testImplementation 'org.mockito:mockito-core:2.13.0' + testImplementation 'org.mockito:mockito-core:2.25.1' } diff --git a/android/app/local.properties b/android/app/local.properties deleted file mode 100644 index 8891df9df..000000000 --- a/android/app/local.properties +++ /dev/null @@ -1,8 +0,0 @@ -## This file must *NOT* be checked into Version Control Systems, -# as it contains information specific to your local configuration. -# -# Location of the SDK. This is only used by Gradle. -# For customization when using a Version Control System, please read the -# header note. -#Wed Jan 30 11:37:18 IST 2019 -sdk.dir=/Users/yogevbd/android-sdk-macosx diff --git a/android/build.gradle b/android/build.gradle index e3c64c966..fac9066a6 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -8,7 +8,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.0.1' + classpath 'com.android.tools.build:gradle:3.5.2' classpath 'com.google.gms:google-services:4.0.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index 297208b24..5108c786d 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu Jan 04 11:01:32 EET 2018 +#Thu Dec 12 22:41:40 IST 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip diff --git a/android/prepare-robolectric.gradle b/android/prepare-robolectric.gradle deleted file mode 100644 index 7570b17e4..000000000 --- a/android/prepare-robolectric.gradle +++ /dev/null @@ -1,43 +0,0 @@ -def robolectricDependenciesFolder = new File(rootProject.buildDir, "robolectric-3.5.1-dependencies") - -configurations.create('robolectricRuntime') - -dependencies { - testImplementation "org.khronos:opengl-api:gl1.1-android-2.1_r1" - - robolectricRuntime "org.robolectric:android-all:8.1.0-robolectric-4402310" - - robolectricRuntime "org.robolectric:annotations:3.5.1" - robolectricRuntime "org.robolectric:junit:3.5.1" - robolectricRuntime "org.robolectric:resources:3.5.1" - robolectricRuntime "org.robolectric:sandbox:3.5.1" - robolectricRuntime "org.robolectric:utils:3.5.1" - robolectricRuntime "org.robolectric:shadows-framework:3.5.1" -} - -rootProject.task(type: Copy, overwrite: true, "downloadRobolectricDependencies") { - println "downloadRobolectricDependencies into " + robolectricDependenciesFolder - from configurations.robolectricRuntime - into robolectricDependenciesFolder -} - -project.afterEvaluate { - tasks.all { - if (it.name.startsWith("test")) { - it.dependsOn(rootProject.tasks.findByName("downloadRobolectricDependencies")) - } - } -} - -android { - testOptions { - unitTests { - includeAndroidResources = true - } - unitTests.all { - systemProperty 'robolectric.offline', 'true' - systemProperty 'robolectric.dependency.dir', robolectricDependenciesFolder - } - } -} - diff --git a/example/android/build.gradle b/example/android/build.gradle index 77dc62dc1..ba10e22ed 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -15,7 +15,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.3.1' + classpath 'com.android.tools.build:gradle:3.5.3' classpath 'com.google.gms:google-services:4.0.1' } } diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index 8cbe8db0c..6bc93315e 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sun Nov 04 14:31:28 IST 2018 +#Thu Dec 12 22:59:18 IST 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip diff --git a/package.json b/package.json index eb85cc6e3..436f71afd 100644 --- a/package.json +++ b/package.json @@ -134,4 +134,4 @@ "html" ] } -} \ No newline at end of file +} From a6a5472d2be53fde5089ea682c4b38b3462a63b1 Mon Sep 17 00:00:00 2001 From: wixmobile Date: Sat, 14 Dec 2019 12:42:37 -0500 Subject: [PATCH 024/191] Update package.json version to 2.1.7 and generate CHANGELOG.gren.md [ci skip] --- CHANGELOG.gren.md | 5 +++++ package.json | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.gren.md b/CHANGELOG.gren.md index 516398d36..338ef29f4 100644 --- a/CHANGELOG.gren.md +++ b/CHANGELOG.gren.md @@ -1,5 +1,10 @@ # Changelog +## 2.1.7 (14/12/2019) +*No changelog for this release.* + +--- + ## 2.1.6 (20/11/2019) *No changelog for this release.* diff --git a/package.json b/package.json index 436f71afd..24213be62 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-notifications", - "version": "2.1.6", + "version": "2.1.7", "description": "Advanced Push Notifications (Silent, interactive notifications) for iOS & Android", "author": "Lidan Hifi ", "license": "MIT", @@ -134,4 +134,4 @@ "html" ] } -} +} \ No newline at end of file From 006e4ab86fad419349de0f64528e8c1c87bd1d80 Mon Sep 17 00:00:00 2001 From: Yogev Ben David Date: Wed, 15 Jan 2020 17:13:07 +0200 Subject: [PATCH 025/191] V3 (#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 <41264282+wixmobile@users.noreply.github.com> Co-authored-by: Artal Druk --- .circleci/config.yml | 40 --- .dockerignore | 2 + .gitignore | 14 +- .npmignore | 9 +- CHANGELOG.gren.md | 15 + Dockerfile | 10 + README.md | 15 +- RNNotifications/RNEventEmitter.h | 15 - docker-compose.yml | 18 ++ docs/advanced-ios.md | 165 +++++++++++ docs/android-api.md | 12 + docs/general-api.md | 55 ++++ docs/general-events.md | 47 +++ docs/installation-android.md | 64 +++++ docs/installation-ios.md | 88 ++++++ docs/ios-api.md | 70 +++++ docs/ios-events.md | 24 ++ docs/localNotifications.md | 29 +- docs/notification-object.md | 25 ++ docs/notifications-events.md | 56 ++++ docs/subscription.md | 68 ++--- {docs => docs_old}/advancedIos.md | 6 +- {docs => docs_old}/installation.md | 2 +- docs_old/localNotifications.md | 84 ++++++ {docs => docs_old}/notificationsEvents.md | 0 docs_old/subscription.md | 77 +++++ e2e/Notifications.test.js | 8 +- example/android/myapplication/build.gradle | 8 +- .../app/MainActivity.java | 3 +- .../app/MainApplication.java | 7 +- example/android/settings.gradle | 2 +- example/index.android.js | 168 ----------- example/index.ios.js | 160 ----------- example/index.js | 157 ++++++++++ .../project.pbxproj | 11 +- .../NotificationsExampleApp.xcscheme | 4 +- index.ios.js | 1 - index.android.js => index.js | 0 {android => lib/android}/.project | 0 .../org.eclipse.buildship.core.prefs | 0 {android => lib/android}/app/.gitignore | 0 .../.gradle/4.10/fileChanges/last-build.bin | Bin .../.gradle/4.10/fileHashes/fileHashes.bin | Bin .../android}/app/.gradle/4.10/gc.properties | 0 .../.gradle/5.5.1/fileChanges/last-build.bin | Bin .../android}/app/.gradle/5.5.1/gc.properties | 0 {android => lib/android}/app/build.gradle | 40 ++- .../android}/app/proguard-rules.pro | 0 .../android}/app/src/main/AndroidManifest.xml | 0 .../wix/reactnativenotifications/Defs.java | 1 - .../RNNotificationsModule.java | 7 +- .../RNNotificationsPackage.java | 0 .../core/AppLaunchHelper.java | 0 .../core/AppLifecycleFacade.java | 0 .../core/AppLifecycleFacadeHolder.java | 0 .../core/InitialNotificationHolder.java | 0 .../core/JsIOHelper.java | 0 .../core/NotificationIntentAdapter.java | 0 .../core/ProxyService.java | 0 .../core/ReactAppLifecycleFacade.java | 0 .../INotificationsApplication.java | 0 .../core/notification/IPushNotification.java | 0 .../core/notification/PushNotification.java | 8 - .../notification/PushNotificationProps.java | 10 - .../INotificationsDrawerApplication.java | 0 .../IPushNotificationsDrawer.java | 0 .../PushNotificationsDrawer.java | 0 .../fcm/FcmInstanceIdListenerService.java | 0 .../FcmInstanceIdRefreshHandlerService.java | 0 .../fcm/FcmToken.java | 5 + .../fcm/IFcmToken.java | 0 .../fcm/INotificationsFcmApplication.java | 0 .../NotificationManagerCompatFacade.java | 12 + .../NotificationManagerCompatFacade.java | 12 + .../core/AppLaunchHelperTest.java | 0 .../core/InitialNotificationHolderTest.java | 0 .../core/JsIOHelperTest.java | 0 .../notification/PushNotificationTest.java | 0 .../PushNotificationsDrawerTest.java | 0 {android => lib/android}/build.gradle | 2 +- {android => lib/android}/gradle.properties | 0 .../gradle/wrapper/gradle-wrapper.jar | Bin .../gradle/wrapper/gradle-wrapper.properties | 0 {android => lib/android}/gradlew | 0 {android => lib/android}/gradlew.bat | 0 {android => lib/android}/settings.gradle | 0 .../NSNotificationCenter+OCMAdditions.h | 0 {RNNotifications => lib/ios}/OCMock/OCMArg.h | 0 .../ios}/OCMock/OCMConstraint.h | 0 .../ios}/OCMock/OCMFunctions.h | 0 .../ios}/OCMock/OCMLocation.h | 0 .../ios}/OCMock/OCMMacroState.h | 0 .../ios}/OCMock/OCMRecorder.h | 0 .../ios}/OCMock/OCMStubRecorder.h | 0 {RNNotifications => lib/ios}/OCMock/OCMock.h | 0 .../ios}/OCMock/OCMockObject.h | 0 .../ios}/RCTConvert+RNNotifications.h | 2 +- .../ios}/RCTConvert+RNNotifications.m | 17 +- {RNNotifications => lib/ios}/RNBridgeModule.h | 0 {RNNotifications => lib/ios}/RNBridgeModule.m | 20 +- .../ios}/RNCommandsHandler.h | 10 +- .../ios}/RNCommandsHandler.m | 16 +- lib/ios/RNEventEmitter.h | 15 + {RNNotifications => lib/ios}/RNEventEmitter.m | 2 +- .../ios}/RNNotificationCenter.h | 6 +- .../ios}/RNNotificationCenter.m | 25 +- .../ios}/RNNotificationCenterListener.h | 0 .../ios}/RNNotificationCenterListener.m | 0 .../ios}/RNNotificationCenterMulticast.h | 0 .../ios}/RNNotificationCenterMulticast.m | 0 .../ios}/RNNotificationEventHandler.h | 0 .../ios}/RNNotificationEventHandler.m | 2 +- .../ios}/RNNotificationParser.h | 0 .../ios}/RNNotificationParser.m | 8 +- .../ios}/RNNotificationUtils.h | 0 .../ios}/RNNotificationUtils.m | 0 .../ios}/RNNotifications.h | 0 .../ios}/RNNotifications.m | 0 .../RNNotifications.xcodeproj/project.pbxproj | 16 +- .../contents.xcworkspacedata | 0 .../xcschemes/RNNotifications.xcscheme | 0 .../ios}/RNNotificationsStore.h | 0 .../ios}/RNNotificationsStore.m | 0 .../ios}/RNNotificationsTests/Info.plist | 0 .../RNBridgeModuleIntegrationTest.m | 0 .../RNCommandsHandlerIntegrationTest.m | 26 +- .../RNNotificationEventHandlerTests.m | 14 +- .../RNNotificationsStoreTests.m | 0 .../RNNotificationsTests.m | 0 {RNNotifications => lib/ios}/RNPushKit.h | 0 {RNNotifications => lib/ios}/RNPushKit.m | 0 .../ios}/RNPushKitEventHandler.h | 0 .../ios}/RNPushKitEventHandler.m | 0 .../ios}/RNPushKitEventListener.h | 0 .../ios}/RNPushKitEventListener.m | 0 {RNNotifications => lib/ios}/libOCMock.a | Bin lib/src/DTO/Notification.test.ts | 50 ++++ lib/src/DTO/Notification.ts | 33 +++ lib/src/DTO/NotificationAndroid.ts | 16 ++ lib/src/DTO/NotificationFactory.ts | 14 + lib/src/DTO/NotificationIOS.ts | 38 +++ lib/src/Notifications.ts | 113 ++++++++ lib/src/NotificationsAndroid.ts | 23 ++ lib/src/NotificationsIOS.ts | 90 ++++++ lib/src/adapters/CompletionCallbackWrapper.ts | 34 +++ lib/src/adapters/NativeCommandsSender.mock.ts | 1 + lib/src/adapters/NativeCommandsSender.ts | 105 +++++++ lib/src/adapters/NativeEventsReceiver.mock.ts | 1 + lib/src/adapters/NativeEventsReceiver.ts | 43 +++ lib/src/adapters/UniqueIdProvider.ts | 7 + lib/src/commands/Commands.test.ts | 199 +++++++++++++ lib/src/commands/Commands.ts | 89 ++++++ lib/src/events/EventsRegistry.test.ts | 155 ++++++++++ lib/src/events/EventsRegistry.ts | 33 +++ lib/src/events/EventsRegistryIOS.test.ts | 25 ++ lib/src/events/EventsRegistryIOS.ts | 19 ++ lib/src/index.android.js | 90 ------ lib/src/index.ios.js | 254 ----------------- lib/src/index.ts | 9 + lib/src/interfaces/EventSubscription.ts | 3 + .../interfaces/NotificationActionResponse.ts | 9 + lib/src/interfaces/NotificationCategory.ts | 30 ++ lib/src/interfaces/NotificationCompletion.ts | 5 + lib/src/interfaces/NotificationEvents.ts | 22 ++ lib/src/interfaces/NotificationPermissions.ts | 5 + lib/src/notification.android.js | 20 -- lib/src/notification.ios.js | 69 ----- metro.config.js | 4 + package.json | 41 +-- react-native-notifications.podspec | 2 +- scripts/release.js | 2 +- scripts/test-js.js | 25 +- scripts/test-unit.js | 2 +- scripts/test.js | 2 +- test/index.android.spec.js | 218 -------------- test/index.ios.spec.js | 268 ------------------ test/notification.ios.spec.js | 126 -------- tsconfig-strict.json | 18 ++ tsconfig.json | 22 ++ wallaby.js | 15 +- website/README.md | 193 +++++++++++++ website/blog/2016-03-11-blog-post.md | 18 ++ website/blog/2017-04-10-blog-post-two.md | 18 ++ website/blog/2017-09-25-testing-rss.md | 11 + website/blog/2017-09-26-adding-rss.md | 10 + website/blog/2017-10-24-new-version-1.0.0.md | 8 + website/core/Footer.js | 115 ++++++++ website/i18n/en.json | 75 +++++ website/package.json | 15 + website/pages/en/help.js | 54 ++++ website/pages/en/index_.js | 212 ++++++++++++++ website/pages/en/users.js | 48 ++++ website/sidebars.json | 12 + website/siteConfig.js | 110 +++++++ website/static/css/custom.css | 16 ++ website/static/img/favicon.ico | Bin 0 -> 766 bytes website/static/img/oss_logo.png | Bin 0 -> 4370 bytes website/static/img/undraw_code_review.svg | 1 + website/static/img/undraw_monitor.svg | 1 + website/static/img/undraw_note_list.svg | 1 + website/static/img/undraw_online.svg | 1 + website/static/img/undraw_open_source.svg | 1 + .../static/img/undraw_operating_system.svg | 1 + website/static/img/undraw_react.svg | 1 + website/static/img/undraw_tweetstorm.svg | 1 + .../static/img/undraw_youtube_tutorial.svg | 1 + website/static/index.html | 14 + 207 files changed, 3453 insertions(+), 1649 deletions(-) delete mode 100644 .circleci/config.yml create mode 100755 .dockerignore create mode 100755 Dockerfile delete mode 100644 RNNotifications/RNEventEmitter.h create mode 100755 docker-compose.yml create mode 100644 docs/advanced-ios.md create mode 100755 docs/android-api.md create mode 100755 docs/general-api.md create mode 100755 docs/general-events.md create mode 100755 docs/installation-android.md create mode 100755 docs/installation-ios.md create mode 100755 docs/ios-api.md create mode 100755 docs/ios-events.md create mode 100755 docs/notification-object.md create mode 100644 docs/notifications-events.md rename {docs => docs_old}/advancedIos.md (98%) rename {docs => docs_old}/installation.md (98%) create mode 100644 docs_old/localNotifications.md rename {docs => docs_old}/notificationsEvents.md (100%) create mode 100644 docs_old/subscription.md delete mode 100644 example/index.android.js delete mode 100644 example/index.ios.js create mode 100644 example/index.js delete mode 100644 index.ios.js rename index.android.js => index.js (100%) rename {android => lib/android}/.project (100%) rename {android => lib/android}/.settings/org.eclipse.buildship.core.prefs (100%) rename {android => lib/android}/app/.gitignore (100%) rename {android => lib/android}/app/.gradle/4.10/fileChanges/last-build.bin (100%) rename {android => lib/android}/app/.gradle/4.10/fileHashes/fileHashes.bin (100%) rename {android => lib/android}/app/.gradle/4.10/gc.properties (100%) rename {android => lib/android}/app/.gradle/5.5.1/fileChanges/last-build.bin (100%) rename {android => lib/android}/app/.gradle/5.5.1/gc.properties (100%) rename {android => lib/android}/app/build.gradle (64%) rename {android => lib/android}/app/proguard-rules.pro (100%) rename {android => lib/android}/app/src/main/AndroidManifest.xml (100%) rename {android => lib/android}/app/src/main/java/com/wix/reactnativenotifications/Defs.java (77%) rename {android => lib/android}/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java (97%) rename {android => lib/android}/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsPackage.java (100%) rename {android => lib/android}/app/src/main/java/com/wix/reactnativenotifications/core/AppLaunchHelper.java (100%) rename {android => lib/android}/app/src/main/java/com/wix/reactnativenotifications/core/AppLifecycleFacade.java (100%) rename {android => lib/android}/app/src/main/java/com/wix/reactnativenotifications/core/AppLifecycleFacadeHolder.java (100%) rename {android => lib/android}/app/src/main/java/com/wix/reactnativenotifications/core/InitialNotificationHolder.java (100%) rename {android => lib/android}/app/src/main/java/com/wix/reactnativenotifications/core/JsIOHelper.java (100%) rename {android => lib/android}/app/src/main/java/com/wix/reactnativenotifications/core/NotificationIntentAdapter.java (100%) rename {android => lib/android}/app/src/main/java/com/wix/reactnativenotifications/core/ProxyService.java (100%) rename {android => lib/android}/app/src/main/java/com/wix/reactnativenotifications/core/ReactAppLifecycleFacade.java (100%) rename {android => lib/android}/app/src/main/java/com/wix/reactnativenotifications/core/notification/INotificationsApplication.java (100%) rename {android => lib/android}/app/src/main/java/com/wix/reactnativenotifications/core/notification/IPushNotification.java (100%) rename {android => lib/android}/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java (94%) rename {android => lib/android}/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotificationProps.java (76%) rename {android => lib/android}/app/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/INotificationsDrawerApplication.java (100%) rename {android => lib/android}/app/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/IPushNotificationsDrawer.java (100%) rename {android => lib/android}/app/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/PushNotificationsDrawer.java (100%) rename {android => lib/android}/app/src/main/java/com/wix/reactnativenotifications/fcm/FcmInstanceIdListenerService.java (100%) rename {android => lib/android}/app/src/main/java/com/wix/reactnativenotifications/fcm/FcmInstanceIdRefreshHandlerService.java (100%) rename {android => lib/android}/app/src/main/java/com/wix/reactnativenotifications/fcm/FcmToken.java (95%) rename {android => lib/android}/app/src/main/java/com/wix/reactnativenotifications/fcm/IFcmToken.java (100%) rename {android => lib/android}/app/src/main/java/com/wix/reactnativenotifications/fcm/INotificationsFcmApplication.java (100%) create mode 100644 lib/android/app/src/reactNative59/java/com/wix/reactnativenotifications/NotificationManagerCompatFacade.java create mode 100644 lib/android/app/src/reactNative60/java/com/wix/reactnativenotifications/NotificationManagerCompatFacade.java rename {android => lib/android}/app/src/test/java/com/wix/reactnativenotifications/core/AppLaunchHelperTest.java (100%) rename {android => lib/android}/app/src/test/java/com/wix/reactnativenotifications/core/InitialNotificationHolderTest.java (100%) rename {android => lib/android}/app/src/test/java/com/wix/reactnativenotifications/core/JsIOHelperTest.java (100%) rename {android => lib/android}/app/src/test/java/com/wix/reactnativenotifications/core/notification/PushNotificationTest.java (100%) rename {android => lib/android}/app/src/test/java/com/wix/reactnativenotifications/core/notificationdrawer/PushNotificationsDrawerTest.java (100%) rename {android => lib/android}/build.gradle (91%) rename {android => lib/android}/gradle.properties (100%) rename {android => lib/android}/gradle/wrapper/gradle-wrapper.jar (100%) rename {android => lib/android}/gradle/wrapper/gradle-wrapper.properties (100%) rename {android => lib/android}/gradlew (100%) rename {android => lib/android}/gradlew.bat (100%) rename {android => lib/android}/settings.gradle (100%) rename {RNNotifications => lib/ios}/OCMock/NSNotificationCenter+OCMAdditions.h (100%) rename {RNNotifications => lib/ios}/OCMock/OCMArg.h (100%) rename {RNNotifications => lib/ios}/OCMock/OCMConstraint.h (100%) rename {RNNotifications => lib/ios}/OCMock/OCMFunctions.h (100%) rename {RNNotifications => lib/ios}/OCMock/OCMLocation.h (100%) rename {RNNotifications => lib/ios}/OCMock/OCMMacroState.h (100%) rename {RNNotifications => lib/ios}/OCMock/OCMRecorder.h (100%) rename {RNNotifications => lib/ios}/OCMock/OCMStubRecorder.h (100%) rename {RNNotifications => lib/ios}/OCMock/OCMock.h (100%) rename {RNNotifications => lib/ios}/OCMock/OCMockObject.h (100%) rename {RNNotifications => lib/ios}/RCTConvert+RNNotifications.h (96%) rename {RNNotifications => lib/ios}/RCTConvert+RNNotifications.m (87%) rename {RNNotifications => lib/ios}/RNBridgeModule.h (100%) rename {RNNotifications => lib/ios}/RNBridgeModule.m (82%) rename {RNNotifications => lib/ios}/RNCommandsHandler.h (79%) rename {RNNotifications => lib/ios}/RNCommandsHandler.m (84%) create mode 100644 lib/ios/RNEventEmitter.h rename {RNNotifications => lib/ios}/RNEventEmitter.m (96%) rename {RNNotifications => lib/ios}/RNNotificationCenter.h (81%) rename {RNNotifications => lib/ios}/RNNotificationCenter.m (95%) rename {RNNotifications => lib/ios}/RNNotificationCenterListener.h (100%) rename {RNNotifications => lib/ios}/RNNotificationCenterListener.m (100%) rename {RNNotifications => lib/ios}/RNNotificationCenterMulticast.h (100%) rename {RNNotifications => lib/ios}/RNNotificationCenterMulticast.m (100%) rename {RNNotifications => lib/ios}/RNNotificationEventHandler.h (100%) rename {RNNotifications => lib/ios}/RNNotificationEventHandler.m (92%) rename {RNNotifications => lib/ios}/RNNotificationParser.h (100%) rename {RNNotifications => lib/ios}/RNNotificationParser.m (62%) rename {RNNotifications => lib/ios}/RNNotificationUtils.h (100%) rename {RNNotifications => lib/ios}/RNNotificationUtils.m (100%) rename {RNNotifications => lib/ios}/RNNotifications.h (100%) rename {RNNotifications => lib/ios}/RNNotifications.m (100%) rename {RNNotifications => lib/ios}/RNNotifications.xcodeproj/project.pbxproj (98%) rename {RNNotifications => lib/ios}/RNNotifications.xcodeproj/project.xcworkspace/contents.xcworkspacedata (100%) rename {RNNotifications => lib/ios}/RNNotifications.xcodeproj/xcshareddata/xcschemes/RNNotifications.xcscheme (100%) rename {RNNotifications => lib/ios}/RNNotificationsStore.h (100%) rename {RNNotifications => lib/ios}/RNNotificationsStore.m (100%) rename {RNNotifications => lib/ios}/RNNotificationsTests/Info.plist (100%) rename {RNNotifications => lib/ios}/RNNotificationsTests/Integration/RNBridgeModuleIntegrationTest.m (100%) rename {RNNotifications => lib/ios}/RNNotificationsTests/Integration/RNCommandsHandlerIntegrationTest.m (80%) rename {RNNotifications => lib/ios}/RNNotificationsTests/RNNotificationEventHandlerTests.m (90%) rename {RNNotifications => lib/ios}/RNNotificationsTests/RNNotificationsStoreTests.m (100%) rename {RNNotifications => lib/ios}/RNNotificationsTests/RNNotificationsTests.m (100%) rename {RNNotifications => lib/ios}/RNPushKit.h (100%) rename {RNNotifications => lib/ios}/RNPushKit.m (100%) rename {RNNotifications => lib/ios}/RNPushKitEventHandler.h (100%) rename {RNNotifications => lib/ios}/RNPushKitEventHandler.m (100%) rename {RNNotifications => lib/ios}/RNPushKitEventListener.h (100%) rename {RNNotifications => lib/ios}/RNPushKitEventListener.m (100%) rename {RNNotifications => lib/ios}/libOCMock.a (100%) create mode 100644 lib/src/DTO/Notification.test.ts create mode 100644 lib/src/DTO/Notification.ts create mode 100644 lib/src/DTO/NotificationAndroid.ts create mode 100644 lib/src/DTO/NotificationFactory.ts create mode 100644 lib/src/DTO/NotificationIOS.ts create mode 100644 lib/src/Notifications.ts create mode 100644 lib/src/NotificationsAndroid.ts create mode 100644 lib/src/NotificationsIOS.ts create mode 100644 lib/src/adapters/CompletionCallbackWrapper.ts create mode 100644 lib/src/adapters/NativeCommandsSender.mock.ts create mode 100644 lib/src/adapters/NativeCommandsSender.ts create mode 100644 lib/src/adapters/NativeEventsReceiver.mock.ts create mode 100644 lib/src/adapters/NativeEventsReceiver.ts create mode 100644 lib/src/adapters/UniqueIdProvider.ts create mode 100644 lib/src/commands/Commands.test.ts create mode 100644 lib/src/commands/Commands.ts create mode 100644 lib/src/events/EventsRegistry.test.ts create mode 100644 lib/src/events/EventsRegistry.ts create mode 100644 lib/src/events/EventsRegistryIOS.test.ts create mode 100644 lib/src/events/EventsRegistryIOS.ts delete mode 100644 lib/src/index.android.js delete mode 100644 lib/src/index.ios.js create mode 100644 lib/src/index.ts create mode 100644 lib/src/interfaces/EventSubscription.ts create mode 100644 lib/src/interfaces/NotificationActionResponse.ts create mode 100644 lib/src/interfaces/NotificationCategory.ts create mode 100644 lib/src/interfaces/NotificationCompletion.ts create mode 100644 lib/src/interfaces/NotificationEvents.ts create mode 100644 lib/src/interfaces/NotificationPermissions.ts delete mode 100644 lib/src/notification.android.js delete mode 100644 lib/src/notification.ios.js delete mode 100644 test/index.android.spec.js delete mode 100644 test/index.ios.spec.js delete mode 100644 test/notification.ios.spec.js create mode 100644 tsconfig-strict.json create mode 100644 tsconfig.json create mode 100755 website/README.md create mode 100755 website/blog/2016-03-11-blog-post.md create mode 100755 website/blog/2017-04-10-blog-post-two.md create mode 100755 website/blog/2017-09-25-testing-rss.md create mode 100755 website/blog/2017-09-26-adding-rss.md create mode 100755 website/blog/2017-10-24-new-version-1.0.0.md create mode 100755 website/core/Footer.js create mode 100644 website/i18n/en.json create mode 100644 website/package.json create mode 100755 website/pages/en/help.js create mode 100755 website/pages/en/index_.js create mode 100755 website/pages/en/users.js create mode 100755 website/sidebars.json create mode 100644 website/siteConfig.js create mode 100755 website/static/css/custom.css create mode 100755 website/static/img/favicon.ico create mode 100755 website/static/img/oss_logo.png create mode 100755 website/static/img/undraw_code_review.svg create mode 100755 website/static/img/undraw_monitor.svg create mode 100755 website/static/img/undraw_note_list.svg create mode 100755 website/static/img/undraw_online.svg create mode 100755 website/static/img/undraw_open_source.svg create mode 100755 website/static/img/undraw_operating_system.svg create mode 100755 website/static/img/undraw_react.svg create mode 100755 website/static/img/undraw_tweetstorm.svg create mode 100755 website/static/img/undraw_youtube_tutorial.svg create mode 100644 website/static/index.html diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index bf8553b5e..000000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,40 +0,0 @@ - -version: 2 -jobs: - ios: - macos: - xcode: "10.2.1" - steps: - - checkout - - run: - name: Install Dependencies - command: scripts/install.ios.sh - - run: - name: npm install - command: npm install - - run: - name: iOS unit tests - command: 'npm run test-unit-ios' - - run: - name: Detox iOS e2e tests - command: 'npm run test-e2e-ios-release' - android: - macos: - xcode: "10.2.1" - steps: - - checkout - - run: - name: Install Android - command: scripts/install.android.sh - - run: - name: npm install - command: npm install - - run: - name: Android unit tests - command: 'npm run test-unit-android' -workflows: - version: 2 - test: - jobs: - - ios - - android \ No newline at end of file diff --git a/.dockerignore b/.dockerignore new file mode 100755 index 000000000..27d2dae2b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +*/node_modules +*.log diff --git a/.gitignore b/.gitignore index 8c499494b..82b4d3ace 100644 --- a/.gitignore +++ b/.gitignore @@ -15,8 +15,12 @@ npm-debug.log ##### # Android -android/local.properties -android/*.iml +lib/android/local.properties +lib/android/*.iml +lib/android/.idea +lib/android/build +lib/android/.gradle +*.gradle ##### # OS X temporary files that should never be committed @@ -187,6 +191,6 @@ coverage/ package-lock.json .history -android/.idea -android/build -android/.gradle \ No newline at end of file + +# Typescript build +lib/dist/ diff --git a/.npmignore b/.npmignore index 3edb07ad4..62b5ab7b4 100644 --- a/.npmignore +++ b/.npmignore @@ -1,7 +1,11 @@ example/ test/ -RNNotifications/DerivedData node_modules/ +website/ +docs/ +docs_old/ +scripts/ +e2e/ .eslintrc *.yml @@ -10,4 +14,5 @@ coverage/ android/.idea android/build/ .idea -.history/ \ No newline at end of file +.history/ +.github/ \ No newline at end of file diff --git a/CHANGELOG.gren.md b/CHANGELOG.gren.md index 338ef29f4..6b184e8a6 100644 --- a/CHANGELOG.gren.md +++ b/CHANGELOG.gren.md @@ -1,5 +1,20 @@ # Changelog +## 3.0.0-beta.4 (14/01/2020) +*No changelog for this release.* + +--- + +## 3.0.0-beta.3 (13/01/2020) +*No changelog for this release.* + +--- + +## 3.0.0-beta.2 (13/01/2020) +*No changelog for this release.* + +--- + ## 2.1.7 (14/12/2019) *No changelog for this release.* diff --git a/Dockerfile b/Dockerfile new file mode 100755 index 000000000..d369844d5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM node:8.11.4 + +WORKDIR /app/website + +EXPOSE 3000 35729 +COPY ./docs /app/docs +COPY ./website /app/website +RUN yarn install + +CMD ["yarn", "start"] diff --git a/README.md b/README.md index 21eeeb190..8bfe2a689 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ -# 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) +# React Native Notifications +![npm](https://img.shields.io/npm/dw/react-native-notifications.svg) +[![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/) +[![npm (tag)](https://img.shields.io/npm/v/react-native-notifications/snapshot.svg)](https://github.com/wix/react-native-navigation/tree/master) Handle all the aspects of push notifications for your app, including remote and local notifications, interactive notifications, silent notifications, and more. @@ -27,14 +30,8 @@ _For information regarding proper integration with [react-native-navigation](htt _Upcoming: local notifications, background-state Rx queue (iOS equivalent)_ -# Table of Content - -- [Installation and setup](./docs/installation.md) - Setting up the library in your app -- [Subscription](./docs/subscription.md) - Signing in to push notifications vendors (e.g. GCM) -- [Notification Events (notfications core)](./docs/notificationsEvents.md) - Handling push notification arrival, notification opening by users -- [Local notifications](./docs/localNotifications.md) - Manually triggering notifications (i.e. not via push) -- [Advanced iOS topics](./docs/advancedIos.md) - e.g. managed notifications, PushKit API, Notifications actions -- [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! +# Quick Links +- [Documentation](https://wix.github.io/react-native-notifications/) # License The MIT License. diff --git a/RNNotifications/RNEventEmitter.h b/RNNotifications/RNEventEmitter.h deleted file mode 100644 index 011477d98..000000000 --- a/RNNotifications/RNEventEmitter.h +++ /dev/null @@ -1,15 +0,0 @@ -#import - -static NSString* const RNRegistered = @"remoteNotificationsRegistered"; -static NSString* const RNRegistrationFailed = @"remoteNotificationsRegistrationFailed"; -static NSString* const RNPushKitRegistered = @"pushKitRegistered"; -static NSString* const RNNotificationReceivedForeground = @"notificationReceivedForeground"; -static NSString* const RNNotificationOpened = @"notificationOpened"; -static NSString* const RNPushKitNotificationReceived = @"pushKitNotificationReceived"; - - -@interface RNEventEmitter : RCTEventEmitter - -+ (void)sendEvent:(NSString *)event body:(NSDictionary *)body; - -@end diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100755 index 000000000..6711192ae --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,18 @@ +version: "3" + +services: + docusaurus: + build: . + ports: + - 3000:3000 + - 35729:35729 + volumes: + - ./docs:/app/docs + - ./website/blog:/app/website/blog + - ./website/core:/app/website/core + - ./website/i18n:/app/website/i18n + - ./website/pages:/app/website/pages + - ./website/static:/app/website/static + - ./website/sidebars.json:/app/website/sidebars.json + - ./website/siteConfig.js:/app/website/siteConfig.js + working_dir: /app/website diff --git a/docs/advanced-ios.md b/docs/advanced-ios.md new file mode 100644 index 000000000..c2e7f0dd5 --- /dev/null +++ b/docs/advanced-ios.md @@ -0,0 +1,165 @@ +--- +id: advanced-ios +title: iOS Advanced API +sidebar_label: iOS +--- + +## PushKit API + +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/). + +### Register to PushKit +[Prepare your app to receive VoIP push notifications](https://developer.apple.com/library/ios/documentation/Performance/Conceptual/EnergyGuide-iOS/OptimizeVoIP.html) + +### Listen to PushKit notifications +On receiving PushKit notification, a `pushKitNotificationReceived` event will be fired with the notification payload. + +```js +Notifications.ios.events().registerPushKitNotificationReceived((payload: object) => { + console.log(JSON.stringify(payload)); +}); +``` + +In your ReactNative code, add event handler for `pushKitRegistered` event and call to `registerPushKit()`: + +```javascript +constructor() { + Notifications.ios.events().registerPushKitRegistered((event: RegisteredPushKit) => { + console.log("PushKit Token Received: " + event.pushKitToken); + }); + + Notifications.ios.events().registerPushKitNotificationReceived((payload: object) => { + console.log('PushKit notification Received: ' + JSON.stringify(payload)); + }); + + Notifications.ios.registerPushKit(); +} +``` + +> 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. +> 2. PushKit will not request permissions from the user for push notifications. + + +--- + +## Interactive / Actionable Notifications + +> 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). + +Interactive notifications allow you to reply to a message right from the notification banner or take action right from the lock screen. + +On the Lock screen and within Notification Center, you swipe from right to left +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. + +For banners, you pull down to reveal actions as buttons. For popups, the actions are immediately visible — the buttons are right there. + +You can find more info about interactive notifications [here](http://www.imore.com/interactive-notifications-ios-8-explained). + +![Interactive Notifications](http://i.imgur.com/XrVzy9w.gif) + + +Notification **actions** allow the user to interact with a given notification. + +Notification **categories** allow you to group multiple actions together, and to connect the actions with the push notification itself. + +Follow the basic workflow of adding interactive notifications to your app: + +1. Config the actions. +2. Group actions together into categories. +3. Register to push notifications with the configured categories. +4. Push a notification (or trigger a [local](#triggering-local-notifications) one) with the configured category name. + +### Example +#### Config the Actions +We will config two actions: upvote and reply. + +```javascript +import { Notifications, NotificationAction, NotificationCategory } from 'react-native-notifications'; + +let upvoteAction = new NotificationAction({ + activationMode: "background", + title: String.fromCodePoint(0x1F44D), + identifier: "UPVOTE_ACTION", + textInput: { + buttonTitle: 'title', + placeholder: 'placeholder text' + } +}); + +let replyAction = new NotificationAction({ + activationMode: "background", + title: "Reply", + authenticationRequired: true, + identifier: "REPLY_ACTION" +}); + +``` + +#### Config the Category +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. + +```javascript +let exampleCategory = new NotificationCategory({ + identifier: "EXAMPLE_CATEGORY", + actions: [upvoteAction, replyAction] +}); +``` + +#### Register to Push Notifications +Instead of basic registration like we've done before, we will register the device to push notifications with the category we've just created. + +```javascript +Notifications.setCategories([exampleCategory]); +``` + +#### Push an Interactive Notification +Notification payload should look like this: + +```javascript +{ + aps: { + // ... (alert, sound, badge, etc) + category: "EXAMPLE_CATEGORY" + } +} +``` + +The [example app](https://github.com/wix/react-native-notifications/tree/master/example) contains this interactive notification example, you can follow there. + +### `NotificationAction` Payload + +- `title` - Action button title. +- `identifier` - Action identifier (must be unique). +- `activationMode` - Indicating whether the app should activate to the foreground or background. + - `foreground` (default) - Activate the app and put it in the foreground. + - `background` - Activate the app and put it in the background. If the app is already in the foreground, it remains in the foreground. +- `textInput` - `TextInput` payload, when supplied, the system will present text input in this action. +- `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. +- `authenticationRequired` - A Boolean value indicating whether the user must unlock the device before the action is performed. + +### `NotificationCategory` Payload + +- `identifier` - The name of the action group (must be unique). +- `actions` - An array of `NotificationAction` objects, which related to this category. + +### `TextInput` Payload + +- `buttonTitle` - Title of the `send` button. +- `placeholder` - Placeholder for the `textInput`. + + +#### Get and set application icon badges count (iOS only) + +Get the current number: +```javascript +Notifications.ios.getBadgeCount((count) => console.log(count)); +``` + +Set to specific number: +```javascript +Notifications.ios.setBadgeCount(2); +``` +Clear badges icon: +```javascript +Notifications.ios.setBadgeCount(0); +``` diff --git a/docs/android-api.md b/docs/android-api.md new file mode 100755 index 000000000..9ee6f9871 --- /dev/null +++ b/docs/android-api.md @@ -0,0 +1,12 @@ +--- +id: android-api +title: Android Specific Commands +sidebar_label: Android specific +--- + +## refreshToken() +Request a new token for sending push notifications. + +```js +Notifications.android.refreshToken(); +``` diff --git a/docs/general-api.md b/docs/general-api.md new file mode 100755 index 000000000..0e0c17992 --- /dev/null +++ b/docs/general-api.md @@ -0,0 +1,55 @@ +--- +id: general-api +title: General Commands +sidebar_label: General +--- + +## registerRemoteNotifications() +Requests remote notification permissions, prompting the user's dialog box on iOS and request a token on Android. +If the user accept the remote notifications permissions, `RemoteNotificationsRegistered` event will get called with the device token. + +```js +Notifications.registerRemoteNotifications(); +``` + +## getInitialNotification() +This method returns a promise. If the app was launched by a push notification, this promise resolves to an object of type [Notification](notification-object). Otherwise, it resolves to undefined. + +```js +const notification: Notification = await Notifications.getInitialNotification(); +``` + +## postLocalNotification(notification, id?) +Posts local notification to the device notification center. + +```js +Notifications.postLocalNotification({ + body: 'Local notificiation!', + title: 'Local Notification Title', + sound: 'chime.aiff', + category: 'SOME_CATEGORY', + link: 'localNotificationLink', + fireDate: new Date() +}, id); +``` + +## cancelLocalNotification(id) +Relevant for notifications sent with `fireDate`. + +```js +Notifications.cancelLocalNotification(id); +``` + +## isRegisteredForRemoteNotifications() +Check if the app has permissions to send remote notifications. + +```js +const hasPermissions: boolean = await Notifications.isRegisteredForRemoteNotifications(); +``` + +## removeAllDeliveredNotifications() +Remove all delivered notifications from Notification Center + +```js +Notifications.removeAllDeliveredNotifications(); +``` diff --git a/docs/general-events.md b/docs/general-events.md new file mode 100755 index 000000000..d1e5a55d7 --- /dev/null +++ b/docs/general-events.md @@ -0,0 +1,47 @@ +--- +id: general-events +title: General +sidebar_label: General +--- + +## registerRemoteNotificationsRegistered() +Fired when the user registers for remote notifications. The handler will be invoked with an event holding the hex string representing the `deviceToken` + +```js +Notifications.events().registerRemoteNotificationsRegistered((event: Registered) => { + console.log(event.deviceToken); +}); +``` + +## registerNotificationReceived() +Fired when a remote notification is received in foreground state. The handler will be invoked with an instance of [Notification](notification-object). +Should call completion function on iOS, will be ignored on Android. + +```js +Notifications.events().registerNotificationReceived((notification: Notification, completion: (response: NotificationCompletion) => void) => { + console.log(JSON.stringify(notification.data)); + + // Calling completion on iOS with `alert: true` will present the native iOS inApp notification. + completion({alert: true, sound: true, badge: false}); +}); +``` + +## registerRemoteNotificationOpened() +Fired when a remote notification is opened from dead or background state. The handler will be invoked with an instance of [Notification](notification-object). +Should call completion function on iOS, will be ignored on Android. + +```js +Notifications.events().registerRemoteNotificationOpened((notification: Notification, completion: () => void) => { + console.log(JSON.stringify(notification.data)); + completion(); +}); +``` + +## registerRemoteNotificationsRegistrationFailed() +Fired when the user fails to register for remote notifications. Typically occurs when APNS is having issues, or the device is a simulator. The handler will be invoked with {localizedDescription: string, code: string, domain: string}. + +```js +Notifications.events().registerRemoteNotificationsRegistrationFailed((event: RegistrationError) => { + console.log(event.code, event.localizedDescription, event.domain); +}); +``` \ No newline at end of file diff --git a/docs/installation-android.md b/docs/installation-android.md new file mode 100755 index 000000000..751e9240a --- /dev/null +++ b/docs/installation-android.md @@ -0,0 +1,64 @@ +--- +id: installation-android +title: Android Installation +sidebar_label: Android Installation +--- + +Add the library to your application class (e.g. `MainApplication.java`): + +```java +import com.wix.reactnativenotifications.RNNotificationsPackage; + +... + + @Override + protected List getPackages() { + return Arrays.asList( + new MainReactPackage(), + // ... + // Add this line: + new RNNotificationsPackage(MainApplication.this) + ); +``` + +### Receiving push notifications + +> Note: This section is only necessary in case you wish to be able to **receive** push notifications in your React-Native app. + +Push notifications on Android are managed and dispatched using [Google's FCM service](https://firebase.google.com/docs/cloud-messaging). The following installation steps are a TL;DR of [Google's FCM setup guide](https://firebase.google.com/docs/cloud-messaging/android/client). You can follow them to get FCM integrated quickly, but we recommend that you will in the very least have a peek at the guide's overview. + +#### Step #1: Subscribe to Google's FCM + +To set FCM in your app, you must first create a google-services.json file. If you have no existing API project yet, the easiest way to go about in creating one is using [this step-by-step installation process](https://firebase.google.com/docs/android/setup); + + +#### Step #2: Copy google-services.json + +After creating google-services.json, copy it into your project's android/app folder. + +#### Step #3: Add google-services package to Project/build.gradle +```gradle +buildscript { + ... + dependencies { + ... + classpath 'com.google.gms:google-services:4.0.0' + } +} +``` + +#### Step #4: Add firebase-core package and apply google-services plugin in Project/app/build.gradle +```gradle +dependencies { + ... + implementation 'com.google.firebase:firebase-core:16.0.0' +} + +apply plugin: 'com.google.gms.google-services' +``` + +#### Step #5: Link react-native-notifications in Project/android/settings.gradle +```gradle +include ':react-native-notifications' +project(':react-native-notifications').projectDir = new File(rootProject.projectDir, '../../../node_modules/react-native-notifications/lib/android/app') +``` \ No newline at end of file diff --git a/docs/installation-ios.md b/docs/installation-ios.md new file mode 100755 index 000000000..9bf6d374a --- /dev/null +++ b/docs/installation-ios.md @@ -0,0 +1,88 @@ +--- +id: installation-ios +title: iOS Installation +sidebar_label: iOS Installation +--- + +As with any React Native project, the first step is to add the project as an npm dependency. + +Start by running this: + +``` +$ npm install react-native-notifications --save +``` + +### Installation with CocoaPods + +Projects generated using newer versions of react-native use CocoaPods by default. In that case it's easier to install react-native-navigation using CocoaPods. + +1. Add the following to `Podfile`: + +```diff +platform :ios, '9.0' +require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' + +target 'YourApp' do + # Pods for YourApp + pod 'React', :path => '../node_modules/react-native/' + pod 'React-Core', :path => '../node_modules/react-native/React' + pod 'React-DevSupport', :path => '../node_modules/react-native/React' + pod 'React-fishhook', :path => '../node_modules/react-native/Libraries/fishhook' + pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS' + pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation' + pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob' + pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image' + pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS' + pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network' + pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings' + pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text' + pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration' + pod 'React-RCTWebSocket', :path => '../node_modules/react-native/Libraries/WebSocket' + + pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact' + pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi' + pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor' + pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector' + pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga' + + pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec' + pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec' + pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec' + ++ pod 'ReactNativeNotifications', :podspec => '../node_modules/react-native-notifications/ReactNativeNotifications.podspec' + + use_native_modules! +end +``` + +2. `cd ios && pod install` + +3. Add the following line at the top of your `AppDelegate.m` + +```objective-c +#import "RNNotifications.h" +``` + +Start monitor notifications in: `application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions` + +```objective-c + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + [RNNotifications startMonitorNotifications]; // -> Add this line + + return YES; +} + +``` + +And add the following methods to support registration: + +```objective-c + +- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { + [RNNotifications didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; +} + +- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { + [RNNotifications didFailToRegisterForRemoteNotificationsWithError:error]; +} \ No newline at end of file diff --git a/docs/ios-api.md b/docs/ios-api.md new file mode 100755 index 000000000..d422cdb9c --- /dev/null +++ b/docs/ios-api.md @@ -0,0 +1,70 @@ +--- +id: ios-api +title: iOS Specific Commands +sidebar_label: iOS specific +--- + +## requestPermissions() +Requests notification permissions from iOS, prompting the user's dialog box. + +```js +Notifications.ios.requestPermissions(); +``` + +## checkPermissions() +See what push permissions are currently enabled. + +```js +Notifications.ios.checkPermissions(); +``` + +## abandonPermissions() +Unregister for all remote notifications received via Apple Push Notification service. + +You should call this method in rare circumstances only, such as when a new version of the app removes support for all types of remote notifications. Users can temporarily prevent apps from receiving remote notifications through the Notifications section of the Settings app. Apps unregistered through this method can always re-register. + +```js +Notifications.ios.abandonPermissions(); +``` + +## registerPushKit() +Register for PushKit notifications + +```js +Notifications.ios.registerPushKit(); +``` + +## cancelAllLocalNotifications() +Cancels all scheduled localNotifications + +```js +Notifications.ios.cancelAllLocalNotifications(); +``` + +## getDeliveredNotifications() +Provides you with a list of the app’s notifications that are still displayed in Notification Center + +```js +Notifications.ios.getDeliveredNotifications(); +``` + +## removeDeliveredNotifications() +Removes the specified notifications from Notification Center + +```js +Notifications.ios.removeDeliveredNotifications(identifiers); +``` + +## getBadgeCount() +Gets the badge count number from the aps object + +```js +Notifications.ios.getBadgeCount(); +``` + +## setBadgeCount() +Sets the badge number for the app icon on the home screen + +```js +Notifications.ios.setBadgeCount(1); +``` \ No newline at end of file diff --git a/docs/ios-events.md b/docs/ios-events.md new file mode 100755 index 000000000..8a939194b --- /dev/null +++ b/docs/ios-events.md @@ -0,0 +1,24 @@ +--- +id: ios-events +title: iOS +sidebar_label: iOS specific +--- + +## registerPushKitRegistered() +Fired when the user registers for PushKit notifications. The handler will be invoked with an event holding the hex string representing the `pushKitToken` + +```js +Notifications.ios.events().registerPushKitRegistered((event: RegisteredPushKit) => { + console.log(event.pushKitToken); +}); +``` + +## registerPushKitNotificationReceived() +Fired when a PushKit notification is received. The handler will be invoked with the notification object. + +```js +Notifications.ios.events().registerPushKitNotificationReceived((payload: object) => { + console.log(JSON.stringify(payload)); +}); +``` + diff --git a/docs/localNotifications.md b/docs/localNotifications.md index 8f1d2b948..db3b6b1e7 100644 --- a/docs/localNotifications.md +++ b/docs/localNotifications.md @@ -1,7 +1,10 @@ +--- +id: localNotifications +title: Local Notifications +sidebar_label: Local Notifications +--- -# Local Notifications - -## iOS + iOS You can manually trigger local notifications in your JS code, to be posted immediately or in the future. Triggering local notifications is fully compatible with React Native `PushNotificationsIOS` library. @@ -9,7 +12,7 @@ Triggering local notifications is fully compatible with React Native `PushNotifi Example: ```javascript -let localNotification = NotificationsIOS.localNotification({ +let localNotification = Notifications.postLocalNotification({ body: "Local notificiation!", title: "Local Notification Title", sound: "chime.aiff", @@ -32,12 +35,12 @@ Notification object contains: ### Cancel Scheduled Local Notifications -The `NotificationsIOS.localNotification()` and `NotificationsAndroid.localNotification()` methods return unique `notificationId` values, which can be used in order to cancel specific local notifications that were scheduled for delivery on `fireDate` and have not yet been delivered. You can cancel local notification by calling `NotificationsIOS.cancelLocalNotification(notificationId)` or `NotificationsAndroid.cancelLocalNotification(notificationId)`. +The `Notifications.postLocalNotification()` method return unique `notificationId` values, which can be used in order to cancel specific local notifications that were scheduled for delivery on `fireDate` and have not yet been delivered. You can cancel local notification by calling `Notifications.cancelLocalNotification(notificationId)`. Example: ```javascript -let someLocalNotification = NotificationsIOS.localNotification({ +let someLocalNotification = Notifications.postLocalNotification({ body: "Local notificiation!", title: "Local Notification Title", sound: "chime.aiff", @@ -45,23 +48,23 @@ let someLocalNotification = NotificationsIOS.localNotification({ userInfo: { } }); -NotificationsIOS.cancelLocalNotification(someLocalNotification); +Notifications.cancelLocalNotification(someLocalNotification); ``` To cancel all local notifications (**iOS only!**), use `cancelAllLocalNotifications()`: ```javascript -NotificationsIOS.cancelAllLocalNotifications(); +Notifications.ios.cancelAllLocalNotifications(); ``` #### Cancel Delivered Local Notifications (iOS 10+ only) -To dismiss notifications from the notification center that have already been shown to the user, call `NotificationsIOS.removeDeliveredNotifications([notificationId])`: +To dismiss notifications from the notification center that have already been shown to the user, call `Notifications.ios.removeDeliveredNotifications([notificationId])`: ```javascript -let someLocalNotification = NotificationsIOS.localNotification({...}); +let someLocalNotification = Notifications.postLocalNotification({...}); -NotificationsIOS.removeDeliveredNotifications([someLocalNotification]); +Notifications.ios.removeDeliveredNotifications([someLocalNotification]); ``` Call `removeAllDeliveredNotifications()` to dismiss all delivered notifications @@ -69,12 +72,12 @@ Call `removeAllDeliveredNotifications()` to dismiss all delivered notifications notifications). -## Android + Android Much like on iOS, notifications can be triggered locally. The API to do so is a simplified version of the iOS equivalent that works more natually with the Android perception of push (remote) notifications: ```javascript -NotificationsAndroid.localNotification({ +Notifications.postLocalNotification({ title: "Local notification", body: "This notification was generated by the app!", extra: "data" diff --git a/docs/notification-object.md b/docs/notification-object.md new file mode 100755 index 000000000..9fa404f66 --- /dev/null +++ b/docs/notification-object.md @@ -0,0 +1,25 @@ +--- +id: notification-object +title: Notification object +sidebar_label: Notification +--- + +Contains the payload data. + +- **`title`**- returns the notification's title string. +- **`subtitle`**- returns the notification's title string. (iOS only) +- **`body`**- returns the notification's main message string. +- **`sound`**- returns the sound string from the `aps` object. +- **`badge`**- returns the badge count number from the `aps` object. +- **`category`**- returns the category from the `aps` object (related to interactive notifications). +- **`payload`**- returns the full payload sent from server. + +Example: +```js +Notifications.events().registerNotificationReceived((notification: Notification, completion: (response: NotificationCompletion) => void) => { + // Prints the notification payload + console.log(JSON.stringify(notification.payload)); + + completion({alert: false, sound: false, badge: false}); +}); +``` \ No newline at end of file diff --git a/docs/notifications-events.md b/docs/notifications-events.md new file mode 100644 index 000000000..a969868f1 --- /dev/null +++ b/docs/notifications-events.md @@ -0,0 +1,56 @@ +--- +id: notifications-events +title: Handling Notification Events +sidebar_label: Events +--- + +When a push notification is received by the device, the application can be in one of the following states: + +1. **Forground:** When the app is running and is used by the user right now; in this case, a `notificationReceived` event will be fired, do not forget to invoke `completion()` callback. + +Finally, when a notification is _opened_ by the device user (i.e. tapped-on), a `notificationOpened` event is fired, here as well you need to remember invoking `completion()` callback. + +Example: + +```javascript +constructor() { + Notifications.events().registerNotificationReceived((notification: Notification, completion: (response: NotificationCompletion) => void) => { + console.log("Notification Received - Foreground", notification.data); + + // Calling completion on iOS with `alert: true` will present the native iOS inApp notification. + completion({alert: true, sound: true, badge: false}); + }); + + Notifications.events().registerRemoteNotificationOpened((notification: Notification, completion: () => void, action: NotificationActionResponse) => { + console.log("Notification opened by device user", notification.data); + console.log(`Notification opened with an action identifier: ${action.identifier} and response text: ${action.text}`); + completion(); + }); +} +``` + +### Notification Object + +When you receive a push notification, you'll get an instance of [Notification](notification-object) object, contains the following methods: + +## Querying initial notification + +React-Native's [`PushNotificationsIOS.getInitialNotification()`](https://facebook.github.io/react-native/docs/pushnotificationios.html#getinitialnotification) allows for the async retrieval of the original notification used to open the App on iOS, but it has no equivalent implementation for Android. + +```javascript +import {Notifications} from 'react-native-notifications'; + +Notifications.getInitialNotification() + .then((notification) => { + console.log("Initial notification was:", (notification ? notification.data : 'N/A')); + }) + .catch((err) => console.error("getInitialNotifiation() failed", err)); + +``` + +> **Note** +> +> Notifications are considered 'initial' under the following terms: + +> - User tapped on a notification, _AND_ - +> - App was either not running at all ("dead" state), _OR_ it existed in the background with **no running activities** associated with it. diff --git a/docs/subscription.md b/docs/subscription.md index ddd493e62..1b5038c6d 100644 --- a/docs/subscription.md +++ b/docs/subscription.md @@ -1,46 +1,32 @@ -# Push Notifications Subscription +--- +id: subscription +title: Push Notifications Subscription +sidebar_label: Subscription +--- -The typical flow for subscribing a device for receiving push notification in real time is to first register the device at the vendor's servers (e.g. GCM), then publishing the received token to your own push management servers. +The typical flow for subscribing a device for receiving push notification in real time is to first register the device at the vendor's servers (e.g. FCM), then publishing the received token to your own push management servers. This section is about the first part of the flow. -## iOS - In order to handle notifications, you must register the `remoteNotificationsRegistered` event beforehand. In your React Native app: ```javascript -import NotificationsIOS from 'react-native-notifications'; +import {Notifications} from 'react-native-notifications'; class App extends Component { constructor() { - NotificationsIOS.addEventListener('remoteNotificationsRegistered', this.onPushRegistered.bind(this)); - NotificationsIOS.addEventListener('remoteNotificationsRegistrationFailed', this.onPushRegistrationFailed.bind(this)); - NotificationsIOS.requestPermissions(); - } - - onPushRegistered(deviceToken) { - // TODO: Send the token to my server so it could send back push notifications... - console.log("Device Token Received", deviceToken); - } - - onPushRegistrationFailed(error) { - // For example: - // - // error={ - // domain: 'NSCocoaErroDomain', - // code: 3010, - // localizedDescription: 'remote notifications are not supported in the simulator' - // } - console.error(error); - } - - componentWillUnmount() { - // prevent memory leaks! - NotificationsIOS.removeEventListener('remoteNotificationsRegistered', this.onPushRegistered.bind(this)); - NotificationsIOS.removeEventListener('remoteNotificationsRegistrationFailed', this.onPushRegistrationFailed.bind(this)); + Notifications.events().registerRemoteNotificationsRegistered((event: Registered) => { + // TODO: Send the token to my server so it could send back push notifications... + console.log("Device Token Received", event.deviceToken); + }); + Notifications.events().registerRemoteNotificationsRegistrationFailed((event: RegistrationError) => { + console.error(event); + }); + + Notifications.requestPermissions(); } } @@ -48,30 +34,12 @@ class App extends Component { When you have the device token, POST it to your server and register the device in your notifications provider (Amazon SNS, Azure, etc.). -You can check if the user granted permissions by calling `checkPermissions()`: +You can check if the user granted permissions on iOS by calling `checkPermissions()`: ```javascript -NotificationsIOS.checkPermissions().then((currentPermissions) => { +Notifications.ios.checkPermissions().then((currentPermissions) => { console.log('Badges enabled: ' + !!currentPermissions.badge); console.log('Sounds enabled: ' + !!currentPermissions.sound); console.log('Alerts enabled: ' + !!currentPermissions.alert); }); ``` - - -## Android - -Android works similarly but using a different API; The equivalent code is: - -```javascript -import {NotificationsAndroid} from 'react-native-notifications'; - -// On Android, we allow for only one (global) listener per each event type. -NotificationsAndroid.setRegistrationTokenUpdateListener((deviceToken) => { - // TODO: Send the token to my server so it could send back push notifications... - console.log('Push-notifications registered!', deviceToken) -}); - -``` - -`deviceToken` being the token used to identify the device on the GCM. diff --git a/docs/advancedIos.md b/docs_old/advancedIos.md similarity index 98% rename from docs/advancedIos.md rename to docs_old/advancedIos.md index 27f69ce15..be68a9319 100644 --- a/docs/advancedIos.md +++ b/docs_old/advancedIos.md @@ -238,14 +238,14 @@ The [example app](https://github.com/wix/react-native-notifications/tree/master/ Get the current number: ```javascript -NotificationsIOS.getBadgesCount((count) => console.log(count)); +NotificationsIOS.getBadgeCount((count) => console.log(count)); ``` Set to specific number: ```javascript -NotificationsIOS.setBadgesCount(2); +NotificationsIOS.setBadgeCount(2); ``` Clear badges icon: ```javascript -NotificationsIOS.setBadgesCount(0); +NotificationsIOS.setBadgeCount(0); ``` diff --git a/docs/installation.md b/docs_old/installation.md similarity index 98% rename from docs/installation.md rename to docs_old/installation.md index 968ac9788..bf476e421 100644 --- a/docs/installation.md +++ b/docs_old/installation.md @@ -54,7 +54,7 @@ Add a reference to the library's native code in your global `settings.gradle`: ```gradle include ':reactnativenotifications' -project(':reactnativenotifications').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-notifications/android/app') +project(':reactnativenotifications').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-notifications/lib/android/app') ``` Declare the library as a dependency in your **app-project's** `build.gradle`: diff --git a/docs_old/localNotifications.md b/docs_old/localNotifications.md new file mode 100644 index 000000000..8f1d2b948 --- /dev/null +++ b/docs_old/localNotifications.md @@ -0,0 +1,84 @@ + +# Local Notifications + +## iOS + +You can manually trigger local notifications in your JS code, to be posted immediately or in the future. +Triggering local notifications is fully compatible with React Native `PushNotificationsIOS` library. + +Example: + +```javascript +let localNotification = NotificationsIOS.localNotification({ + body: "Local notificiation!", + title: "Local Notification Title", + sound: "chime.aiff", + silent: false, + category: "SOME_CATEGORY", + userInfo: { } +}); +``` + +Notification object contains: + +- **`fireDate`**- The date and time when the system should deliver the notification (optinal - default is immidiate dispatch). +- `body`- The message displayed in the notification alert. +- `title`- The title of the notification, displayed in the notifications center. +- `alertAction`- The "action" displayed beneath an actionable notification on the lockscreen (e.g. "Slide to **open**"). Note that Apple no longer shows this in iOS 10. +- `sound`- The sound played when the notification is fired (optional -- will play default sound if unspecified). This must be the filename of a sound included in the application bundle; the sound must be 30 seconds or less and should be encoded with linear PCM or IMA4. +- `silent`- Whether the notification sound should be suppressed (optional). +- `category`- The category of this notification, required for [interactive notifications](#interactive--actionable-notifications-ios-only) (optional). +- `userInfo`- An optional object containing additional notification data. + +### Cancel Scheduled Local Notifications + +The `NotificationsIOS.localNotification()` and `NotificationsAndroid.localNotification()` methods return unique `notificationId` values, which can be used in order to cancel specific local notifications that were scheduled for delivery on `fireDate` and have not yet been delivered. You can cancel local notification by calling `NotificationsIOS.cancelLocalNotification(notificationId)` or `NotificationsAndroid.cancelLocalNotification(notificationId)`. + +Example: + +```javascript +let someLocalNotification = NotificationsIOS.localNotification({ + body: "Local notificiation!", + title: "Local Notification Title", + sound: "chime.aiff", + category: "SOME_CATEGORY", + userInfo: { } +}); + +NotificationsIOS.cancelLocalNotification(someLocalNotification); +``` + +To cancel all local notifications (**iOS only!**), use `cancelAllLocalNotifications()`: + +```javascript +NotificationsIOS.cancelAllLocalNotifications(); +``` + +#### Cancel Delivered Local Notifications (iOS 10+ only) + +To dismiss notifications from the notification center that have already been shown to the user, call `NotificationsIOS.removeDeliveredNotifications([notificationId])`: + +```javascript +let someLocalNotification = NotificationsIOS.localNotification({...}); + +NotificationsIOS.removeDeliveredNotifications([someLocalNotification]); +``` + +Call `removeAllDeliveredNotifications()` to dismiss all delivered notifications +(note that this will dismiss push notifications in addition to local +notifications). + + +## Android + +Much like on iOS, notifications can be triggered locally. The API to do so is a simplified version of the iOS equivalent that works more natually with the Android perception of push (remote) notifications: + +```javascript +NotificationsAndroid.localNotification({ + title: "Local notification", + body: "This notification was generated by the app!", + extra: "data" +}); +``` + +Upon notification opening (tapping by the device user), all data fields will be delivered as-is). diff --git a/docs/notificationsEvents.md b/docs_old/notificationsEvents.md similarity index 100% rename from docs/notificationsEvents.md rename to docs_old/notificationsEvents.md diff --git a/docs_old/subscription.md b/docs_old/subscription.md new file mode 100644 index 000000000..ddd493e62 --- /dev/null +++ b/docs_old/subscription.md @@ -0,0 +1,77 @@ +# Push Notifications Subscription + +The typical flow for subscribing a device for receiving push notification in real time is to first register the device at the vendor's servers (e.g. GCM), then publishing the received token to your own push management servers. + +This section is about the first part of the flow. + +## iOS + +In order to handle notifications, you must register the `remoteNotificationsRegistered` event beforehand. + + +In your React Native app: + +```javascript +import NotificationsIOS from 'react-native-notifications'; + +class App extends Component { + constructor() { + NotificationsIOS.addEventListener('remoteNotificationsRegistered', this.onPushRegistered.bind(this)); + NotificationsIOS.addEventListener('remoteNotificationsRegistrationFailed', this.onPushRegistrationFailed.bind(this)); + NotificationsIOS.requestPermissions(); + } + + onPushRegistered(deviceToken) { + // TODO: Send the token to my server so it could send back push notifications... + console.log("Device Token Received", deviceToken); + } + + onPushRegistrationFailed(error) { + // For example: + // + // error={ + // domain: 'NSCocoaErroDomain', + // code: 3010, + // localizedDescription: 'remote notifications are not supported in the simulator' + // } + console.error(error); + } + + componentWillUnmount() { + // prevent memory leaks! + NotificationsIOS.removeEventListener('remoteNotificationsRegistered', this.onPushRegistered.bind(this)); + NotificationsIOS.removeEventListener('remoteNotificationsRegistrationFailed', this.onPushRegistrationFailed.bind(this)); + } +} + +``` + +When you have the device token, POST it to your server and register the device in your notifications provider (Amazon SNS, Azure, etc.). + +You can check if the user granted permissions by calling `checkPermissions()`: + +```javascript +NotificationsIOS.checkPermissions().then((currentPermissions) => { + console.log('Badges enabled: ' + !!currentPermissions.badge); + console.log('Sounds enabled: ' + !!currentPermissions.sound); + console.log('Alerts enabled: ' + !!currentPermissions.alert); +}); +``` + + +## Android + +Android works similarly but using a different API; The equivalent code is: + +```javascript +import {NotificationsAndroid} from 'react-native-notifications'; + +// On Android, we allow for only one (global) listener per each event type. +NotificationsAndroid.setRegistrationTokenUpdateListener((deviceToken) => { + // TODO: Send the token to my server so it could send back push notifications... + console.log('Push-notifications registered!', deviceToken) +}); + +``` + +`deviceToken` being the token used to identify the device on the GCM. diff --git a/e2e/Notifications.test.js b/e2e/Notifications.test.js index d6ede1100..09881409d 100644 --- a/e2e/Notifications.test.js +++ b/e2e/Notifications.test.js @@ -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 () => { @@ -30,9 +30,13 @@ describe('Notifications', () => { describe('Dead state', () => { it('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}) { diff --git a/example/android/myapplication/build.gradle b/example/android/myapplication/build.gradle index af1baf57e..cbfe3869d 100644 --- a/example/android/myapplication/build.gradle +++ b/example/android/myapplication/build.gradle @@ -2,8 +2,8 @@ apply plugin: "com.android.application" project.ext.react = [ root : "../../../", - entryFile: "index.android.js", - bundleAssetName: "index.android.bundle", + entryFile: "index.js", + bundleAssetName: "index.bundle", bundleInAlpha: true, bundleInBeta: true ] @@ -13,10 +13,9 @@ apply from: "../../../node_modules/react-native/react.gradle" android { compileSdkVersion 28 buildToolsVersion "28.0.3" - defaultConfig { applicationId "com.wix.reactnativenotifications.app" - minSdkVersion 19 + minSdkVersion 16 targetSdkVersion 28 versionCode 1 versionName "1.0" @@ -24,7 +23,6 @@ android { ndk { abiFilters "armeabi-v7a", "x86" } - missingDimensionStrategy "RNNotifications.reactNativeVersion", "reactNative60" } buildTypes { release { diff --git a/example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/MainActivity.java b/example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/MainActivity.java index 48f4dabc7..e600962f1 100644 --- a/example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/MainActivity.java +++ b/example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/MainActivity.java @@ -1,11 +1,12 @@ package com.wix.reactnativenotifications.app; +import android.os.Bundle; import com.facebook.react.ReactActivity; public class MainActivity extends ReactActivity { @Override protected String getMainComponentName() { - return "WixRNNotifications"; + return "NotificationsExampleApp"; } } diff --git a/example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/MainApplication.java b/example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/MainApplication.java index 110f09a93..021e42a17 100644 --- a/example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/MainApplication.java +++ b/example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/MainApplication.java @@ -30,7 +30,12 @@ protected List getPackages() { return Arrays.asList( new MainReactPackage(), new RNNotificationsPackage(MainApplication.this) - ); + ); + } + + @Override + protected String getJSMainModuleName() { + return "index"; } }; diff --git a/example/android/settings.gradle b/example/android/settings.gradle index 8e11e0797..ac64752eb 100644 --- a/example/android/settings.gradle +++ b/example/android/settings.gradle @@ -1,4 +1,4 @@ include ':myapplication' include ':react-native-notifications' -project(':react-native-notifications').projectDir = new File(rootProject.projectDir, '../../android/app') \ No newline at end of file +project(':react-native-notifications').projectDir = new File(rootProject.projectDir, '../../lib/android/app') \ No newline at end of file diff --git a/example/index.android.js b/example/index.android.js deleted file mode 100644 index 5c7faaf0f..000000000 --- a/example/index.android.js +++ /dev/null @@ -1,168 +0,0 @@ -'use strict'; - -import React, {Component} from 'react'; -import { - AppRegistry, - StyleSheet, - Text, - View, - Button, - TouchableHighlight -} from 'react-native'; - -import {NotificationsAndroid, PendingNotifications} from 'react-native-notifications'; - -let mainScreen; - -function onPushRegistered() { - if (mainScreen) { - mainScreen.onPushRegistered(); - } -} - -function onNotificationOpened(notification) { - if (mainScreen) { - mainScreen.onNotificationOpened(notification) - } -} - -function onNotificationReceived(notification) { - if (mainScreen) { - mainScreen.onNotificationReceived(notification) - } -} - -// It's highly recommended to keep listeners registration at global scope rather than at screen-scope seeing that -// component mount and unmount lifecycle tends to be asymmetric! -NotificationsAndroid.setRegistrationTokenUpdateListener(onPushRegistered); -NotificationsAndroid.setNotificationOpenedListener(onNotificationOpened); -NotificationsAndroid.setNotificationReceivedListener(onNotificationReceived); - -const styles = StyleSheet.create({ - container: { - flex: 1, - justifyContent: 'center', - }, - titleText: { - fontSize: 24, - textAlign: 'center', - margin: 10, - }, - bodyText: { - fontSize: 18, - textAlign: 'center', - margin: 10, - }, - mainButtonText: { - fontSize: 25, - fontStyle: 'italic', - fontWeight: 'bold', - textAlign: 'center', - margin: 10, - }, - plainButtonText: { - fontSize: 18, - fontStyle: 'italic', - textAlign: 'center', - margin: 10, - }, -}); - -class MainComponent extends Component { - - constructor(props) { - super(props); - - this.onPostNotification = this.onPostNotification.bind(this); - this.onCancelNotification = this.onCancelNotification.bind(this); - - this.state = { - elapsed: 0, - lastNotification: undefined - }; - - console.log('ReactScreen', 'ReactScreen'); - mainScreen = this; - - setInterval(this.onTick.bind(this), 1000); - } - - componentDidMount() { - console.log('ReactScreen', 'componentDidMount'); - PendingNotifications.getInitialNotification() - .then((notification) => {console.log("getInitialNotification:", notification); this.setState({initialNotification: (notification ? notification.getData() : undefined)});}) - .catch((err) => console.error("getInitialNotifiation failed", err)); - } - - componentWillUnmount() { - console.log('ReactScreen', 'componentWillUnmount'); - } - - onTick() { - this.setState({elapsed: this.state.elapsed + 1}); - } - - onPostNotification() { - this.lastNotificationId = NotificationsAndroid.localNotification({title: "Local notification", body: "This notification was generated by the app!"}); - } - - onCancelNotification() { - if (this.lastNotificationId) { - NotificationsAndroid.cancelLocalNotification(this.lastNotificationId); - this.lastNotificationId = undefined; - } - } - - render() { - return ( - - Wix React Native Notifications - {this.state.initialNotification ? 'Opened from notification' : ''} - Last notification: {this.state.lastNotification ? '\n'+this.state.lastNotification.body + ` (opened at ''${this.state.notificationRxTime})` : "N/A"} - Time elapsed: {this.state.elapsed} - {"\n\n"} - this.onPostNotification()}> - Try Me! - - this.onCancelNotification()}> - Undo last - - this.onCheckPermissions()}> - Check permissions - -