Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ android/app/libs
android/keystores/debug.keystore

# Expo
.expo/*
.expo/

# Turborepo
.turbo/

# generated by bob
lib/

# VSCode history extension
.history
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16.18.1
107 changes: 26 additions & 81 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,38 +1,42 @@
buildscript {
repositories {
google()
mavenCentral()
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath "com.android.tools.build:gradle:7.2.1"

}
}

def isNewArchitectureEnabled() {
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
}

apply plugin: 'com.android.library'
apply plugin: "com.android.library"


def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }

if (isNewArchitectureEnabled()) {
apply plugin: 'com.facebook.react'
apply plugin: "com.facebook.react"
}

def getExtOrDefault(name) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['ImageResizer_' + name]
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["ImageResizer_" + name]
}

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

android {
compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")

defaultConfig {
minSdkVersion getExtOrIntegerDefault('minSdkVersion')
targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
}
buildTypes {
Expand All @@ -42,19 +46,24 @@ android {
}

lintOptions {
disable 'GradleCompatible'
disable "GradleCompatible"
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

sourceSets {
main {
if (isNewArchitectureEnabled()) {
java.srcDirs += ['src/turbo']
java.srcDirs += [
"src/newarch",
// This is needed to build Kotlin project with NewArch enabled
"${project.buildDir}/generated/source/codegen/java"
]
} else {
java.srcDirs += ['src/legacy']
java.srcDirs += ["src/oldarch"]
}
}
}
Expand All @@ -63,79 +72,15 @@ android {
repositories {
mavenCentral()
google()

def found = false
def defaultDir = null
def androidSourcesName = 'React Native sources'

if (rootProject.ext.has('reactNativeAndroidRoot')) {
defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
} else {
defaultDir = new File(
projectDir,
'/../../../node_modules/react-native/android'
)
}

if (defaultDir.exists()) {
maven {
url defaultDir.toString()
name androidSourcesName
}

logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}")
found = true
} else {
def parentDir = rootProject.projectDir

1.upto(5, {
if (found) return true
parentDir = parentDir.parentFile

def androidSourcesDir = new File(
parentDir,
'node_modules/react-native'
)

def androidPrebuiltBinaryDir = new File(
parentDir,
'node_modules/react-native/android'
)

if (androidPrebuiltBinaryDir.exists()) {
maven {
url androidPrebuiltBinaryDir.toString()
name androidSourcesName
}

logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}")
found = true
} else if (androidSourcesDir.exists()) {
maven {
url androidSourcesDir.toString()
name androidSourcesName
}

logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}")
found = true
}
})
}

if (!found) {
throw new GradleException(
"${project.name}: unable to locate React Native android sources. " +
"Ensure you have you installed React Native as a dependency in your project and try again."
)
}
}


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

if (isNewArchitectureEnabled()) {
Expand Down
32 changes: 0 additions & 32 deletions android/src/legacy/ImageResizerModule.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,39 +1,52 @@
package com.reactnativeimageresizer;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.AsyncTask;
import android.util.Log;

import androidx.annotation.Nullable;
import androidx.annotation.NonNull;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.GuardedAsyncTask;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.ReactMethod;


import java.io.File;
import java.io.IOException;
import java.util.UUID;

public class ImageResizerModuleImpl {
public class ImageResizerModule extends ImageResizerSpec {
public static final String NAME = "ImageResizer";

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) {
ImageResizerModule(ReactApplicationContext reactContext) {
super(reactContext);
}

@Override
@NonNull
public String getName() {
return NAME;
}

@ReactMethod
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) {
WritableMap options = Arguments.createMap();
options.putString("mode", mode);
options.putBoolean("onlyScaleDown", onlyScaleDown);

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

@SuppressLint("LongLogTag")
private static Object createResizedImageWithExceptions(String imagePath, int newWidth, int newHeight,
private Object createResizedImageWithExceptions(String imagePath, int newWidth, int newHeight,
String compressFormatString, int quality, int rotation, String outputPath,
final boolean keepMeta,
final ReadableMap options, Context context) throws IOException {
final ReadableMap options) throws IOException {

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

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

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

// Save the resulting image
File path = context.getCacheDir();
File path = this.getReactApplicationContext().getCacheDir();
if (outputPath != null) {
path = new File(outputPath);
}
Expand All @@ -80,11 +93,11 @@ private static Object createResizedImageWithExceptions(String imagePath, int new
// Copy file's metadata/exif info if required
if(keepMeta){
try{
ImageResizer.copyExif(context, imageUri, resizedImage.getAbsolutePath());
ImageResizer.copyExif(this.getReactApplicationContext(), imageUri, resizedImage.getAbsolutePath());
}
catch(Exception ignored){
Log.e("ImageResizer::createResizedImageWithExceptions", "EXIF copy failed", ignored);
};
}
}
} else {
throw new IOException("Error getting resized image path");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public ReactModuleInfoProvider getReactModuleInfoProvider() {
final Map<String, ReactModuleInfo> moduleInfos = new HashMap<>();
boolean isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
moduleInfos.put(
ImageResizerModuleImpl.NAME,
ImageResizerModule.NAME,
new ReactModuleInfo(
ImageResizerModuleImpl.NAME,
ImageResizerModuleImpl.NAME,
ImageResizerModule.NAME,
ImageResizerModule.NAME,
false, // canOverrideExistingModule
false, // needsEagerInit
true, // hasConstants
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.reactnativeimageresizer;

import com.facebook.react.bridge.ReactApplicationContext;

abstract class ImageResizerSpec extends NativeImageResizerSpec {
ImageResizerSpec(ReactApplicationContext context) {
super(context);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.reactnativeimageresizer;

import androidx.annotation.Nullable;

import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;

abstract class ImageResizerSpec extends ReactContextBaseJavaModule {

ImageResizerSpec(ReactApplicationContext context) {
super(context);
}

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);
}
30 changes: 0 additions & 30 deletions android/src/turbo/ImageResizerModule.java

This file was deleted.

1 change: 0 additions & 1 deletion example/.java-version

This file was deleted.

1 change: 1 addition & 0 deletions example/.node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18
1 change: 0 additions & 1 deletion example/.ruby-version

This file was deleted.

1 change: 1 addition & 0 deletions example/.watchmanconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Loading