Skip to content

Commit c4e6fa0

Browse files
authored
Fix trampoline on target sdk 31 (#837)
* bump to rn 67 in example * restrict trampoline fix to targetSdk 31 and above
1 parent 0189089 commit c4e6fa0

File tree

8 files changed

+29
-23
lines changed

8 files changed

+29
-23
lines changed

example/android/build.gradle

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4-
ext{
5-
androidSdkVersion = 31
4+
ext {
5+
androidSdkVersion = 30
66
androidMinSdkVersion = 21
77
kotlinVersion = "1.3.61"
88
kotlinStdlib = "kotlin-stdlib-jdk8"
99
detoxKotlinVersion = kotlinVersion
10-
}
10+
}
1111
repositories {
1212
google()
1313
mavenCentral()
1414
}
1515
dependencies {
16-
classpath "com.android.tools.build:gradle:4.0.2"
16+
classpath "com.android.tools.build:gradle:4.2.2"
1717
classpath "com.google.gms:google-services:4.3.3"
1818
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
1919
}
2020
}
2121

2222
allprojects {
2323
repositories {
24-
mavenLocal()
25-
mavenCentral()
26-
google()
27-
maven {
28-
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
29-
url "$rootDir/../../node_modules/react-native/android"
30-
}
24+
maven { url "$rootDir/../../node_modules/react-native/android" }
3125
maven { url "$rootDir/../../node_modules/jsc-android/dist" }
26+
mavenCentral {
27+
content {
28+
excludeGroup "com.facebook.react"
29+
}
30+
}
31+
google()
3232
maven { url 'https://www.jitpack.io' }
3333
}
3434
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#Thu Dec 12 22:59:18 IST 2019
21
distributionBase=GRADLE_USER_HOME
32
distributionPath=wrapper/dists
43
zipStoreBase=GRADLE_USER_HOME
54
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-all.zip
5+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip

example/android/myapplication/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ project.ext.react = [
1212
bundleInBeta : true,
1313
hermesFlagsDebug:['-Xes6-proxy','-output-source-map'],
1414
hermesFlagsRelease:['-output-source-map'],
15-
hermesCommand: "../../../node_modules/react-native/node_modules/hermes-engine/%OS-BIN%/hermesc",
15+
hermesCommand: "../../../node_modules/hermes-engine/%OS-BIN%/hermesc",
1616
]
1717

1818
apply from: "../../../node_modules/react-native/react.gradle"
@@ -51,7 +51,7 @@ dependencies {
5151
//noinspection GradleDynamicVersion
5252
implementation "com.facebook.react:react-native:+"
5353

54-
def hermesPath = "../../../node_modules/react-native/node_modules/hermes-engine/android/";
54+
def hermesPath = "../../../node_modules/hermes-engine/android/";
5555
debugImplementation files(hermesPath + "hermes-debug.aar")
5656
releaseImplementation files(hermesPath + "hermes-release.aar")
5757
implementation "org.jetbrains.kotlin:$kotlinStdlib:$kotlinVersion"

example/android/settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
rootProject.name = 'NotificationsExampleApp'
12
include ':myapplication'
23

34
include ':react-native-notifications'

lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsPackage.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.app.Activity;
44
import android.app.Application;
5+
import android.content.Context;
56
import android.content.Intent;
67
import android.os.Bundle;
78

@@ -94,9 +95,10 @@ public void onActivityDestroyed(Activity activity) {
9495
private void callOnOpenedIfNeed(Activity activity) {
9596
Intent intent = activity.getIntent();
9697
if (NotificationIntentAdapter.canHandleIntent(intent)) {
97-
Bundle notificationData = android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R ?
98+
Context appContext = mApplication.getApplicationContext();
99+
Bundle notificationData = NotificationIntentAdapter.cannotHandleTrampolineActivity(appContext) ?
98100
NotificationIntentAdapter.extractPendingNotificationDataFromIntent(intent) : intent.getExtras();
99-
final IPushNotification pushNotification = PushNotification.get(mApplication.getApplicationContext(), notificationData);
101+
final IPushNotification pushNotification = PushNotification.get(appContext, notificationData);
100102
if (pushNotification != null) {
101103
pushNotification.onOpened();
102104
}

lib/android/app/src/main/java/com/wix/reactnativenotifications/core/NotificationIntentAdapter.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,23 @@ public class NotificationIntentAdapter {
1414

1515
@SuppressLint("UnspecifiedImmutableFlag")
1616
public static PendingIntent createPendingNotificationIntent(Context appContext, PushNotificationProps notification) {
17-
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {
17+
if (cannotHandleTrampolineActivity(appContext)) {
1818
Intent mainActivityIntent = appContext.getPackageManager().getLaunchIntentForPackage(appContext.getPackageName());
1919
mainActivityIntent.putExtra(PUSH_NOTIFICATION_EXTRA_NAME, notification.asBundle());
2020
TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(appContext);
2121
taskStackBuilder.addNextIntentWithParentStack(mainActivityIntent);
22-
return taskStackBuilder.getPendingIntent((int) System.currentTimeMillis(), PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE);
22+
return taskStackBuilder.getPendingIntent((int) System.currentTimeMillis(), PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE);
2323
} else {
2424
Intent intent = new Intent(appContext, ProxyService.class);
2525
intent.putExtra(PUSH_NOTIFICATION_EXTRA_NAME, notification.asBundle());
2626
return PendingIntent.getService(appContext, (int) System.currentTimeMillis(), intent, PendingIntent.FLAG_ONE_SHOT);
2727
}
2828
}
2929

30+
public static boolean cannotHandleTrampolineActivity(Context appContext) {
31+
return android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R && appContext.getApplicationInfo().targetSdkVersion >= 31;
32+
}
33+
3034
public static Bundle extractPendingNotificationDataFromIntent(Intent intent) {
3135
return intent.getBundleExtra(PUSH_NOTIFICATION_EXTRA_NAME);
3236
}

lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ private void notifyOpenedToJS() {
213213
}
214214

215215
protected void launchOrResumeApp() {
216-
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.R) {
216+
if (!NotificationIntentAdapter.cannotHandleTrampolineActivity(mContext)) {
217217
final Intent intent = mAppLaunchHelper.getLaunchIntent(mContext);
218218
mContext.startActivity(intent);
219219
}

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"@types/jest": "24.9.0",
5555
"@types/lodash": "4.14.170",
5656
"@types/react": "16.9.35",
57-
"@types/react-native": "0.66.12",
57+
"@types/react-native": "0.67.1",
5858
"@types/react-test-renderer": "16.9.2",
5959
"babel-eslint": "10.0.3",
6060
"detox": "^19.4.2",
@@ -64,7 +64,7 @@
6464
"metro-react-native-babel-preset": "0.66.2",
6565
"react": "17.0.2",
6666
"react-autobind": "1.0.6",
67-
"react-native": "0.66.3",
67+
"react-native": "0.67.3",
6868
"shell-utils": "1.0.10",
6969
"ts-mockito": "2.5.0",
7070
"tslint": "6.1.2",
@@ -131,4 +131,4 @@
131131
"html"
132132
]
133133
}
134-
}
134+
}

0 commit comments

Comments
 (0)