Skip to content

Commit f53aa7d

Browse files
authored
Chore/upgrade rn (#370)
* chore: upgrade template to rn 71 * refactor: remove private context attribute
1 parent 675c96c commit f53aa7d

File tree

72 files changed

+6635
-6672
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+6635
-6672
lines changed

.gitignore

+4-4
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ android/app/libs
6161
android/keystores/debug.keystore
6262

6363
# Expo
64-
.expo/*
64+
.expo/
65+
66+
# Turborepo
67+
.turbo/
6568

6669
# generated by bob
6770
lib/
68-
69-
# VSCode history extension
70-
.history

.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
16.18.1

android/build.gradle

+26-81
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,42 @@
11
buildscript {
22
repositories {
3-
google()
4-
mavenCentral()
3+
google()
4+
mavenCentral()
55
}
66

77
dependencies {
8-
classpath 'com.android.tools.build:gradle:3.5.3'
8+
classpath "com.android.tools.build:gradle:7.2.1"
9+
910
}
1011
}
1112

1213
def isNewArchitectureEnabled() {
13-
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
14+
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
1415
}
1516

16-
apply plugin: 'com.android.library'
17+
apply plugin: "com.android.library"
18+
19+
20+
def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }
1721

1822
if (isNewArchitectureEnabled()) {
19-
apply plugin: 'com.facebook.react'
23+
apply plugin: "com.facebook.react"
2024
}
2125

2226
def getExtOrDefault(name) {
23-
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['ImageResizer_' + name]
27+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["ImageResizer_" + name]
2428
}
2529

2630
def getExtOrIntegerDefault(name) {
27-
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['ImageResizer_' + name]).toInteger()
31+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["ImageResizer_" + name]).toInteger()
2832
}
2933

3034
android {
31-
compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
35+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
3236

3337
defaultConfig {
34-
minSdkVersion getExtOrIntegerDefault('minSdkVersion')
35-
targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
38+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
39+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
3640
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
3741
}
3842
buildTypes {
@@ -42,19 +46,24 @@ android {
4246
}
4347

4448
lintOptions {
45-
disable 'GradleCompatible'
49+
disable "GradleCompatible"
4650
}
4751

4852
compileOptions {
4953
sourceCompatibility JavaVersion.VERSION_1_8
5054
targetCompatibility JavaVersion.VERSION_1_8
5155
}
56+
5257
sourceSets {
5358
main {
5459
if (isNewArchitectureEnabled()) {
55-
java.srcDirs += ['src/turbo']
60+
java.srcDirs += [
61+
"src/newarch",
62+
// This is needed to build Kotlin project with NewArch enabled
63+
"${project.buildDir}/generated/source/codegen/java"
64+
]
5665
} else {
57-
java.srcDirs += ['src/legacy']
66+
java.srcDirs += ["src/oldarch"]
5867
}
5968
}
6069
}
@@ -63,79 +72,15 @@ android {
6372
repositories {
6473
mavenCentral()
6574
google()
66-
67-
def found = false
68-
def defaultDir = null
69-
def androidSourcesName = 'React Native sources'
70-
71-
if (rootProject.ext.has('reactNativeAndroidRoot')) {
72-
defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
73-
} else {
74-
defaultDir = new File(
75-
projectDir,
76-
'/../../../node_modules/react-native/android'
77-
)
78-
}
79-
80-
if (defaultDir.exists()) {
81-
maven {
82-
url defaultDir.toString()
83-
name androidSourcesName
84-
}
85-
86-
logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}")
87-
found = true
88-
} else {
89-
def parentDir = rootProject.projectDir
90-
91-
1.upto(5, {
92-
if (found) return true
93-
parentDir = parentDir.parentFile
94-
95-
def androidSourcesDir = new File(
96-
parentDir,
97-
'node_modules/react-native'
98-
)
99-
100-
def androidPrebuiltBinaryDir = new File(
101-
parentDir,
102-
'node_modules/react-native/android'
103-
)
104-
105-
if (androidPrebuiltBinaryDir.exists()) {
106-
maven {
107-
url androidPrebuiltBinaryDir.toString()
108-
name androidSourcesName
109-
}
110-
111-
logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}")
112-
found = true
113-
} else if (androidSourcesDir.exists()) {
114-
maven {
115-
url androidSourcesDir.toString()
116-
name androidSourcesName
117-
}
118-
119-
logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}")
120-
found = true
121-
}
122-
})
123-
}
124-
125-
if (!found) {
126-
throw new GradleException(
127-
"${project.name}: unable to locate React Native android sources. " +
128-
"Ensure you have you installed React Native as a dependency in your project and try again."
129-
)
130-
}
13175
}
13276

13377

13478
dependencies {
135-
//noinspection GradleDynamicVersion
79+
// For < 0.71, this will be from the local maven repo
80+
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
81+
//noinspection GradleDynamicVersion
13682
implementation "com.facebook.react:react-native:+"
13783
implementation "androidx.exifinterface:exifinterface:1.3.2"
138-
// From node_modules
13984
}
14085

14186
if (isNewArchitectureEnabled()) {

android/src/legacy/ImageResizerModule.java

-32
This file was deleted.

android/src/main/java/com/reactnativeimageresizer/ImageResizerModuleImpl.java renamed to android/src/main/java/com/reactnativeimageresizer/ImageResizerModule.java

+24-11
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,52 @@
11
package com.reactnativeimageresizer;
22

33
import android.annotation.SuppressLint;
4-
import android.content.Context;
54
import android.graphics.Bitmap;
65
import android.net.Uri;
76
import android.os.AsyncTask;
87
import android.util.Log;
98

109
import androidx.annotation.Nullable;
10+
import androidx.annotation.NonNull;
1111

1212
import com.facebook.react.bridge.Arguments;
1313
import com.facebook.react.bridge.GuardedAsyncTask;
1414
import com.facebook.react.bridge.Promise;
1515
import com.facebook.react.bridge.ReactApplicationContext;
1616
import com.facebook.react.bridge.ReadableMap;
1717
import com.facebook.react.bridge.WritableMap;
18+
import com.facebook.react.bridge.ReactMethod;
19+
1820

1921
import java.io.File;
2022
import java.io.IOException;
2123
import java.util.UUID;
2224

23-
public class ImageResizerModuleImpl {
25+
public class ImageResizerModule extends ImageResizerSpec {
2426
public static final String NAME = "ImageResizer";
2527

26-
public static void createResizedImage(String uri, double width, double height, String format, double quality, Double rotation, @Nullable String outputPath, Boolean keepMeta, @Nullable String mode, Boolean onlyScaleDown, Promise promise, Context context, ReactApplicationContext reactContext) {
28+
ImageResizerModule(ReactApplicationContext reactContext) {
29+
super(reactContext);
30+
}
31+
32+
@Override
33+
@NonNull
34+
public String getName() {
35+
return NAME;
36+
}
37+
38+
@ReactMethod
39+
public void createResizedImage(String uri, double width, double height, String format, double quality, String mode, boolean onlyScaleDown, Double rotation, @Nullable String outputPath, Boolean keepMeta, Promise promise) {
2740
WritableMap options = Arguments.createMap();
2841
options.putString("mode", mode);
2942
options.putBoolean("onlyScaleDown", onlyScaleDown);
3043

3144
// Run in guarded async task to prevent blocking the React bridge
32-
new GuardedAsyncTask<Void, Void>(reactContext) {
45+
new GuardedAsyncTask<Void, Void>(this.getReactApplicationContext()) {
3346
@Override
3447
protected void doInBackgroundGuarded(Void... params) {
3548
try {
36-
Object response = createResizedImageWithExceptions(uri, (int) width, (int) height, format, (int) quality, rotation.intValue(), outputPath, keepMeta, options, context);
49+
Object response = createResizedImageWithExceptions(uri, (int) width, (int) height, format, (int) quality, rotation.intValue(), outputPath, keepMeta, options);
3750
promise.resolve(response);
3851
}
3952
catch (IOException e) {
@@ -44,23 +57,23 @@ protected void doInBackgroundGuarded(Void... params) {
4457
}
4558

4659
@SuppressLint("LongLogTag")
47-
private static Object createResizedImageWithExceptions(String imagePath, int newWidth, int newHeight,
60+
private Object createResizedImageWithExceptions(String imagePath, int newWidth, int newHeight,
4861
String compressFormatString, int quality, int rotation, String outputPath,
4962
final boolean keepMeta,
50-
final ReadableMap options, Context context) throws IOException {
63+
final ReadableMap options) throws IOException {
5164

5265
Bitmap.CompressFormat compressFormat = Bitmap.CompressFormat.valueOf(compressFormatString);
5366
Uri imageUri = Uri.parse(imagePath);
5467

55-
Bitmap scaledImage = ImageResizer.createResizedImage(context, imageUri, newWidth, newHeight, quality, rotation,
68+
Bitmap scaledImage = ImageResizer.createResizedImage(this.getReactApplicationContext(), imageUri, newWidth, newHeight, quality, rotation,
5669
options.getString("mode"), options.getBoolean("onlyScaleDown"));
5770

5871
if (scaledImage == null) {
5972
throw new IOException("The image failed to be resized; invalid Bitmap result.");
6073
}
6174

6275
// Save the resulting image
63-
File path = context.getCacheDir();
76+
File path = this.getReactApplicationContext().getCacheDir();
6477
if (outputPath != null) {
6578
path = new File(outputPath);
6679
}
@@ -80,11 +93,11 @@ private static Object createResizedImageWithExceptions(String imagePath, int new
8093
// Copy file's metadata/exif info if required
8194
if(keepMeta){
8295
try{
83-
ImageResizer.copyExif(context, imageUri, resizedImage.getAbsolutePath());
96+
ImageResizer.copyExif(this.getReactApplicationContext(), imageUri, resizedImage.getAbsolutePath());
8497
}
8598
catch(Exception ignored){
8699
Log.e("ImageResizer::createResizedImageWithExceptions", "EXIF copy failed", ignored);
87-
};
100+
}
88101
}
89102
} else {
90103
throw new IOException("Error getting resized image path");

android/src/main/java/com/reactnativeimageresizer/ImageResizerPackage.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ public ReactModuleInfoProvider getReactModuleInfoProvider() {
2929
final Map<String, ReactModuleInfo> moduleInfos = new HashMap<>();
3030
boolean isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
3131
moduleInfos.put(
32-
ImageResizerModuleImpl.NAME,
32+
ImageResizerModule.NAME,
3333
new ReactModuleInfo(
34-
ImageResizerModuleImpl.NAME,
35-
ImageResizerModuleImpl.NAME,
34+
ImageResizerModule.NAME,
35+
ImageResizerModule.NAME,
3636
false, // canOverrideExistingModule
3737
false, // needsEagerInit
3838
true, // hasConstants
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.reactnativeimageresizer;
2+
3+
import com.facebook.react.bridge.ReactApplicationContext;
4+
5+
abstract class ImageResizerSpec extends NativeImageResizerSpec {
6+
ImageResizerSpec(ReactApplicationContext context) {
7+
super(context);
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.reactnativeimageresizer;
2+
3+
import androidx.annotation.Nullable;
4+
5+
import com.facebook.react.bridge.Promise;
6+
import com.facebook.react.bridge.ReactApplicationContext;
7+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
8+
9+
abstract class ImageResizerSpec extends ReactContextBaseJavaModule {
10+
11+
ImageResizerSpec(ReactApplicationContext context) {
12+
super(context);
13+
}
14+
15+
public abstract void createResizedImage(String uri, double width, double height, String format, double quality, String mode, boolean onlyScaleDown, Double rotation, @Nullable String outputPath, Boolean keepMeta, Promise promise);
16+
}

android/src/turbo/ImageResizerModule.java

-30
This file was deleted.

example/.java-version

-1
This file was deleted.

example/.node-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
18

example/.ruby-version

-1
This file was deleted.

example/.watchmanconfig

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

0 commit comments

Comments
 (0)