Skip to content

Commit 5107ee0

Browse files
DanielElirazelliscwc
authored andcommitted
Fix trampoline on target sdk 31 (wix#837)
* bump to rn 67 in example * restrict trampoline fix to targetSdk 31 and above
1 parent 9a144ab commit 5107ee0

File tree

8 files changed

+48
-25
lines changed

8 files changed

+48
-25
lines changed

example/android/build.gradle

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,37 @@
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
mavenLocal()
1414
mavenCentral()
1515
jcenter()
1616
}
1717
dependencies {
18-
classpath "com.android.tools.build:gradle:4.0.2"
18+
classpath "com.android.tools.build:gradle:4.2.2"
1919
classpath "com.google.gms:google-services:4.3.3"
2020
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
2121
}
2222
}
2323

2424
allprojects {
2525
repositories {
26-
mavenLocal()
27-
mavenCentral()
28-
google()
29-
jcenter()
30-
maven {
31-
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
32-
url "$rootDir/../../node_modules/react-native/android"
26+
maven { url "$rootDir/../../node_modules/react-native/android" }
27+
maven { url "$rootDir/../../node_modules/jsc-android/dist" }
28+
mavenCentral {
29+
content {
30+
excludeGroup "com.facebook.react"
31+
}
3332
}
33+
google()
34+
maven { url 'https://www.jitpack.io' }
3435
}
3536
}
3637

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.1.1-all.zip
5+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip

example/android/myapplication/build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ project.ext.react = [
99
enableHermes : true,
1010
bundleInAlpha : true,
1111
bundleInBeta : true,
12-
hermesFlagsDebug:['-Xes6-proxy'],
13-
hermesFlagsRelease:['-Xes6-proxy']
12+
hermesFlagsDebug:['-Xes6-proxy','-output-source-map'],
13+
hermesFlagsRelease:['-output-source-map'],
14+
hermesCommand: "../../../node_modules/hermes-engine/%OS-BIN%/hermesc",
1415
]
1516

1617
apply from: "../../../node_modules/react-native/react.gradle"
@@ -59,11 +60,10 @@ android {
5960

6061
dependencies {
6162
implementation fileTree(dir: 'libs', include: ['*.jar'])
63+
//noinspection GradleDynamicVersion
64+
implementation "com.facebook.react:react-native:+"
65+
6266
def hermesPath = "../../../node_modules/hermes-engine/android/";
63-
exec {
64-
executable 'grep'
65-
args "version", '../../../node_modules/hermes-engine/package.json'
66-
}
6767
debugImplementation files(hermesPath + "hermes-debug.aar")
6868
releaseImplementation files(hermesPath + "hermes-release.aar")
6969
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(0, 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: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,23 @@
7171
"@babel/plugin-proposal-export-default-from": "7.2.0",
7272
"@babel/plugin-proposal-export-namespace-from": "7.2.0",
7373
"@types/jest": "24.9.0",
74-
"@types/lodash": "4.14.170"
74+
"@types/lodash": "4.14.170",
75+
"@types/react": "16.9.35",
76+
"@types/react-native": "0.67.1",
77+
"@types/react-test-renderer": "16.9.2",
78+
"babel-eslint": "10.0.3",
79+
"detox": "^19.4.2",
80+
"github-release-notes": "https://github.com/yogevbd/github-release-notes/tarball/e601b3dba72dcd6cba323c1286ea6dd0c0110b58",
81+
"jest": "24.9.0",
82+
"lodash": "4.17.21",
83+
"metro-react-native-babel-preset": "0.66.2",
84+
"react": "17.0.2",
85+
"react-autobind": "1.0.6",
86+
"react-native": "0.67.3",
87+
"shell-utils": "1.0.10",
88+
"ts-mockito": "2.5.0",
89+
"tslint": "6.1.2",
90+
"typescript": "^3.7.5"
7591
},
7692
"publishConfig": {
7793
"registry": "https://registry.npmjs.org/"

0 commit comments

Comments
 (0)