Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
react-native-notifications
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Jira
Jira
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
冷佳娟
react-native-notifications
Commits
3f4bb620
Commit
3f4bb620
authored
Nov 16, 2016
by
Amit Davidi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extensibility refactor step 3: notification drawer & init-notification cleanup
parent
27906420
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
179 additions
and
34 deletions
+179
-34
example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/MainApplication.java
...com/wix/reactnativenotifications/app/MainApplication.java
+1
-1
example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/RNNotificationsPackage.java
.../wix/reactnativenotifications/RNNotificationsPackage.java
+10
-1
example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/AppLaunchHelper.java
...om/wix/reactnativenotifications/core/AppLaunchHelper.java
+3
-1
example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/INotificationsDrawerApplication.java
...venotifications/core/INotificationsDrawerApplication.java
+5
-0
example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/IPushNotificationsDrawer.java
...actnativenotifications/core/IPushNotificationsDrawer.java
+11
-0
example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/InitialNotification.java
...ix/reactnativenotifications/core/InitialNotification.java
+4
-0
example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/PushNotification.java
...m/wix/reactnativenotifications/core/PushNotification.java
+1
-6
example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/PushNotificationsDrawer.java
...eactnativenotifications/core/PushNotificationsDrawer.java
+51
-0
example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/RNNotificationsModule.java
.../reactnativenotifications/core/RNNotificationsModule.java
+57
-12
example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/ReactAppLifecycleFacade.java
...eactnativenotifications/core/ReactAppLifecycleFacade.java
+4
-7
example/index.android.js
example/index.android.js
+32
-6
No files found.
example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/MainApplication.java
View file @
3f4bb620
...
@@ -23,7 +23,7 @@ public class MainApplication extends Application implements ReactApplication {
...
@@ -23,7 +23,7 @@ public class MainApplication extends Application implements ReactApplication {
protected
List
<
ReactPackage
>
getPackages
()
{
protected
List
<
ReactPackage
>
getPackages
()
{
return
Arrays
.
asList
(
return
Arrays
.
asList
(
new
MainReactPackage
(),
new
MainReactPackage
(),
new
RNNotificationsPackage
()
new
RNNotificationsPackage
(
MainApplication
.
this
)
);
);
}
}
};
};
...
...
example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/RNNotificationsPackage.java
View file @
3f4bb620
package
com.wix.reactnativenotifications
;
package
com.wix.reactnativenotifications
;
import
android.app.Application
;
import
com.facebook.react.ReactPackage
;
import
com.facebook.react.ReactPackage
;
import
com.facebook.react.bridge.JavaScriptModule
;
import
com.facebook.react.bridge.JavaScriptModule
;
import
com.facebook.react.bridge.NativeModule
;
import
com.facebook.react.bridge.NativeModule
;
...
@@ -13,9 +15,16 @@ import java.util.List;
...
@@ -13,9 +15,16 @@ import java.util.List;
public
class
RNNotificationsPackage
implements
ReactPackage
{
public
class
RNNotificationsPackage
implements
ReactPackage
{
final
Application
mApplication
;
public
RNNotificationsPackage
(
Application
application
)
{
mApplication
=
application
;
}
@Override
@Override
public
List
<
NativeModule
>
createNativeModules
(
ReactApplicationContext
reactContext
)
{
public
List
<
NativeModule
>
createNativeModules
(
ReactApplicationContext
reactContext
)
{
return
Arrays
.<
NativeModule
>
asList
(
new
RNNotificationsModule
(
reactContext
));
return
Arrays
.<
NativeModule
>
asList
(
new
RNNotificationsModule
(
mApplication
,
reactContext
));
}
}
@Override
@Override
...
...
example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/AppLaunchHelper.java
View file @
3f4bb620
...
@@ -34,7 +34,9 @@ public class AppLaunchHelper {
...
@@ -34,7 +34,9 @@ public class AppLaunchHelper {
public
static
boolean
isLaunchIntentsActivity
(
Activity
activity
)
{
public
static
boolean
isLaunchIntentsActivity
(
Activity
activity
)
{
final
Intent
helperIntent
=
activity
.
getPackageManager
().
getLaunchIntentForPackage
(
activity
.
getPackageName
());
final
Intent
helperIntent
=
activity
.
getPackageManager
().
getLaunchIntentForPackage
(
activity
.
getPackageName
());
return
activity
.
getLocalClassName
().
equals
(
helperIntent
.
getComponent
().
getClassName
());
final
String
activityName
=
activity
.
getComponentName
().
getClassName
();
final
String
launchIntentActivityName
=
helperIntent
.
getComponent
().
getClassName
();
return
activityName
.
equals
(
launchIntentActivityName
);
}
}
public
static
boolean
isLaunchIntent
(
Intent
intent
)
{
public
static
boolean
isLaunchIntent
(
Intent
intent
)
{
...
...
example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/INotificationsDrawerApplication.java
0 → 100644
View file @
3f4bb620
package
com.wix.reactnativenotifications.core
;
public
interface
INotificationsDrawerApplication
{
IPushNotificationsDrawer
getPushNotificationsDrawer
();
}
example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/IPushNotificationsDrawer.java
0 → 100644
View file @
3f4bb620
package
com.wix.reactnativenotifications.core
;
import
android.app.Activity
;
public
interface
IPushNotificationsDrawer
{
void
onAppInit
();
void
onAppVisible
();
void
onNewActivity
(
Activity
activity
);
void
onNotificationOpened
();
}
example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/InitialNotification.java
View file @
3f4bb620
...
@@ -9,6 +9,10 @@ public class InitialNotification {
...
@@ -9,6 +9,10 @@ public class InitialNotification {
sNotification
=
pushNotificationProps
;
sNotification
=
pushNotificationProps
;
}
}
public
static
void
clear
()
{
sNotification
=
null
;
}
@Nullable
@Nullable
public
static
PushNotificationProps
get
()
{
public
static
PushNotificationProps
get
()
{
return
sNotification
;
return
sNotification
;
...
...
example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/PushNotification.java
View file @
3f4bb620
...
@@ -58,7 +58,7 @@ public class PushNotification implements IPushNotification {
...
@@ -58,7 +58,7 @@ public class PushNotification implements IPushNotification {
@Override
@Override
public
void
onOpened
()
{
public
void
onOpened
()
{
digestNotification
();
digestNotification
();
deleteAllPostedNotifications
();
PushNotificationsDrawer
.
get
(
mContext
).
onNotificationOpened
();
}
}
@Override
@Override
...
@@ -170,9 +170,4 @@ public class PushNotification implements IPushNotification {
...
@@ -170,9 +170,4 @@ public class PushNotification implements IPushNotification {
final
Intent
intent
=
AppLaunchHelper
.
getLaunchIntent
(
mContext
);
final
Intent
intent
=
AppLaunchHelper
.
getLaunchIntent
(
mContext
);
mContext
.
startActivity
(
intent
);
mContext
.
startActivity
(
intent
);
}
}
protected
void
deleteAllPostedNotifications
()
{
final
NotificationManager
notificationManager
=
(
NotificationManager
)
mContext
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
);
notificationManager
.
cancelAll
();
}
}
}
example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/PushNotificationsDrawer.java
0 → 100644
View file @
3f4bb620
package
com.wix.reactnativenotifications.core
;
import
android.app.Activity
;
import
android.app.NotificationManager
;
import
android.content.Context
;
public
class
PushNotificationsDrawer
implements
IPushNotificationsDrawer
{
protected
final
Context
mContext
;
public
PushNotificationsDrawer
(
Context
context
)
{
mContext
=
context
;
}
public
static
IPushNotificationsDrawer
get
(
Context
context
)
{
final
Context
appContext
=
context
.
getApplicationContext
();
if
(
appContext
instanceof
INotificationsDrawerApplication
)
{
return
((
INotificationsDrawerApplication
)
appContext
).
getPushNotificationsDrawer
();
}
return
new
PushNotificationsDrawer
(
context
);
}
@Override
public
void
onAppInit
()
{
clearAll
();
}
@Override
public
void
onAppVisible
()
{
clearAll
();
}
@Override
public
void
onNewActivity
(
Activity
activity
)
{
if
(
AppLaunchHelper
.
isLaunchIntentsActivity
(
activity
)
&&
!
AppLaunchHelper
.
isLaunchIntent
(
activity
.
getIntent
()))
{
InitialNotification
.
clear
();
}
}
@Override
public
void
onNotificationOpened
()
{
clearAll
();
}
protected
void
clearAll
()
{
final
NotificationManager
notificationManager
=
(
NotificationManager
)
mContext
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
);
notificationManager
.
cancelAll
();
}
}
example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/RNNotificationsModule.java
View file @
3f4bb620
package
com.wix.reactnativenotifications.core
;
package
com.wix.reactnativenotifications.core
;
import
android.app.Activity
;
import
android.app.Application
;
import
android.content.Context
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.os.Bundle
;
import
android.util.Log
;
import
android.util.Log
;
import
com.facebook.react.bridge.Arguments
;
import
com.facebook.react.bridge.Arguments
;
...
@@ -13,12 +16,14 @@ import com.wix.reactnativenotifications.gcm.GcmInstanceIdRefreshHandlerService;
...
@@ -13,12 +16,14 @@ import com.wix.reactnativenotifications.gcm.GcmInstanceIdRefreshHandlerService;
import
static
com
.
wix
.
reactnativenotifications
.
Defs
.
LOGTAG
;
import
static
com
.
wix
.
reactnativenotifications
.
Defs
.
LOGTAG
;
public
class
RNNotificationsModule
extends
ReactContextBaseJavaModule
{
public
class
RNNotificationsModule
extends
ReactContextBaseJavaModule
implements
AppLifecycleFacade
.
AppVisibilityListener
,
Application
.
ActivityLifecycleCallbacks
{
public
RNNotificationsModule
(
ReactApplicationContext
reactContext
)
{
public
RNNotificationsModule
(
Application
application
,
ReactApplicationContext
reactContext
)
{
super
(
reactContext
);
super
(
reactContext
);
ReactAppLifecycleFacade
.
get
().
onAppInit
(
reactContext
);
ReactAppLifecycleFacade
.
get
().
init
(
reactContext
);
ReactAppLifecycleFacade
.
get
().
addVisibilityListener
(
this
);
application
.
registerActivityLifecycleCallbacks
(
this
);
}
}
@Override
@Override
...
@@ -29,14 +34,17 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule {
...
@@ -29,14 +34,17 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule {
@Override
@Override
public
void
initialize
()
{
public
void
initialize
()
{
Log
.
d
(
LOGTAG
,
"Native module init"
);
Log
.
d
(
LOGTAG
,
"Native module init"
);
startGcmIntentService
(
GcmInstanceIdRefreshHandlerService
.
EXTRA_IS_APP_INIT
);
final
Context
appContext
=
getReactApplicationContext
().
getApplicationContext
();
IPushNotificationsDrawer
notificationsDrawer
=
PushNotificationsDrawer
.
get
(
getReactApplicationContext
().
getApplicationContext
());
final
Intent
tokenFetchIntent
=
new
Intent
(
appContext
,
GcmInstanceIdRefreshHandlerService
.
class
);
notificationsDrawer
.
onAppInit
();
tokenFetchIntent
.
putExtra
(
GcmInstanceIdRefreshHandlerService
.
EXTRA_IS_APP_INIT
,
true
);
appContext
.
startService
(
tokenFetchIntent
);
}
}
@ReactMethod
public
void
refreshToken
()
{
Log
.
d
(
LOGTAG
,
"Native method invocation: refreshToken()"
);
startGcmIntentService
(
GcmInstanceIdRefreshHandlerService
.
EXTRA_MANUAL_REFRESH
);
}
@ReactMethod
@ReactMethod
public
void
getInitialNotification
(
final
Promise
promise
)
{
public
void
getInitialNotification
(
final
Promise
promise
)
{
...
@@ -55,13 +63,50 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule {
...
@@ -55,13 +63,50 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule {
}
}
}
}
@ReactMethod
@Override
public
void
refreshToken
()
{
public
void
onAppVisible
()
{
Log
.
d
(
LOGTAG
,
"Native method invocation: refreshToken()"
);
IPushNotificationsDrawer
notificationsDrawer
=
PushNotificationsDrawer
.
get
(
getReactApplicationContext
().
getApplicationContext
());
notificationsDrawer
.
onAppVisible
();
}
@Override
public
void
onAppNotVisible
()
{
}
@Override
public
void
onActivityCreated
(
Activity
activity
,
Bundle
savedInstanceState
)
{
IPushNotificationsDrawer
notificationsDrawer
=
PushNotificationsDrawer
.
get
(
getReactApplicationContext
().
getApplicationContext
());
notificationsDrawer
.
onNewActivity
(
activity
);
}
@Override
public
void
onActivityStarted
(
Activity
activity
)
{
}
@Override
public
void
onActivityResumed
(
Activity
activity
)
{
}
@Override
public
void
onActivityPaused
(
Activity
activity
)
{
}
@Override
public
void
onActivityStopped
(
Activity
activity
)
{
}
@Override
public
void
onActivitySaveInstanceState
(
Activity
activity
,
Bundle
outState
)
{
}
@Override
public
void
onActivityDestroyed
(
Activity
activity
)
{
}
protected
void
startGcmIntentService
(
String
extraFlag
)
{
final
Context
appContext
=
getReactApplicationContext
().
getApplicationContext
();
final
Context
appContext
=
getReactApplicationContext
().
getApplicationContext
();
final
Intent
tokenFetchIntent
=
new
Intent
(
appContext
,
GcmInstanceIdRefreshHandlerService
.
class
);
final
Intent
tokenFetchIntent
=
new
Intent
(
appContext
,
GcmInstanceIdRefreshHandlerService
.
class
);
tokenFetchIntent
.
putExtra
(
GcmInstanceIdRefreshHandlerService
.
EXTRA_MANUAL_REFRESH
,
true
);
tokenFetchIntent
.
putExtra
(
extraFlag
,
true
);
appContext
.
startService
(
tokenFetchIntent
);
appContext
.
startService
(
tokenFetchIntent
);
}
}
}
}
example/android/reactnativenotification/src/main/java/com/wix/reactnativenotifications/core/ReactAppLifecycleFacade.java
View file @
3f4bb620
...
@@ -12,7 +12,7 @@ import static com.wix.reactnativenotifications.Defs.LOGTAG;
...
@@ -12,7 +12,7 @@ import static com.wix.reactnativenotifications.Defs.LOGTAG;
public
class
ReactAppLifecycleFacade
implements
AppLifecycleFacade
{
public
class
ReactAppLifecycleFacade
implements
AppLifecycleFacade
{
private
static
ReactAppLifecycleFacade
sInstance
=
new
ReactAppLifecycleFacade
();
private
static
final
ReactAppLifecycleFacade
sInstance
=
new
ReactAppLifecycleFacade
();
private
ReactContext
mReactContext
;
private
ReactContext
mReactContext
;
private
boolean
mIsVisible
;
private
boolean
mIsVisible
;
...
@@ -22,10 +22,8 @@ public class ReactAppLifecycleFacade implements AppLifecycleFacade {
...
@@ -22,10 +22,8 @@ public class ReactAppLifecycleFacade implements AppLifecycleFacade {
return
sInstance
;
return
sInstance
;
}
}
public
synchronized
void
onAppI
nit
(
ReactContext
reactContext
)
{
public
void
i
nit
(
ReactContext
reactContext
)
{
mReactContext
=
reactContext
;
mReactContext
=
reactContext
;
mIsVisible
=
false
;
reactContext
.
addLifecycleEventListener
(
new
LifecycleEventListener
()
{
reactContext
.
addLifecycleEventListener
(
new
LifecycleEventListener
()
{
@Override
@Override
public
void
onHostResume
()
{
public
void
onHostResume
()
{
...
@@ -35,15 +33,14 @@ public class ReactAppLifecycleFacade implements AppLifecycleFacade {
...
@@ -35,15 +33,14 @@ public class ReactAppLifecycleFacade implements AppLifecycleFacade {
@Override
@Override
public
void
onHostPause
()
{
public
void
onHostPause
()
{
Log
.
d
(
LOGTAG
,
"onHostPause"
);
switchToInvisible
();
switchToInvisible
();
}
}
@Override
@Override
public
void
onHostDestroy
()
{
public
void
onHostDestroy
()
{
switchToInvisible
();
Log
.
d
(
LOGTAG
,
"onHostDestroy"
);
Log
.
d
(
LOGTAG
,
"onHostDestroy"
);
mReactContext
.
removeLifecycleEventListener
(
this
);
switchToInvisible
();
mReactContext
=
null
;
}
}
});
});
}
}
...
...
example/index.android.js
View file @
3f4bb620
...
@@ -11,6 +11,30 @@ import {
...
@@ -11,6 +11,30 @@ import {
import
{
NotificationsAndroid
,
PendingNotifications
}
from
'
./notifications
'
;
import
{
NotificationsAndroid
,
PendingNotifications
}
from
'
./notifications
'
;
let
mainScreen
;
function
onPushRegistered
()
{
if
(
mainScreen
)
{
mainScreen
.
onPushRegistered
();
}
}
function
onNotificationOpened
(
notification
)
{
if
(
mainScreen
)
{
mainScreen
.
onNotificationOpened
(
notification
)
}
}
function
onNotificationReceived
(
notification
)
{
if
(
mainScreen
)
{
mainScreen
.
onNotificationReceived
(
notification
)
}
}
NotificationsAndroid
.
setRegistrationTokenUpdateListener
(
onPushRegistered
);
NotificationsAndroid
.
setNotificationOpenedListener
(
onNotificationOpened
);
NotificationsAndroid
.
setNotificationReceivedListener
(
onNotificationReceived
);
const
styles
=
StyleSheet
.
create
({
const
styles
=
StyleSheet
.
create
({
container
:
{
container
:
{
flex
:
1
,
flex
:
1
,
...
@@ -36,22 +60,24 @@ class MainComponent extends Component {
...
@@ -36,22 +60,24 @@ class MainComponent extends Component {
this
.
state
=
{
this
.
state
=
{
elapsed
:
0
,
elapsed
:
0
,
lastNotification
:
undefined
lastNotification
:
undefined
}
};
}
componentWillMount
()
{
console
.
log
(
'
ReactScreen
'
,
'
ReactScreen
'
);
NotificationsAndroid
.
setRegistrationTokenUpdateListener
(
this
.
onPushRegistered
.
bind
(
this
));
mainScreen
=
this
;
NotificationsAndroid
.
setNotificationOpenedListener
(
this
.
onNotificationOpened
.
bind
(
this
));
NotificationsAndroid
.
setNotificationReceivedListener
(
this
.
onNotificationReceived
.
bind
(
this
));
}
}
componentDidMount
()
{
componentDidMount
()
{
console
.
log
(
'
ReactScreen
'
,
'
componentDidMount
'
);
setInterval
(
this
.
onTick
.
bind
(
this
),
1000
);
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
));
}
}
componentWillUnmount
()
{
console
.
log
(
'
ReactScreen
'
,
'
componentWillUnmount
'
);
}
onTick
()
{
onTick
()
{
this
.
setState
({
elapsed
:
this
.
state
.
elapsed
+
1
});
this
.
setState
({
elapsed
:
this
.
state
.
elapsed
+
1
});
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment