diff --git a/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/InitialNotification.java b/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/InitialNotification.java index 499d6cf2cba2f41f6fa5a814154a5b0a3d811f23..3d3e5fe0d7030f576ebd008457f704b3f2c69389 100644 --- a/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/InitialNotification.java +++ b/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/InitialNotification.java @@ -2,6 +2,8 @@ package com.wix.reactnativenotifications.core; import android.support.annotation.Nullable; +import com.wix.reactnativenotifications.core.notification.PushNotificationProps; + public class InitialNotification { private static PushNotificationProps sNotification; diff --git a/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/NotificationIntentAdapter.java b/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/NotificationIntentAdapter.java index 6868387499c1a33f32f034df8adcf7fe012a7eb8..de89b848adc424c58bfd2d198eb1d29bf5be5d8c 100644 --- a/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/NotificationIntentAdapter.java +++ b/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/NotificationIntentAdapter.java @@ -5,6 +5,8 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; +import com.wix.reactnativenotifications.core.notification.PushNotificationProps; + public class NotificationIntentAdapter { private static final int PENDING_INTENT_CODE = 0; private static final String PUSH_NOTIFICATION_EXTRA_NAME = "pushNotification"; diff --git a/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/ProxyService.java b/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/ProxyService.java index 4523b637b57a64b8072f0ad7c422f96f01b4c44b..bbc10c8b36bc7b101910d2c563959800a91f27b2 100644 --- a/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/ProxyService.java +++ b/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/ProxyService.java @@ -5,6 +5,9 @@ import android.content.Intent; import android.os.Bundle; import android.util.Log; +import com.wix.reactnativenotifications.core.notification.IPushNotification; +import com.wix.reactnativenotifications.core.notification.PushNotification; + public class ProxyService extends IntentService { private static final String TAG = ProxyService.class.getSimpleName(); diff --git a/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/RNNotificationsModule.java b/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/RNNotificationsModule.java index 6e554cbc2b29de3dfff69692976a41ec8d1ed9d8..5db1c3273b35712486f2f5a16031c9837d2e445b 100644 --- a/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/RNNotificationsModule.java +++ b/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/RNNotificationsModule.java @@ -12,6 +12,9 @@ import com.facebook.react.bridge.Promise; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactMethod; +import com.wix.reactnativenotifications.core.notification.PushNotificationProps; +import com.wix.reactnativenotifications.core.notificationdrawer.IPushNotificationsDrawer; +import com.wix.reactnativenotifications.core.notificationdrawer.PushNotificationsDrawer; import com.wix.reactnativenotifications.gcm.GcmInstanceIdRefreshHandlerService; import static com.wix.reactnativenotifications.Defs.LOGTAG; @@ -36,7 +39,7 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule implements Log.d(LOGTAG, "Native module init"); startGcmIntentService(GcmInstanceIdRefreshHandlerService.EXTRA_IS_APP_INIT); - IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(getReactApplicationContext().getApplicationContext()); + final IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(getReactApplicationContext().getApplicationContext()); notificationsDrawer.onAppInit(); } @@ -65,7 +68,7 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule implements @Override public void onAppVisible() { - IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(getReactApplicationContext().getApplicationContext()); + final IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(getReactApplicationContext().getApplicationContext()); notificationsDrawer.onAppVisible(); } @@ -75,7 +78,7 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule implements @Override public void onActivityCreated(Activity activity, Bundle savedInstanceState) { - IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(getReactApplicationContext().getApplicationContext()); + final IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(getReactApplicationContext().getApplicationContext()); notificationsDrawer.onNewActivity(activity); } diff --git a/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/INotificationsApplication.java b/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/notification/INotificationsApplication.java similarity index 62% rename from example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/INotificationsApplication.java rename to example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/notification/INotificationsApplication.java index 150051490b50a26b11235b4760b0665372faca69..6b46988ed3d2c3db15f22a7fc121ad261d8b55ba 100644 --- a/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/INotificationsApplication.java +++ b/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/notification/INotificationsApplication.java @@ -1,8 +1,10 @@ -package com.wix.reactnativenotifications.core; +package com.wix.reactnativenotifications.core.notification; import android.content.Context; import android.os.Bundle; +import com.wix.reactnativenotifications.core.AppLifecycleFacade; + public interface INotificationsApplication { IPushNotification getPushNotification(Context context, Bundle bundle, AppLifecycleFacade facade); } diff --git a/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/IPushNotification.java b/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/notification/IPushNotification.java similarity index 90% rename from example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/IPushNotification.java rename to example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/notification/IPushNotification.java index 5b1d8e9701cfdde93a58d44f70dfe8ac320b9023..a142f4969b1bc24f98ba256841247f854010d30c 100644 --- a/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/IPushNotification.java +++ b/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/notification/IPushNotification.java @@ -1,4 +1,4 @@ -package com.wix.reactnativenotifications.core; +package com.wix.reactnativenotifications.core.notification; public interface IPushNotification { class InvalidNotificationException extends Exception { diff --git a/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/PushNotification.java b/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java similarity index 92% rename from example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/PushNotification.java rename to example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java index 176cb560ad8b3cc824dca77df8952f0cc18d43f1..f3cae79d611a0074254e01e06259c540ccaefcd4 100644 --- a/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/PushNotification.java +++ b/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java @@ -1,4 +1,4 @@ -package com.wix.reactnativenotifications.core; +package com.wix.reactnativenotifications.core.notification; import android.app.Notification; import android.app.NotificationManager; @@ -14,7 +14,13 @@ import com.facebook.react.bridge.Arguments; import com.facebook.react.bridge.ReactContext; import com.facebook.react.bridge.WritableMap; import com.facebook.react.modules.core.DeviceEventManagerModule; +import com.wix.reactnativenotifications.core.AppLaunchHelper; +import com.wix.reactnativenotifications.core.AppLifecycleFacade; import com.wix.reactnativenotifications.core.AppLifecycleFacade.AppVisibilityListener; +import com.wix.reactnativenotifications.core.InitialNotification; +import com.wix.reactnativenotifications.core.NotificationIntentAdapter; +import com.wix.reactnativenotifications.core.ProxyService; +import com.wix.reactnativenotifications.core.notificationdrawer.PushNotificationsDrawer; import static com.wix.reactnativenotifications.Defs.NOTIFICATION_OPENED_EVENT_NAME; import static com.wix.reactnativenotifications.Defs.NOTIFICATION_RECEIVED_EVENT_NAME; diff --git a/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/PushNotificationProps.java b/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotificationProps.java similarity index 94% rename from example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/PushNotificationProps.java rename to example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotificationProps.java index 33936b04eace093f5489b975bd7a2d253961a992..d4512ced5ab6a874ddbcd0312aee5fb8209b5819 100644 --- a/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/PushNotificationProps.java +++ b/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotificationProps.java @@ -1,4 +1,4 @@ -package com.wix.reactnativenotifications.core; +package com.wix.reactnativenotifications.core.notification; import android.os.Bundle; diff --git a/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/INotificationsDrawerApplication.java b/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/INotificationsDrawerApplication.java similarity index 63% rename from example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/INotificationsDrawerApplication.java rename to example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/INotificationsDrawerApplication.java index 13cffc708a197fbd1491413483ac1a438e6aa65a..fe17c74c232aa729462c7b35b9a8a5ee4127a124 100644 --- a/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/INotificationsDrawerApplication.java +++ b/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/INotificationsDrawerApplication.java @@ -1,4 +1,4 @@ -package com.wix.reactnativenotifications.core; +package com.wix.reactnativenotifications.core.notificationdrawer; public interface INotificationsDrawerApplication { IPushNotificationsDrawer getPushNotificationsDrawer(); diff --git a/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/IPushNotificationsDrawer.java b/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/IPushNotificationsDrawer.java similarity index 75% rename from example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/IPushNotificationsDrawer.java rename to example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/IPushNotificationsDrawer.java index 13a1b3039f496661ca5454afb27710aa1aebb3f9..6711baa30cfdf7f443cffa4752613def6007f5ab 100644 --- a/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/IPushNotificationsDrawer.java +++ b/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/IPushNotificationsDrawer.java @@ -1,4 +1,4 @@ -package com.wix.reactnativenotifications.core; +package com.wix.reactnativenotifications.core.notificationdrawer; import android.app.Activity; diff --git a/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/PushNotificationsDrawer.java b/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/PushNotificationsDrawer.java similarity index 87% rename from example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/PushNotificationsDrawer.java rename to example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/PushNotificationsDrawer.java index 6aedd99b9ffe2c34116cd60e595ffd64d9e30ef6..c0aa9235cd483ac295878d495cc0a6da580943a1 100644 --- a/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/PushNotificationsDrawer.java +++ b/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/PushNotificationsDrawer.java @@ -1,9 +1,12 @@ -package com.wix.reactnativenotifications.core; +package com.wix.reactnativenotifications.core.notificationdrawer; import android.app.Activity; import android.app.NotificationManager; import android.content.Context; +import com.wix.reactnativenotifications.core.AppLaunchHelper; +import com.wix.reactnativenotifications.core.InitialNotification; + public class PushNotificationsDrawer implements IPushNotificationsDrawer { protected final Context mContext; diff --git a/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/gcm/GcmMessageHandlerService.java b/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/gcm/GcmMessageHandlerService.java index 9c60ce7c650625d07ebb6252bb8b8adbf41444df..5a75a9a3acb4c3d78c80f86b4b294ef0c0c0a503 100644 --- a/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/gcm/GcmMessageHandlerService.java +++ b/example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/gcm/GcmMessageHandlerService.java @@ -4,8 +4,8 @@ import android.os.Bundle; import android.util.Log; import com.google.android.gms.gcm.GcmListenerService; -import com.wix.reactnativenotifications.core.IPushNotification; -import com.wix.reactnativenotifications.core.PushNotification; +import com.wix.reactnativenotifications.core.notification.IPushNotification; +import com.wix.reactnativenotifications.core.notification.PushNotification; import com.wix.reactnativenotifications.core.ReactAppLifecycleFacade; import static com.wix.reactnativenotifications.Defs.LOGTAG; diff --git a/example/android/settings.gradle b/example/android/settings.gradle index 35b948e6b00428b325f27c78697932628f725049..588dd4856de64bd2e82693395f8f24829bc6f501 100644 --- a/example/android/settings.gradle +++ b/example/android/settings.gradle @@ -1 +1,4 @@ -include ':reactnativenotification', ':myapplication' +include ':myapplication' + +include ':reactnativenotification' +//project(':reactnativenotification').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-notification/android') diff --git a/example/index.android.js b/example/index.android.js index e6e9d5529b13f3f9a1f3b16117cc4bbdb861fa60..b0af4b48f3fc411cc4a36de8c1f478b3fe29cb83 100644 --- a/example/index.android.js +++ b/example/index.android.js @@ -5,11 +5,10 @@ import { AppRegistry, StyleSheet, Text, - View, - TouchableHighlight + View } from 'react-native'; -import {NotificationsAndroid, PendingNotifications} from './notifications'; +import {NotificationsAndroid, PendingNotifications} from 'react-native-notifications'; let mainScreen; @@ -31,6 +30,8 @@ function 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 tend to be asymmetric! NotificationsAndroid.setRegistrationTokenUpdateListener(onPushRegistered); NotificationsAndroid.setNotificationOpenedListener(onNotificationOpened); NotificationsAndroid.setNotificationReceivedListener(onNotificationReceived); @@ -64,11 +65,12 @@ class MainComponent extends Component { console.log('ReactScreen', 'ReactScreen'); mainScreen = this; + + setInterval(this.onTick.bind(this), 1000); } componentDidMount() { console.log('ReactScreen', 'componentDidMount'); - setInterval(this.onTick.bind(this), 1000); PendingNotifications.getInitialNotification() .then((notification) => {console.log("getInitialNotification:", notification); this.setState({initialNotification: notification.getData()});}) .catch((err) => console.error("getInitialNotifiation failed", err)); diff --git a/example/package.json b/example/package.json index 8712369c230f07dc0a50b5bb8f597166733ff188..29be05403937d7f42d260b61fee69c3993a590ac 100644 --- a/example/package.json +++ b/example/package.json @@ -7,7 +7,7 @@ }, "dependencies": { "babel-preset-react-native-stage-0": "^1.0.1", - "react": "^15.3.1", + "react": "15.3.1", "react-native": "0.34.0", "react-native-notifications": "../" }, diff --git a/example/notifications.android.js b/index.android.js similarity index 82% rename from example/notifications.android.js rename to index.android.js index 1fc102632e97e1a3baf9ab8cf09fde09f821d467..e0517bc8b8a7d328a4423e2ff6cd3e3d94982ff3 100644 --- a/example/notifications.android.js +++ b/index.android.js @@ -1,5 +1,5 @@ -require('react'); import {NativeModules, DeviceEventEmitter} from 'react-native'; +import NotificationAndroid from './notification'; const RNNotifications = NativeModules.WixRNNotifications; @@ -7,26 +7,6 @@ let notificationReceivedListener; let notificationOpenedListener; let registrationTokenUpdateListener; -/** A wrapper to align Android with iOS in terms on notification structure. */ -class NotificationAndroid { - - constructor(notification) { - this.data = notification; - } - - getData() { - return this.data; - } - - getTitle() { - return this.data.title; - } - - getMessage() { - return this.data.body; - } -} - export class NotificationsAndroid { static setRegistrationTokenUpdateListener(listener) { registrationTokenUpdateListener = DeviceEventEmitter.addListener('remoteNotificationsRegistered', listener); diff --git a/notification.android.js b/notification.android.js new file mode 100644 index 0000000000000000000000000000000000000000..bb2ace85e1dfa5656311edf703250dd2fdd352ec --- /dev/null +++ b/notification.android.js @@ -0,0 +1,20 @@ +/** A wrapper to align Android with iOS in terms on notification structure. */ +export default class NotificationAndroid { + + constructor(notification) { + this.data = notification; + } + + getData() { + return this.data; + } + + getTitle() { + return this.data.title; + } + + getMessage() { + return this.data.body; + } +} + diff --git a/package.json b/package.json index e7431aa507a2f55fa367b4871227684ac0a8b59d..ec648ba9a7666c7b5e326550ce784db8335fef2c 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,6 @@ "bugs": { "url": "https://github.com/wix/react-native-notifications/issues" }, - "main": "index.ios.js", "babel": { "presets": [ "react-native"