Commit 4c846f0d authored by Amit Davidi's avatar Amit Davidi

Extensibility step 4: reorganize folders, fix js issues

parent 3f4bb620
...@@ -2,6 +2,8 @@ package com.wix.reactnativenotifications.core; ...@@ -2,6 +2,8 @@ package com.wix.reactnativenotifications.core;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import com.wix.reactnativenotifications.core.notification.PushNotificationProps;
public class InitialNotification { public class InitialNotification {
private static PushNotificationProps sNotification; private static PushNotificationProps sNotification;
......
...@@ -5,6 +5,8 @@ import android.content.Context; ...@@ -5,6 +5,8 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import com.wix.reactnativenotifications.core.notification.PushNotificationProps;
public class NotificationIntentAdapter { public class NotificationIntentAdapter {
private static final int PENDING_INTENT_CODE = 0; private static final int PENDING_INTENT_CODE = 0;
private static final String PUSH_NOTIFICATION_EXTRA_NAME = "pushNotification"; private static final String PUSH_NOTIFICATION_EXTRA_NAME = "pushNotification";
......
...@@ -5,6 +5,9 @@ import android.content.Intent; ...@@ -5,6 +5,9 @@ import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import com.wix.reactnativenotifications.core.notification.IPushNotification;
import com.wix.reactnativenotifications.core.notification.PushNotification;
public class ProxyService extends IntentService { public class ProxyService extends IntentService {
private static final String TAG = ProxyService.class.getSimpleName(); private static final String TAG = ProxyService.class.getSimpleName();
......
...@@ -12,6 +12,9 @@ import com.facebook.react.bridge.Promise; ...@@ -12,6 +12,9 @@ import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod; 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 com.wix.reactnativenotifications.gcm.GcmInstanceIdRefreshHandlerService;
import static com.wix.reactnativenotifications.Defs.LOGTAG; import static com.wix.reactnativenotifications.Defs.LOGTAG;
...@@ -36,7 +39,7 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule implements ...@@ -36,7 +39,7 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule implements
Log.d(LOGTAG, "Native module init"); Log.d(LOGTAG, "Native module init");
startGcmIntentService(GcmInstanceIdRefreshHandlerService.EXTRA_IS_APP_INIT); startGcmIntentService(GcmInstanceIdRefreshHandlerService.EXTRA_IS_APP_INIT);
IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(getReactApplicationContext().getApplicationContext()); final IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(getReactApplicationContext().getApplicationContext());
notificationsDrawer.onAppInit(); notificationsDrawer.onAppInit();
} }
...@@ -65,7 +68,7 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule implements ...@@ -65,7 +68,7 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule implements
@Override @Override
public void onAppVisible() { public void onAppVisible() {
IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(getReactApplicationContext().getApplicationContext()); final IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(getReactApplicationContext().getApplicationContext());
notificationsDrawer.onAppVisible(); notificationsDrawer.onAppVisible();
} }
...@@ -75,7 +78,7 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule implements ...@@ -75,7 +78,7 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule implements
@Override @Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) { public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(getReactApplicationContext().getApplicationContext()); final IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(getReactApplicationContext().getApplicationContext());
notificationsDrawer.onNewActivity(activity); notificationsDrawer.onNewActivity(activity);
} }
......
package com.wix.reactnativenotifications.core; package com.wix.reactnativenotifications.core.notification;
import android.content.Context; import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import com.wix.reactnativenotifications.core.AppLifecycleFacade;
public interface INotificationsApplication { public interface INotificationsApplication {
IPushNotification getPushNotification(Context context, Bundle bundle, AppLifecycleFacade facade); IPushNotification getPushNotification(Context context, Bundle bundle, AppLifecycleFacade facade);
} }
package com.wix.reactnativenotifications.core; package com.wix.reactnativenotifications.core.notification;
public interface IPushNotification { public interface IPushNotification {
class InvalidNotificationException extends Exception { class InvalidNotificationException extends Exception {
......
package com.wix.reactnativenotifications.core; package com.wix.reactnativenotifications.core.notification;
import android.app.Notification; import android.app.Notification;
import android.app.NotificationManager; import android.app.NotificationManager;
...@@ -14,7 +14,13 @@ import com.facebook.react.bridge.Arguments; ...@@ -14,7 +14,13 @@ import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReactContext; import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.WritableMap; import com.facebook.react.bridge.WritableMap;
import com.facebook.react.modules.core.DeviceEventManagerModule; 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.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_OPENED_EVENT_NAME;
import static com.wix.reactnativenotifications.Defs.NOTIFICATION_RECEIVED_EVENT_NAME; import static com.wix.reactnativenotifications.Defs.NOTIFICATION_RECEIVED_EVENT_NAME;
......
package com.wix.reactnativenotifications.core; package com.wix.reactnativenotifications.core.notificationdrawer;
public interface INotificationsDrawerApplication { public interface INotificationsDrawerApplication {
IPushNotificationsDrawer getPushNotificationsDrawer(); IPushNotificationsDrawer getPushNotificationsDrawer();
......
package com.wix.reactnativenotifications.core; package com.wix.reactnativenotifications.core.notificationdrawer;
import android.app.Activity; import android.app.Activity;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.content.Context; import android.content.Context;
import com.wix.reactnativenotifications.core.AppLaunchHelper;
import com.wix.reactnativenotifications.core.InitialNotification;
public class PushNotificationsDrawer implements IPushNotificationsDrawer { public class PushNotificationsDrawer implements IPushNotificationsDrawer {
protected final Context mContext; protected final Context mContext;
......
...@@ -4,8 +4,8 @@ import android.os.Bundle; ...@@ -4,8 +4,8 @@ import android.os.Bundle;
import android.util.Log; import android.util.Log;
import com.google.android.gms.gcm.GcmListenerService; import com.google.android.gms.gcm.GcmListenerService;
import com.wix.reactnativenotifications.core.IPushNotification; import com.wix.reactnativenotifications.core.notification.IPushNotification;
import com.wix.reactnativenotifications.core.PushNotification; import com.wix.reactnativenotifications.core.notification.PushNotification;
import com.wix.reactnativenotifications.core.ReactAppLifecycleFacade; import com.wix.reactnativenotifications.core.ReactAppLifecycleFacade;
import static com.wix.reactnativenotifications.Defs.LOGTAG; import static com.wix.reactnativenotifications.Defs.LOGTAG;
......
include ':reactnativenotification', ':myapplication' include ':myapplication'
include ':reactnativenotification'
//project(':reactnativenotification').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-notification/android')
...@@ -5,11 +5,10 @@ import { ...@@ -5,11 +5,10 @@ import {
AppRegistry, AppRegistry,
StyleSheet, StyleSheet,
Text, Text,
View, View
TouchableHighlight
} from 'react-native'; } from 'react-native';
import {NotificationsAndroid, PendingNotifications} from './notifications'; import {NotificationsAndroid, PendingNotifications} from 'react-native-notifications';
let mainScreen; let mainScreen;
...@@ -31,6 +30,8 @@ function onNotificationReceived(notification) { ...@@ -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.setRegistrationTokenUpdateListener(onPushRegistered);
NotificationsAndroid.setNotificationOpenedListener(onNotificationOpened); NotificationsAndroid.setNotificationOpenedListener(onNotificationOpened);
NotificationsAndroid.setNotificationReceivedListener(onNotificationReceived); NotificationsAndroid.setNotificationReceivedListener(onNotificationReceived);
...@@ -64,11 +65,12 @@ class MainComponent extends Component { ...@@ -64,11 +65,12 @@ class MainComponent extends Component {
console.log('ReactScreen', 'ReactScreen'); console.log('ReactScreen', 'ReactScreen');
mainScreen = this; mainScreen = this;
setInterval(this.onTick.bind(this), 1000);
} }
componentDidMount() { componentDidMount() {
console.log('ReactScreen', 'componentDidMount'); console.log('ReactScreen', 'componentDidMount');
setInterval(this.onTick.bind(this), 1000);
PendingNotifications.getInitialNotification() PendingNotifications.getInitialNotification()
.then((notification) => {console.log("getInitialNotification:", notification); this.setState({initialNotification: notification.getData()});}) .then((notification) => {console.log("getInitialNotification:", notification); this.setState({initialNotification: notification.getData()});})
.catch((err) => console.error("getInitialNotifiation failed", err)); .catch((err) => console.error("getInitialNotifiation failed", err));
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
}, },
"dependencies": { "dependencies": {
"babel-preset-react-native-stage-0": "^1.0.1", "babel-preset-react-native-stage-0": "^1.0.1",
"react": "^15.3.1", "react": "15.3.1",
"react-native": "0.34.0", "react-native": "0.34.0",
"react-native-notifications": "../" "react-native-notifications": "../"
}, },
......
require('react');
import {NativeModules, DeviceEventEmitter} from 'react-native'; import {NativeModules, DeviceEventEmitter} from 'react-native';
import NotificationAndroid from './notification';
const RNNotifications = NativeModules.WixRNNotifications; const RNNotifications = NativeModules.WixRNNotifications;
...@@ -7,26 +7,6 @@ let notificationReceivedListener; ...@@ -7,26 +7,6 @@ let notificationReceivedListener;
let notificationOpenedListener; let notificationOpenedListener;
let registrationTokenUpdateListener; 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 { export class NotificationsAndroid {
static setRegistrationTokenUpdateListener(listener) { static setRegistrationTokenUpdateListener(listener) {
registrationTokenUpdateListener = DeviceEventEmitter.addListener('remoteNotificationsRegistered', listener); registrationTokenUpdateListener = DeviceEventEmitter.addListener('remoteNotificationsRegistered', listener);
......
/** 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;
}
}
...@@ -56,7 +56,6 @@ ...@@ -56,7 +56,6 @@
"bugs": { "bugs": {
"url": "https://github.com/wix/react-native-notifications/issues" "url": "https://github.com/wix/react-native-notifications/issues"
}, },
"main": "index.ios.js",
"babel": { "babel": {
"presets": [ "presets": [
"react-native" "react-native"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment