Skip to content

Commit 4c846f0

Browse files
committed
Extensibility step 4: reorganize folders, fix js issues
1 parent 3f4bb62 commit 4c846f0

18 files changed

+65
-40
lines changed

example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/InitialNotification.java

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import android.support.annotation.Nullable;
44

5+
import com.wix.reactnativenotifications.core.notification.PushNotificationProps;
6+
57
public class InitialNotification {
68
private static PushNotificationProps sNotification;
79

example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/NotificationIntentAdapter.java

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import android.content.Intent;
66
import android.os.Bundle;
77

8+
import com.wix.reactnativenotifications.core.notification.PushNotificationProps;
9+
810
public class NotificationIntentAdapter {
911
private static final int PENDING_INTENT_CODE = 0;
1012
private static final String PUSH_NOTIFICATION_EXTRA_NAME = "pushNotification";

example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/ProxyService.java

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import android.os.Bundle;
66
import android.util.Log;
77

8+
import com.wix.reactnativenotifications.core.notification.IPushNotification;
9+
import com.wix.reactnativenotifications.core.notification.PushNotification;
10+
811
public class ProxyService extends IntentService {
912

1013
private static final String TAG = ProxyService.class.getSimpleName();

example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/RNNotificationsModule.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
import com.facebook.react.bridge.ReactApplicationContext;
1313
import com.facebook.react.bridge.ReactContextBaseJavaModule;
1414
import com.facebook.react.bridge.ReactMethod;
15+
import com.wix.reactnativenotifications.core.notification.PushNotificationProps;
16+
import com.wix.reactnativenotifications.core.notificationdrawer.IPushNotificationsDrawer;
17+
import com.wix.reactnativenotifications.core.notificationdrawer.PushNotificationsDrawer;
1518
import com.wix.reactnativenotifications.gcm.GcmInstanceIdRefreshHandlerService;
1619

1720
import static com.wix.reactnativenotifications.Defs.LOGTAG;
@@ -36,7 +39,7 @@ public void initialize() {
3639
Log.d(LOGTAG, "Native module init");
3740
startGcmIntentService(GcmInstanceIdRefreshHandlerService.EXTRA_IS_APP_INIT);
3841

39-
IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(getReactApplicationContext().getApplicationContext());
42+
final IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(getReactApplicationContext().getApplicationContext());
4043
notificationsDrawer.onAppInit();
4144
}
4245

@@ -65,7 +68,7 @@ public void getInitialNotification(final Promise promise) {
6568

6669
@Override
6770
public void onAppVisible() {
68-
IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(getReactApplicationContext().getApplicationContext());
71+
final IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(getReactApplicationContext().getApplicationContext());
6972
notificationsDrawer.onAppVisible();
7073
}
7174

@@ -75,7 +78,7 @@ public void onAppNotVisible() {
7578

7679
@Override
7780
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
78-
IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(getReactApplicationContext().getApplicationContext());
81+
final IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(getReactApplicationContext().getApplicationContext());
7982
notificationsDrawer.onNewActivity(activity);
8083
}
8184

Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
package com.wix.reactnativenotifications.core;
1+
package com.wix.reactnativenotifications.core.notification;
22

33
import android.content.Context;
44
import android.os.Bundle;
55

6+
import com.wix.reactnativenotifications.core.AppLifecycleFacade;
7+
68
public interface INotificationsApplication {
79
IPushNotification getPushNotification(Context context, Bundle bundle, AppLifecycleFacade facade);
810
}

example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/IPushNotification.java example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/notification/IPushNotification.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.wix.reactnativenotifications.core;
1+
package com.wix.reactnativenotifications.core.notification;
22

33
public interface IPushNotification {
44
class InvalidNotificationException extends Exception {

example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/PushNotification.java example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.wix.reactnativenotifications.core;
1+
package com.wix.reactnativenotifications.core.notification;
22

33
import android.app.Notification;
44
import android.app.NotificationManager;
@@ -14,7 +14,13 @@
1414
import com.facebook.react.bridge.ReactContext;
1515
import com.facebook.react.bridge.WritableMap;
1616
import com.facebook.react.modules.core.DeviceEventManagerModule;
17+
import com.wix.reactnativenotifications.core.AppLaunchHelper;
18+
import com.wix.reactnativenotifications.core.AppLifecycleFacade;
1719
import com.wix.reactnativenotifications.core.AppLifecycleFacade.AppVisibilityListener;
20+
import com.wix.reactnativenotifications.core.InitialNotification;
21+
import com.wix.reactnativenotifications.core.NotificationIntentAdapter;
22+
import com.wix.reactnativenotifications.core.ProxyService;
23+
import com.wix.reactnativenotifications.core.notificationdrawer.PushNotificationsDrawer;
1824

1925
import static com.wix.reactnativenotifications.Defs.NOTIFICATION_OPENED_EVENT_NAME;
2026
import static com.wix.reactnativenotifications.Defs.NOTIFICATION_RECEIVED_EVENT_NAME;

example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/PushNotificationProps.java example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotificationProps.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.wix.reactnativenotifications.core;
1+
package com.wix.reactnativenotifications.core.notification;
22

33
import android.os.Bundle;
44

example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/INotificationsDrawerApplication.java example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/INotificationsDrawerApplication.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.wix.reactnativenotifications.core;
1+
package com.wix.reactnativenotifications.core.notificationdrawer;
22

33
public interface INotificationsDrawerApplication {
44
IPushNotificationsDrawer getPushNotificationsDrawer();

example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/IPushNotificationsDrawer.java example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/IPushNotificationsDrawer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.wix.reactnativenotifications.core;
1+
package com.wix.reactnativenotifications.core.notificationdrawer;
22

33
import android.app.Activity;
44

example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/PushNotificationsDrawer.java example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/notificationdrawer/PushNotificationsDrawer.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
package com.wix.reactnativenotifications.core;
1+
package com.wix.reactnativenotifications.core.notificationdrawer;
22

33
import android.app.Activity;
44
import android.app.NotificationManager;
55
import android.content.Context;
66

7+
import com.wix.reactnativenotifications.core.AppLaunchHelper;
8+
import com.wix.reactnativenotifications.core.InitialNotification;
9+
710
public class PushNotificationsDrawer implements IPushNotificationsDrawer {
811

912
protected final Context mContext;

example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/gcm/GcmMessageHandlerService.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import android.util.Log;
55

66
import com.google.android.gms.gcm.GcmListenerService;
7-
import com.wix.reactnativenotifications.core.IPushNotification;
8-
import com.wix.reactnativenotifications.core.PushNotification;
7+
import com.wix.reactnativenotifications.core.notification.IPushNotification;
8+
import com.wix.reactnativenotifications.core.notification.PushNotification;
99
import com.wix.reactnativenotifications.core.ReactAppLifecycleFacade;
1010

1111
import static com.wix.reactnativenotifications.Defs.LOGTAG;

example/android/settings.gradle

+4-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
include ':reactnativenotification', ':myapplication'
1+
include ':myapplication'
2+
3+
include ':reactnativenotification'
4+
//project(':reactnativenotification').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-notification/android')

example/index.android.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ import {
55
AppRegistry,
66
StyleSheet,
77
Text,
8-
View,
9-
TouchableHighlight
8+
View
109
} from 'react-native';
1110

12-
import {NotificationsAndroid, PendingNotifications} from './notifications';
11+
import {NotificationsAndroid, PendingNotifications} from 'react-native-notifications';
1312

1413
let mainScreen;
1514

@@ -31,6 +30,8 @@ function onNotificationReceived(notification) {
3130
}
3231
}
3332

33+
// It's highly recommended to keep listeners registration at global scope rather than at screen-scope seeing that
34+
// component mount and unmount lifecycle tend to be asymmetric!
3435
NotificationsAndroid.setRegistrationTokenUpdateListener(onPushRegistered);
3536
NotificationsAndroid.setNotificationOpenedListener(onNotificationOpened);
3637
NotificationsAndroid.setNotificationReceivedListener(onNotificationReceived);
@@ -64,11 +65,12 @@ class MainComponent extends Component {
6465

6566
console.log('ReactScreen', 'ReactScreen');
6667
mainScreen = this;
68+
69+
setInterval(this.onTick.bind(this), 1000);
6770
}
6871

6972
componentDidMount() {
7073
console.log('ReactScreen', 'componentDidMount');
71-
setInterval(this.onTick.bind(this), 1000);
7274
PendingNotifications.getInitialNotification()
7375
.then((notification) => {console.log("getInitialNotification:", notification); this.setState({initialNotification: notification.getData()});})
7476
.catch((err) => console.error("getInitialNotifiation failed", err));

example/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
"dependencies": {
99
"babel-preset-react-native-stage-0": "^1.0.1",
10-
"react": "^15.3.1",
10+
"react": "15.3.1",
1111
"react-native": "0.34.0",
1212
"react-native-notifications": "../"
1313
},

example/notifications.android.js index.android.js

+1-21
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,12 @@
1-
require('react');
21
import {NativeModules, DeviceEventEmitter} from 'react-native';
2+
import NotificationAndroid from './notification';
33

44
const RNNotifications = NativeModules.WixRNNotifications;
55

66
let notificationReceivedListener;
77
let notificationOpenedListener;
88
let registrationTokenUpdateListener;
99

10-
/** A wrapper to align Android with iOS in terms on notification structure. */
11-
class NotificationAndroid {
12-
13-
constructor(notification) {
14-
this.data = notification;
15-
}
16-
17-
getData() {
18-
return this.data;
19-
}
20-
21-
getTitle() {
22-
return this.data.title;
23-
}
24-
25-
getMessage() {
26-
return this.data.body;
27-
}
28-
}
29-
3010
export class NotificationsAndroid {
3111
static setRegistrationTokenUpdateListener(listener) {
3212
registrationTokenUpdateListener = DeviceEventEmitter.addListener('remoteNotificationsRegistered', listener);

notification.android.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/** A wrapper to align Android with iOS in terms on notification structure. */
2+
export default class NotificationAndroid {
3+
4+
constructor(notification) {
5+
this.data = notification;
6+
}
7+
8+
getData() {
9+
return this.data;
10+
}
11+
12+
getTitle() {
13+
return this.data.title;
14+
}
15+
16+
getMessage() {
17+
return this.data.body;
18+
}
19+
}
20+

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
"bugs": {
5757
"url": "https://github.com/wix/react-native-notifications/issues"
5858
},
59-
"main": "index.ios.js",
6059
"babel": {
6160
"presets": [
6261
"react-native"

0 commit comments

Comments
 (0)