Created
April 18, 2024 10:28
-
-
Save ilight/be7141f45f15e39b6fccfe46ca6e3829 to your computer and use it in GitHub Desktop.
Patch to wix's react-native-notifications 5.1.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/node_modules/react-native-notifications/android/app/src/reactNative59/java/com/wix/reactnativenotifications/NotificationManagerCompatFacade.java b/node_modules/react-native-notifications/android/app/src/reactNative59/java/com/wix/reactnativenotifications/NotificationManagerCompatFacade.java | |
index f9c858b..94ea188 100644 | |
--- a/node_modules/react-native-notifications/android/app/src/reactNative59/java/com/wix/reactnativenotifications/NotificationManagerCompatFacade.java | |
+++ b/node_modules/react-native-notifications/android/app/src/reactNative59/java/com/wix/reactnativenotifications/NotificationManagerCompatFacade.java | |
@@ -2,8 +2,8 @@ | |
package com.wix.reactnativenotifications; | |
import android.content.Context; | |
-import android.support.annotation.NonNull; | |
-import android.support.v4.app.NotificationManagerCompat; | |
+import androidx.annotation.NonNull; | |
+import androidx.core.app.NotificationManagerCompat; | |
public abstract class NotificationManagerCompatFacade { | |
public static NotificationManagerCompat from(@NonNull Context context) { | |
diff --git a/node_modules/react-native-notifications/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java b/node_modules/react-native-notifications/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java | |
index 90969b2..4c00e69 100644 | |
--- a/node_modules/react-native-notifications/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java | |
+++ b/node_modules/react-native-notifications/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java | |
@@ -63,7 +63,7 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule implements | |
@Override | |
public void onNewIntent(Intent intent) { | |
if (NotificationIntentAdapter.canHandleIntent(intent)) { | |
- Bundle notificationData = intent.getExtras(); | |
+ Bundle notificationData = NotificationIntentAdapter.extractPendingNotificationDataFromIntent(intent); | |
final IPushNotification notification = PushNotification.get(getReactApplicationContext().getApplicationContext(), notificationData); | |
if (notification != null) { | |
notification.onOpened(); | |
diff --git a/node_modules/react-native-notifications/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsPackage.java b/node_modules/react-native-notifications/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsPackage.java | |
index 5b7f15f..7b3ee7e 100644 | |
--- a/node_modules/react-native-notifications/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsPackage.java | |
+++ b/node_modules/react-native-notifications/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsPackage.java | |
@@ -15,6 +15,7 @@ import com.wix.reactnativenotifications.core.AppLifecycleFacade; | |
import com.wix.reactnativenotifications.core.AppLifecycleFacadeHolder; | |
import com.wix.reactnativenotifications.core.InitialNotificationHolder; | |
import com.wix.reactnativenotifications.core.NotificationIntentAdapter; | |
+import com.wix.reactnativenotifications.core.ReactAppLifecycleFacade; | |
import com.wix.reactnativenotifications.core.notification.IPushNotification; | |
import com.wix.reactnativenotifications.core.notification.PushNotification; | |
import com.wix.reactnativenotifications.core.notificationdrawer.IPushNotificationsDrawer; | |
@@ -66,7 +67,12 @@ public class RNNotificationsPackage implements ReactPackage, AppLifecycleFacade. | |
@Override | |
public void onActivityStarted(Activity activity) { | |
- if (InitialNotificationHolder.getInstance().get() == null) { | |
+ boolean isReactInitialized = false; | |
+ if (AppLifecycleFacadeHolder.get() instanceof ReactAppLifecycleFacade) { | |
+ isReactInitialized = AppLifecycleFacadeHolder.get().isReactInitialized(); | |
+ } | |
+ | |
+ if (InitialNotificationHolder.getInstance().get() == null && !isReactInitialized) { | |
callOnOpenedIfNeed(activity); | |
} | |
} | |
diff --git a/node_modules/react-native-notifications/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/NotificationIntentAdapter.java b/node_modules/react-native-notifications/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/NotificationIntentAdapter.java | |
index 1e7e871..62e5cb8 100644 | |
--- a/node_modules/react-native-notifications/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/NotificationIntentAdapter.java | |
+++ b/node_modules/react-native-notifications/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/NotificationIntentAdapter.java | |
@@ -14,17 +14,9 @@ public class NotificationIntentAdapter { | |
@SuppressLint("UnspecifiedImmutableFlag") | |
public static PendingIntent createPendingNotificationIntent(Context appContext, PushNotificationProps notification) { | |
- if (canHandleTrampolineActivity(appContext)) { | |
- Intent intent = new Intent(appContext, ProxyService.class); | |
- intent.putExtra(PUSH_NOTIFICATION_EXTRA_NAME, notification.asBundle()); | |
- return PendingIntent.getService(appContext, (int) System.currentTimeMillis(), intent, PendingIntent.FLAG_ONE_SHOT); | |
- } else { | |
- Intent mainActivityIntent = appContext.getPackageManager().getLaunchIntentForPackage(appContext.getPackageName()); | |
- mainActivityIntent.putExtra(PUSH_NOTIFICATION_EXTRA_NAME, notification.asBundle()); | |
- TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(appContext); | |
- taskStackBuilder.addNextIntentWithParentStack(mainActivityIntent); | |
- return taskStackBuilder.getPendingIntent((int) System.currentTimeMillis(), PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE); | |
- } | |
+ Intent intent = appContext.getPackageManager().getLaunchIntentForPackage(appContext.getPackageName()); | |
+ intent.putExtra(PUSH_NOTIFICATION_EXTRA_NAME, notification.asBundle()); | |
+ return PendingIntent.getActivity(appContext, (int) System.currentTimeMillis(), intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE); | |
} | |
public static boolean canHandleTrampolineActivity(Context appContext) { | |
diff --git a/node_modules/react-native-notifications/lib/android/app/src/reactNative59/java/com/wix/reactnativenotifications/NotificationManagerCompatFacade.java b/node_modules/react-native-notifications/lib/android/app/src/reactNative59/java/com/wix/reactnativenotifications/NotificationManagerCompatFacade.java | |
index f9c858b..94ea188 100644 | |
--- a/node_modules/react-native-notifications/lib/android/app/src/reactNative59/java/com/wix/reactnativenotifications/NotificationManagerCompatFacade.java | |
+++ b/node_modules/react-native-notifications/lib/android/app/src/reactNative59/java/com/wix/reactnativenotifications/NotificationManagerCompatFacade.java | |
@@ -2,8 +2,8 @@ | |
package com.wix.reactnativenotifications; | |
import android.content.Context; | |
-import android.support.annotation.NonNull; | |
-import android.support.v4.app.NotificationManagerCompat; | |
+import androidx.annotation.NonNull; | |
+import androidx.core.app.NotificationManagerCompat; | |
public abstract class NotificationManagerCompatFacade { | |
public static NotificationManagerCompat from(@NonNull Context context) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This patch was inspired from a 4.3.3 patch available online. When I upgraded to react-native-notifications v5.1.0, I deleted the 4.3.3 patch. The issue I faced without this patch was