Commit 0fdabd3e authored by Yogev Ben David's avatar Yogev Ben David Committed by GitHub

React Native 0.60 Support (#375)

* Add react-native@0.60.* support

* Change variant name

* Update installation docs

* Fix example project

* Update installation.md
parent 71607f71
...@@ -16,6 +16,9 @@ android { ...@@ -16,6 +16,9 @@ android {
minifyEnabled false minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
} }
debug {
debuggable true
}
} }
testOptions { testOptions {
unitTests.all { t -> unitTests.all { t ->
...@@ -36,6 +39,16 @@ android { ...@@ -36,6 +39,16 @@ android {
} }
} }
} }
flavorDimensions "RNNotifications.reactNativeVersion"
productFlavors {
reactNative59 {
dimension "RNNotifications.reactNativeVersion"
}
reactNative60 {
dimension "RNNotifications.reactNativeVersion"
}
}
} }
dependencies { dependencies {
......
...@@ -5,7 +5,6 @@ import android.app.Application; ...@@ -5,7 +5,6 @@ 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.os.Bundle;
import android.support.v4.app.NotificationManagerCompat;
import android.util.Log; import android.util.Log;
import com.facebook.react.bridge.ActivityEventListener; import com.facebook.react.bridge.ActivityEventListener;
...@@ -108,7 +107,7 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule implements ...@@ -108,7 +107,7 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule implements
@ReactMethod @ReactMethod
public void isRegisteredForRemoteNotifications(Promise promise) { public void isRegisteredForRemoteNotifications(Promise promise) {
boolean hasPermission = NotificationManagerCompat.from(getReactApplicationContext()).areNotificationsEnabled(); boolean hasPermission = NotificationManagerCompatFacade.from(getReactApplicationContext()).areNotificationsEnabled();
promise.resolve(new Boolean(hasPermission)); promise.resolve(new Boolean(hasPermission));
} }
......
package com.wix.reactnativenotifications.core; package com.wix.reactnativenotifications.core;
import android.support.annotation.Nullable;
import com.wix.reactnativenotifications.core.notification.PushNotificationProps; import com.wix.reactnativenotifications.core.notification.PushNotificationProps;
...@@ -32,7 +31,6 @@ public class InitialNotificationHolder { ...@@ -32,7 +31,6 @@ public class InitialNotificationHolder {
mNotification = null; mNotification = null;
} }
@Nullable
public PushNotificationProps get() { public PushNotificationProps get() {
return mNotification; return mNotification;
} }
......
package com.wix.reactnativenotifications;
import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v4.app.NotificationManagerCompat;
public abstract class NotificationManagerCompatFacade {
public static NotificationManagerCompat from(@NonNull Context context) {
return NotificationManagerCompat.from(context);
}
}
package com.wix.reactnativenotifications;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.core.app.NotificationManagerCompat;
public abstract class NotificationManagerCompatFacade {
public static NotificationManagerCompat from(@NonNull Context context) {
return NotificationManagerCompat.from(context);
}
}
...@@ -119,3 +119,68 @@ dependencies { ...@@ -119,3 +119,68 @@ dependencies {
apply plugin: 'com.google.gms.google-services' apply plugin: 'com.google.gms.google-services'
``` ```
#### Step #5: RNNotifications and React Native version
<B>This step is required only for `react-native-notifications` version `3.1.0` and above.</B> <Br>
react-native-notifications supports multiple React Native versions. Target the React Native version required by your project by specifying the RNN build flavor in `android/app/build.gradle`.
```diff
android {
...
defaultConfig {
applicationId "com.yourproject"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
+ missingDimensionStrategy "RNNotifications.reactNativeVersion", "reactNative60" // See note below!
versionCode 1
versionName "1.0"
...
}
...
}
```
!>Important note about `missingDimensionStrategy`<Br>
>`reactNative59` - RN 0.59.x and below<Br>
>`reactNative60` - RN 0.60.0 and above
Now we need to instruct gradle how to build that flavor. To do so here two solutions:
#### 5.1 Build app with gradle command
**prefered solution** The RNNotification flavor you would like to build is specified in `app/build.gradle`. Therefore in order to compile only that flavor, instead of building your entire project using `./gradlew assembleDebug`, you should instruct gradle to build the app module: `./gradlew app:assembleDebug`. The easiest way is to add a package.json command to build and install your debug Android APK .
```
"scripts": {
...
"android": "cd ./android && ./gradlew app:assembleDebug && ./gradlew installDebug"
}
```
Now run `npm run android` to build your application
#### 5.2 Ignore other RNN flavors
If you don't want to run `npm run android` and want to keep the default `react-native run-android` command, you need to specify to graddle to ignore the other flavors RNNotifications provides.
To do so edit `android/build.gradle` and add:
```diff
+subprojects { subproject ->
+ afterEvaluate {
+ if ((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {
+ android {
+ variantFilter { variant ->
+ def names = variant.flavors*.name
+ if (names.contains("reactNative59")) {
+ setIgnore(true)
+ }
+ }
+ }
+ }
+ }
+}
```
**Note**: As more build variants come available in the future, you will need to adjust the list (`names.contains("reactNative59")`). This is why we recommend the first solution.
\ No newline at end of file
...@@ -15,4 +15,7 @@ ...@@ -15,4 +15,7 @@
# When configured, Gradle will run in incubating parallel mode. # When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit # This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true # org.gradle.parallel=true
\ No newline at end of file
android.useAndroidX=true
android.enableJetifier=true
\ No newline at end of file
...@@ -24,6 +24,7 @@ android { ...@@ -24,6 +24,7 @@ android {
ndk { ndk {
abiFilters "armeabi-v7a", "x86" abiFilters "armeabi-v7a", "x86"
} }
missingDimensionStrategy "RNNotifications.reactNativeVersion", "reactNative60"
} }
buildTypes { buildTypes {
release { release {
...@@ -35,17 +36,13 @@ android { ...@@ -35,17 +36,13 @@ android {
sourceCompatibility 1.8 sourceCompatibility 1.8
targetCompatibility 1.8 targetCompatibility 1.8
} }
} packagingOptions {
pickFirst '**/libjsc.so'
configurations.all { pickFirst '**/libc++_shared.so'
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
details.useVersion "28.0.0"
}
} }
} }
configurations.all { configurations.all {
resolutionStrategy { resolutionStrategy {
force 'org.webkit:android-jsc:r236355' force 'org.webkit:android-jsc:r236355'
...@@ -53,12 +50,12 @@ configurations.all { ...@@ -53,12 +50,12 @@ configurations.all {
} }
dependencies { dependencies {
// compile fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.firebase:firebase-core:16.0.0' implementation 'com.google.firebase:firebase-core:16.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.android.support:design:28.0.0'
implementation 'com.facebook.react:react-native:+' implementation 'com.facebook.react:react-native:+'
implementation 'org.webkit:android-jsc-intl:+'
implementation project(':react-native-notifications') implementation project(':react-native-notifications')
testImplementation'junit:junit:4.12' testImplementation'junit:junit:4.12'
......
package com.wix.reactnativenotifications.app; package com.wix.reactnativenotifications.app;
import android.os.Build;
import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.Toolbar;
import com.facebook.react.ReactActivity; import com.facebook.react.ReactActivity;
import com.facebook.react.ReactRootView;
import static android.os.Build.VERSION.SDK_INT;
public class MainActivity extends ReactActivity { public class MainActivity extends ReactActivity {
private ReactRootView mReactRootView;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected String getMainComponentName() {
super.onCreate(savedInstanceState); return "WixRNNotifications";
ViewGroup layout;
if (SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
layout = (ViewGroup) getLayoutInflater().inflate(R.layout.activity_main, null);
Toolbar toolbar = layout.findViewById(R.id.toolbar);
setActionBar(toolbar);
} else {
layout = (ViewGroup) getLayoutInflater().inflate(R.layout.activity_main_prelollipop, null);
}
mReactRootView = new ReactRootView(this);
layout.addView(mReactRootView);
setContentView(layout);
startReactApplication();
}
private void startReactApplication() {
mReactRootView.startReactApplication(getReactInstanceManager(), "WixRNNotifications", null);
} }
} }
...@@ -6,12 +6,18 @@ import com.facebook.react.ReactApplication; ...@@ -6,12 +6,18 @@ import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost; import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage; import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage; import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import com.wix.reactnativenotifications.RNNotificationsPackage; import com.wix.reactnativenotifications.RNNotificationsPackage;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
public class MainApplication extends Application implements ReactApplication { public class MainApplication extends Application implements ReactApplication {
@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, false);
}
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override @Override
......
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.wix.reactnativenotifications.app.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
>
<android.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.wix.reactnativenotifications.app.MainActivity">
</android.support.design.widget.CoordinatorLayout>
...@@ -13,7 +13,7 @@ function run() { ...@@ -13,7 +13,7 @@ function run() {
} }
function runAndroidUnitTests() { function runAndroidUnitTests() {
const conf = release ? 'testReleaseUnitTest' : 'testDebugUnitTest'; const conf = release ? 'testReactNative60ReleaseUnitTest' : 'testReactNative60DebugUnitTest';
if (android && process.env.JENKINS_CI) { if (android && process.env.JENKINS_CI) {
const sdkmanager = '/usr/local/share/android-sdk/tools/bin/sdkmanager'; const sdkmanager = '/usr/local/share/android-sdk/tools/bin/sdkmanager';
exec.execSync(`yes | ${sdkmanager} --licenses`); exec.execSync(`yes | ${sdkmanager} --licenses`);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment