mirror of
https://github.com/zhigang1992/react-native-notifications.git
synced 2026-01-12 22:50:34 +08:00
Extensibility step 4: reorganize folders, fix js issues
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.wix.reactnativenotifications.core;
|
||||
package com.wix.reactnativenotifications.core.notification;
|
||||
|
||||
public interface IPushNotification {
|
||||
class InvalidNotificationException extends Exception {
|
||||
@@ -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;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.wix.reactnativenotifications.core;
|
||||
package com.wix.reactnativenotifications.core.notification;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.wix.reactnativenotifications.core;
|
||||
package com.wix.reactnativenotifications.core.notificationdrawer;
|
||||
|
||||
public interface INotificationsDrawerApplication {
|
||||
IPushNotificationsDrawer getPushNotificationsDrawer();
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.wix.reactnativenotifications.core;
|
||||
package com.wix.reactnativenotifications.core.notificationdrawer;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
|
||||
@@ -1 +1,4 @@
|
||||
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 {
|
||||
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));
|
||||
|
||||
@@ -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": "../"
|
||||
},
|
||||
|
||||
@@ -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);
|
||||
20
notification.android.js
Normal file
20
notification.android.js
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,6 @@
|
||||
"bugs": {
|
||||
"url": "https://github.com/wix/react-native-notifications/issues"
|
||||
},
|
||||
"main": "index.ios.js",
|
||||
"babel": {
|
||||
"presets": [
|
||||
"react-native"
|
||||
|
||||
Reference in New Issue
Block a user