Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit d1dd76c

Browse files
committed
Cleanup Event listener.
Initialize Fresco only when required and avoid crash if not initialized.
1 parent 8372c5f commit d1dd76c

File tree

8 files changed

+35
-10
lines changed

8 files changed

+35
-10
lines changed

android/.classpath

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
4+
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
5+
<classpathentry kind="output" path="bin/default"/>
6+
</classpath>

android/.project

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@
55
<projects>
66
</projects>
77
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
813
<buildCommand>
914
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
1015
<arguments>
1116
</arguments>
1217
</buildCommand>
1318
</buildSpec>
1419
<natures>
20+
<nature>org.eclipse.jdt.core.javanature</nature>
1521
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
1622
</natures>
1723
</projectDescription>

android/.settings/org.eclipse.buildship.core.prefs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
arguments=
22
auto.sync=false
33
build.scans.enabled=false
4-
connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(6.3))
4+
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
55
connection.project.dir=
66
eclipse.preferences.version=1
77
gradle.user.home=

android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationListenerService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void onNewToken(String token) {
2929
handler.post(new Runnable() {
3030
public void run() {
3131
// Construct and load our normal React JS code bundle
32-
ReactInstanceManager mReactInstanceManager = ((ReactApplication) getApplication()).getReactNativeHost().getReactInstanceManager();
32+
final ReactInstanceManager mReactInstanceManager = ((ReactApplication) getApplication()).getReactNativeHost().getReactInstanceManager();
3333
ReactContext context = mReactInstanceManager.getCurrentReactContext();
3434
// If it's constructed, send a notification
3535
if (context != null) {
@@ -39,6 +39,7 @@ public void run() {
3939
mReactInstanceManager.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {
4040
public void onReactContextInitialized(ReactContext context) {
4141
handleNewToken((ReactApplicationContext) context, deviceToken);
42+
mReactInstanceManager.removeReactInstanceEventListener(this);
4243
}
4344
});
4445
if (!mReactInstanceManager.hasStartedCreatingInitialContext()) {

android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationPicturesAggregator.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,9 @@ interface Callback {
3030
private Bitmap largeIconImage;
3131
private Bitmap bigPictureImage;
3232

33-
private ImagePipeline imagePipeline;
34-
3533
private Callback callback;
3634

3735
public RNPushNotificationPicturesAggregator(Callback callback) {
38-
this.imagePipeline = Fresco.getImagePipeline();
39-
4036
this.callback = callback;
4137
}
4238

@@ -119,7 +115,11 @@ private void downloadRequest(Context context, Uri uri, BaseBitmapDataSubscriber
119115
.setLowestPermittedRequestLevel(ImageRequest.RequestLevel.FULL_FETCH)
120116
.build();
121117

122-
DataSource<CloseableReference<CloseableImage>> dataSource = this.imagePipeline.fetchDecodedImage(imageRequest, context);
118+
if(!Fresco.hasBeenInitialized()) {
119+
Fresco.initialize(context);
120+
}
121+
122+
DataSource<CloseableReference<CloseableImage>> dataSource = Fresco.getImagePipeline().fetchDecodedImage(imageRequest, context);
123123

124124
dataSource.subscribe(subscriber, CallerThreadExecutor.getInstance());
125125
}

android/src/main/java/com/dieam/reactnativepushnotification/modules/RNReceivedMessageHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public void handleReceivedMessage(RemoteMessage message) {
9191
handler.post(new Runnable() {
9292
public void run() {
9393
// Construct and load our normal React JS code bundle
94-
ReactInstanceManager mReactInstanceManager = ((ReactApplication) mFirebaseMessagingService.getApplication()).getReactNativeHost().getReactInstanceManager();
94+
final ReactInstanceManager mReactInstanceManager = ((ReactApplication) mFirebaseMessagingService.getApplication()).getReactNativeHost().getReactInstanceManager();
9595
ReactContext context = mReactInstanceManager.getCurrentReactContext();
9696
// If it's constructed, send a notificationre
9797
if (context != null) {
@@ -101,6 +101,7 @@ public void run() {
101101
mReactInstanceManager.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {
102102
public void onReactContextInitialized(ReactContext context) {
103103
handleRemotePushNotification((ReactApplicationContext) context, bundle);
104+
mReactInstanceManager.removeReactInstanceEventListener(this);
104105
}
105106
});
106107
if (!mReactInstanceManager.hasStartedCreatingInitialContext()) {

example/android/.settings/org.eclipse.buildship.core.prefs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ arguments=
22
auto.sync=false
33
build.scans.enabled=false
44
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
5-
connection.project.dir=
5+
connection.project.dir=app
66
eclipse.preferences.version=1
77
gradle.user.home=
88
java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
1-
connection.project.dir=..
1+
arguments=
2+
auto.sync=false
3+
build.scans.enabled=false
4+
connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(6.3))
5+
connection.project.dir=
26
eclipse.preferences.version=1
7+
gradle.user.home=
8+
java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
9+
jvm.arguments=
10+
offline.mode=false
11+
override.workspace.settings=true
12+
show.console.view=true
13+
show.executions.view=true

0 commit comments

Comments
 (0)