diff --git a/README.md b/README.md index 54977b4..11bd5e5 100644 --- a/README.md +++ b/README.md @@ -4,36 +4,6 @@ `$ npm install rn-root-view --save` -### Mostly automatic installation - -`$ react-native link rn-root-view` - -### Manual installation - - -#### iOS - -1. In XCode, in the project navigator, right click `Libraries` ➜ `Add Files to [your project's name]` -2. Go to `node_modules` ➜ `rn-root-view` and add `RootView.xcodeproj` -3. In XCode, in the project navigator, select your project. Add `libRootView.a` to your project's `Build Phases` ➜ `Link Binary With Libraries` -4. Run your project (`Cmd+R`)< - -#### Android - -1. Open up `android/app/src/main/java/[...]/MainApplication.java` - - Add `import chat.rocket.RootViewPackage;` to the imports at the top of the file - - Add `new RootViewPackage()` to the list returned by the `getPackages()` method -2. Append the following lines to `android/settings.gradle`: - ``` - include ':rn-root-view' - project(':rn-root-view').projectDir = new File(rootProject.projectDir, '../node_modules/rn-root-view/android') - ``` -3. Insert the following lines inside the dependencies block in `android/app/build.gradle`: - ``` - compile project(':rn-root-view') - ``` - - ## Usage ```javascript import setRootViewColor from 'rn-root-view'; diff --git a/android/build.gradle b/android/build.gradle index 99031c9..75962f1 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,46 +1,44 @@ -// android/build.gradle - -def safeExtGet(prop, fallback) { - rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback -} - buildscript { - // The Android Gradle plugin is only required when opening the android folder stand-alone. - // This avoids unnecessary downloads and potential conflicts when the library is included as a - // module dependency in an application project. if (project == rootProject) { repositories { google() + mavenCentral() jcenter() } + dependencies { - classpath 'com.android.tools.build:gradle:3.4.1' + classpath 'com.android.tools.build:gradle:3.5.3' } } } apply plugin: 'com.android.library' -apply plugin: 'maven' -// Matches values in recent template from React Native 0.59 / 0.60 -// https://github.com/facebook/react-native/blob/0.59-stable/template/android/build.gradle#L5-L9 -// https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle#L5-L9 -def DEFAULT_COMPILE_SDK_VERSION = 28 -def DEFAULT_BUILD_TOOLS_VERSION = "28.0.3" -def DEFAULT_MIN_SDK_VERSION = 16 -def DEFAULT_TARGET_SDK_VERSION = 28 +def safeExtGet(prop, fallback) { + rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback +} android { - compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION) - buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION) + compileSdkVersion safeExtGet('compileSdkVersion', 29) defaultConfig { - minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION) - targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION) + minSdkVersion safeExtGet('minSdkVersion', 16) + targetSdkVersion safeExtGet('targetSdkVersion', 29) versionCode 1 versionName "1.0" + + } + + buildTypes { + release { + minifyEnabled false + } } lintOptions { - abortOnError false + disable 'GradleCompatible' + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 } } @@ -48,90 +46,14 @@ repositories { mavenLocal() maven { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm - url "$rootDir/../node_modules/react-native/android" - } - maven { - // Android JSC is installed from npm - url "$rootDir/../node_modules/jsc-android/dist" + url("$rootDir/../node_modules/react-native/android") } google() + mavenCentral() jcenter() } dependencies { - // ref: - // https://github.com/facebook/react-native/blob/0.61-stable/template/android/app/build.gradle#L192 //noinspection GradleDynamicVersion - implementation 'com.facebook.react:react-native:+' // From node_modules -} - -def configureReactNativePom(def pom) { - def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text) - - pom.project { - name packageJson.title - artifactId packageJson.name - version = packageJson.version - group = "chat.rocket.rootview" - description packageJson.description - url packageJson.repository.baseUrl - - licenses { - license { - name packageJson.license - url packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename - distribution 'repo' - } - } - - developers { - developer { - id packageJson.author.username - name packageJson.author.name - } - } - } -} - -afterEvaluate { project -> - // some Gradle build hooks ref: - // https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch03.html - task androidJavadoc(type: Javadoc) { - source = android.sourceSets.main.java.srcDirs - classpath += files(android.bootClasspath) - classpath += files(project.getConfigurations().getByName('compile').asList()) - include '**/*.java' - } - - task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) { - classifier = 'javadoc' - from androidJavadoc.destinationDir - } - - task androidSourcesJar(type: Jar) { - classifier = 'sources' - from android.sourceSets.main.java.srcDirs - include '**/*.java' - } - - android.libraryVariants.all { variant -> - def name = variant.name.capitalize() - task "jar${name}"(type: Jar, dependsOn: variant.javaCompile) { - from variant.javaCompile.destinationDir - } - } - - artifacts { - archives androidSourcesJar - archives androidJavadocJar - } - - task installArchives(type: Upload) { - configuration = configurations.archives - repositories.mavenDeployer { - // Deploy to react-native-event-bridge/maven, ready to publish to npm - repository url: "file://${projectDir}/../android/maven" - configureReactNativePom pom - } - } + implementation "com.facebook.react:react-native:+" // From node_modules } diff --git a/android/src/main/java/chat/rocket/rootview/RootViewModule.java b/android/src/main/java/chat/rocket/rootview/RootViewModule.java index 66fbb48..ac214e2 100644 --- a/android/src/main/java/chat/rocket/rootview/RootViewModule.java +++ b/android/src/main/java/chat/rocket/rootview/RootViewModule.java @@ -1,28 +1,32 @@ package chat.rocket.rootview; +import androidx.annotation.NonNull; + import android.app.Activity; import android.view.View; import android.graphics.Color; +import com.facebook.react.bridge.Promise; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactMethod; -import com.facebook.react.bridge.Callback; +import com.facebook.react.module.annotations.ReactModule; +@ReactModule(name = RootViewModule.NAME) public class RootViewModule extends ReactContextBaseJavaModule { - - private final ReactApplicationContext reactContext; + public static final String NAME = "RootView"; public RootViewModule(ReactApplicationContext reactContext) { super(reactContext); - this.reactContext = reactContext; } @Override + @NonNull public String getName() { - return "RootView"; + return NAME; } + @ReactMethod public void setColor(final String color) { final Activity activity = getCurrentActivity(); diff --git a/android/src/main/java/chat/rocket/rootview/RootViewPackage.java b/android/src/main/java/chat/rocket/rootview/RootViewPackage.java index ac23108..854ff74 100644 --- a/android/src/main/java/chat/rocket/rootview/RootViewPackage.java +++ b/android/src/main/java/chat/rocket/rootview/RootViewPackage.java @@ -1,23 +1,28 @@ package chat.rocket.rootview; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; +import androidx.annotation.NonNull; import com.facebook.react.ReactPackage; import com.facebook.react.bridge.NativeModule; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.uimanager.ViewManager; -import com.facebook.react.bridge.JavaScriptModule; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; public class RootViewPackage implements ReactPackage { + @NonNull @Override - public List createNativeModules(ReactApplicationContext reactContext) { - return Arrays.asList(new RootViewModule(reactContext)); + public List createNativeModules(@NonNull ReactApplicationContext reactContext) { + List modules = new ArrayList<>(); + modules.add(new RootViewModule(reactContext)); + return modules; } + @NonNull @Override - public List createViewManagers(ReactApplicationContext reactContext) { + public List createViewManagers(@NonNull ReactApplicationContext reactContext) { return Collections.emptyList(); } } diff --git a/package.json b/package.json index df099e0..d535635 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "rn-root-view", "title": "React Native Root View", - "version": "1.0.3", + "version": "2.0.0", "description": "Change Root View Background color on React Native", "homepage": "https://github.com/RocketChat/rn-root-view", "main": "index.js", @@ -25,11 +25,11 @@ "licenseFilename": "LICENSE", "readmeFilename": "README.md", "peerDependencies": { - "react": "^16.8.1", - "react-native": ">=0.59.0-rc.0 <1.0.x" + "react": "^17.0.2", + "react-native": ">=0.68.2" }, "devDependencies": { - "react": "^16.8.3", - "react-native": "^0.59.10" + "react": "^17.0.2", + "react-native": "^0.68.2" } }