From 4e661458a7f06a691eb7aad7577308ad3273240b Mon Sep 17 00:00:00 2001 From: yogevbd Date: Mon, 9 Sep 2019 11:50:26 +0300 Subject: [PATCH] Split Notification.ts, Fix android example module --- example/android/myapplication/build.gradle | 3 +- .../app/MainActivity.java | 28 ++-------- .../app/MainApplication.java | 7 ++- example/index.js | 31 ++++++----- lib/android/app/build.gradle | 2 +- .../notification/PushNotificationProps.java | 10 ---- lib/src/Notifications.ts | 3 +- lib/src/adapters/CompletionCallbackWrapper.ts | 4 +- lib/src/adapters/NativeCommandsSender.ts | 5 +- lib/src/adapters/NativeEventsReceiver.ts | 8 ++- lib/src/commands/Commands.test.ts | 12 +++-- lib/src/commands/Commands.ts | 4 +- lib/src/events/EventsRegistry.test.ts | 19 +++---- lib/src/events/EventsRegistry.ts | 3 +- lib/src/interfaces/Notification.ts | 51 ++++++------------- .../interfaces/NotificationActionResponse.ts | 4 ++ lib/src/interfaces/NotificationCategory.ts | 18 +++++++ lib/src/interfaces/NotificationCompletion.ts | 5 ++ lib/src/interfaces/NotificationEvents.ts | 3 +- lib/src/interfaces/NotificationPermissions.ts | 5 ++ package.json | 3 +- 21 files changed, 117 insertions(+), 111 deletions(-) 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/NotificationPermissions.ts diff --git a/example/android/myapplication/build.gradle b/example/android/myapplication/build.gradle index 5c8cbee..2adc9ac 100644 --- a/example/android/myapplication/build.gradle +++ b/example/android/myapplication/build.gradle @@ -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" 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 0aa9149..30fedc6 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,18 @@ 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(), "NotificationsExampleApp", null); + @Override + protected String getMainComponentName() { + 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 87b0d3a..24c9cbc 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 @@ -24,7 +24,12 @@ public class MainApplication extends Application implements ReactApplication { return Arrays.asList( new MainReactPackage(), new RNNotificationsPackage(MainApplication.this) - ); + ); + } + + @Override + protected String getJSMainModuleName() { + return "index"; } }; diff --git a/example/index.js b/example/index.js index f047e96..c30bce5 100644 --- a/example/index.js +++ b/example/index.js @@ -6,7 +6,7 @@ import { Button } from 'react-native'; import React, {Component} from 'react'; -import { Notifications } from 'react-native-notifications'; +import {Notifications} from 'react-native-notifications'; class NotificationsExampleApp extends Component { constructor() { @@ -22,7 +22,7 @@ class NotificationsExampleApp extends Component { registerNotificationEvents() { Notifications.events().registerNotificationReceived((notification, completion) => { this.setState({ - notifications: [...this.state.notifications, notification.link] + notifications: [...this.state.notifications, notification] }); completion({alert: true, sound: false, badge: false}); @@ -30,15 +30,21 @@ class NotificationsExampleApp extends Component { Notifications.events().registerRemoteNotificationOpened((notification, completion) => { this.setState({ - notifications: [...this.state.notifications, `Notification Clicked: ${notification.link}`] + notifications: [...this.state.notifications, notification] }); - + completion(); }); } renderNotification(notification) { - return {`${notification}`}; + return ( + + {`Title: ${notification.title}`} + {`Body: ${notification.body}`} + {`Extra Link Param: ${notification.data.link}`} + + ); } requestPermissions() { @@ -51,7 +57,7 @@ class NotificationsExampleApp extends Component { title: String.fromCodePoint(0x1F44D), identifier: 'UPVOTE_ACTION' }; - + const replyAction = { activationMode: 'background', title: 'Reply', @@ -62,7 +68,7 @@ class NotificationsExampleApp extends Component { }, identifier: 'REPLY_ACTION' }; - + const category = { identifier: 'SOME_CATEGORY', actions: [upvoteAction, replyAction] @@ -88,13 +94,10 @@ class NotificationsExampleApp extends Component { async componentDidMount() { const initialNotification = await Notifications.getInitialNotification(); if (initialNotification) { - this.setState({notifications: [initialNotification.link, ...this.state.notifications]}); + this.setState({notifications: [initialNotification, ...this.state.notifications]}); } } - componentWillUnmount() { - } - render() { const notifications = this.state.notifications.map((notification, idx) => ( @@ -105,9 +108,9 @@ class NotificationsExampleApp extends Component { return ( -