yeet
This commit is contained in:
85
node_modules/expo-image-loader/android/build.gradle
generated
vendored
Normal file
85
node_modules/expo-image-loader/android/build.gradle
generated
vendored
Normal file
@ -0,0 +1,85 @@
|
||||
apply plugin: 'com.android.library'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'maven'
|
||||
|
||||
buildscript {
|
||||
// Simple helper that allows the root project to override versions declared by this library.
|
||||
ext.safeExtGet = { prop, fallback ->
|
||||
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${safeExtGet("kotlinVersion", "1.3.50")}")
|
||||
}
|
||||
}
|
||||
|
||||
group = 'host.exp.exponent'
|
||||
version = '1.3.0'
|
||||
|
||||
// Upload android library to maven with javadoc and android sources
|
||||
configurations {
|
||||
deployerJars
|
||||
}
|
||||
|
||||
// Creating sources with comments
|
||||
task androidSourcesJar(type: Jar) {
|
||||
classifier = 'sources'
|
||||
from android.sourceSets.main.java.srcDirs
|
||||
}
|
||||
|
||||
// Put the androidSources and javadoc to the artifacts
|
||||
artifacts {
|
||||
archives androidSourcesJar
|
||||
}
|
||||
|
||||
uploadArchives {
|
||||
repositories {
|
||||
mavenDeployer {
|
||||
configuration = configurations.deployerJars
|
||||
repository(url: mavenLocal().url)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion safeExtGet("compileSdkVersion", 29)
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion safeExtGet("minSdkVersion", 21)
|
||||
targetSdkVersion safeExtGet("targetSdkVersion", 29)
|
||||
versionCode 7
|
||||
versionName "1.3.0"
|
||||
}
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility = '1.8'
|
||||
targetCompatibility = '1.8'
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
if (new File(rootProject.projectDir.parentFile, 'package.json').exists()) {
|
||||
apply from: project(":unimodules-core").file("../unimodules-core.gradle")
|
||||
} else {
|
||||
throw new GradleException(
|
||||
'\'unimodules-core.gradle\' was not found in the usual React Native dependency location. ' +
|
||||
'This package can only be used in such projects. Are you sure you\'ve installed the dependencies properly?')
|
||||
}
|
||||
|
||||
dependencies {
|
||||
unimodule 'unimodules-core'
|
||||
unimodule 'unimodules-image-loader-interface'
|
||||
|
||||
api "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${safeExtGet('kotlinVersion', '1.3.50')}"
|
||||
api 'com.github.bumptech.glide:glide:4.9.0'
|
||||
api 'com.facebook.fresco:fresco:2.0.0'
|
||||
}
|
2
node_modules/expo-image-loader/android/src/main/AndroidManifest.xml
generated
vendored
Normal file
2
node_modules/expo-image-loader/android/src/main/AndroidManifest.xml
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
<manifest package="expo.modules.imageloader">
|
||||
</manifest>
|
101
node_modules/expo-image-loader/android/src/main/java/expo/modules/imageloader/ImageLoaderModule.kt
generated
vendored
Normal file
101
node_modules/expo-image-loader/android/src/main/java/expo/modules/imageloader/ImageLoaderModule.kt
generated
vendored
Normal file
@ -0,0 +1,101 @@
|
||||
package expo.modules.imageloader
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.os.AsyncTask
|
||||
import androidx.annotation.NonNull
|
||||
import androidx.annotation.Nullable
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||
import com.bumptech.glide.request.target.SimpleTarget
|
||||
import com.bumptech.glide.request.transition.Transition
|
||||
import com.facebook.common.references.CloseableReference
|
||||
import com.facebook.datasource.DataSource
|
||||
import com.facebook.drawee.backends.pipeline.Fresco
|
||||
import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber
|
||||
import com.facebook.imagepipeline.image.CloseableImage
|
||||
import com.facebook.imagepipeline.request.ImageRequest
|
||||
import org.unimodules.core.interfaces.InternalModule
|
||||
import org.unimodules.interfaces.imageloader.ImageLoader
|
||||
import java.util.concurrent.ExecutionException
|
||||
import java.util.concurrent.Future
|
||||
|
||||
|
||||
class ImageLoaderModule(val context: Context) : InternalModule, ImageLoader {
|
||||
|
||||
override fun getExportedInterfaces(): List<Class<*>>? {
|
||||
return listOf(ImageLoader::class.java)
|
||||
}
|
||||
|
||||
override fun loadImageForDisplayFromURL(url: String): Future<Bitmap> {
|
||||
val future = SimpleSettableFuture<Bitmap>()
|
||||
loadImageForDisplayFromURL(url, object : ImageLoader.ResultListener {
|
||||
override fun onSuccess(bitmap: Bitmap) = future.set(bitmap)
|
||||
|
||||
override fun onFailure(@Nullable cause: Throwable?) = future.setException(ExecutionException(cause))
|
||||
})
|
||||
return future
|
||||
}
|
||||
|
||||
override fun loadImageForDisplayFromURL(url: String, resultListener: ImageLoader.ResultListener) {
|
||||
val imageRequest = ImageRequest.fromUri(url)
|
||||
val imagePipeline = Fresco.getImagePipeline()
|
||||
val dataSource = imagePipeline.fetchDecodedImage(imageRequest, context)
|
||||
|
||||
dataSource.subscribe(
|
||||
object : BaseBitmapDataSubscriber() {
|
||||
override fun onNewResultImpl(bitmap: Bitmap?) {
|
||||
bitmap?.let {
|
||||
resultListener.onSuccess(bitmap)
|
||||
return
|
||||
}
|
||||
|
||||
resultListener.onFailure(Exception("Loaded bitmap is null"))
|
||||
}
|
||||
|
||||
override fun onFailureImpl(@NonNull dataSource: DataSource<CloseableReference<CloseableImage>>) {
|
||||
resultListener.onFailure(dataSource.failureCause)
|
||||
}
|
||||
},
|
||||
AsyncTask.THREAD_POOL_EXECUTOR
|
||||
)
|
||||
}
|
||||
|
||||
override fun loadImageForManipulationFromURL(@NonNull url: String): Future<Bitmap> {
|
||||
val future = SimpleSettableFuture<Bitmap>()
|
||||
loadImageForManipulationFromURL(url, object : ImageLoader.ResultListener {
|
||||
override fun onSuccess(bitmap: Bitmap) = future.set(bitmap)
|
||||
|
||||
override fun onFailure(@NonNull cause: Throwable?) = future.setException(ExecutionException(cause))
|
||||
})
|
||||
return future
|
||||
}
|
||||
|
||||
override fun loadImageForManipulationFromURL(url: String, resultListener: ImageLoader.ResultListener) {
|
||||
val normalizedUrl = normalizeAssetsUrl(url)
|
||||
|
||||
Glide.with(context)
|
||||
.asBitmap()
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.skipMemoryCache(true)
|
||||
.load(normalizedUrl)
|
||||
.into(object : SimpleTarget<Bitmap>() {
|
||||
override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
|
||||
resultListener.onSuccess(resource)
|
||||
}
|
||||
|
||||
override fun onLoadFailed(errorDrawable: Drawable?) {
|
||||
resultListener.onFailure(Exception("Loading bitmap failed"))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun normalizeAssetsUrl(url: String): String {
|
||||
var actualUrl = url
|
||||
if (url.startsWith("asset:///")) {
|
||||
actualUrl = "file:///android_asset/" + url.split("/").last()
|
||||
}
|
||||
return actualUrl
|
||||
}
|
||||
}
|
9
node_modules/expo-image-loader/android/src/main/java/expo/modules/imageloader/ImageLoaderPackage.kt
generated
vendored
Normal file
9
node_modules/expo-image-loader/android/src/main/java/expo/modules/imageloader/ImageLoaderPackage.kt
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
package expo.modules.imageloader
|
||||
|
||||
import android.content.Context
|
||||
import org.unimodules.core.BasePackage
|
||||
import org.unimodules.core.interfaces.InternalModule
|
||||
|
||||
class ImageLoaderPackage : BasePackage() {
|
||||
override fun createInternalModules(context: Context): List<InternalModule> = listOf(ImageLoaderModule(context))
|
||||
}
|
120
node_modules/expo-image-loader/android/src/main/java/expo/modules/imageloader/SimpleSettableFuture.java
generated
vendored
Normal file
120
node_modules/expo-image-loader/android/src/main/java/expo/modules/imageloader/SimpleSettableFuture.java
generated
vendored
Normal file
@ -0,0 +1,120 @@
|
||||
// Copied from React Native
|
||||
package expo.modules.imageloader;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
/**
|
||||
* A super simple Future-like class that can safely notify another Thread when a value is ready.
|
||||
* Does not support canceling.
|
||||
*/
|
||||
public class SimpleSettableFuture<T> implements Future<T> {
|
||||
private final CountDownLatch mReadyLatch = new CountDownLatch(1);
|
||||
private @Nullable
|
||||
T mResult;
|
||||
private @Nullable
|
||||
Exception mException;
|
||||
|
||||
/**
|
||||
* Sets the result. If another thread has called {@link #get}, they will immediately receive the
|
||||
* value. set or setException must only be called once.
|
||||
*/
|
||||
public void set(@Nullable T result) {
|
||||
checkNotSet();
|
||||
mResult = result;
|
||||
mReadyLatch.countDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the exception. If another thread has called {@link #get}, they will immediately receive
|
||||
* the exception. set or setException must only be called once.
|
||||
*/
|
||||
public void setException(Exception exception) {
|
||||
checkNotSet();
|
||||
mException = exception;
|
||||
mReadyLatch.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cancel(boolean mayInterruptIfRunning) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDone() {
|
||||
return mReadyLatch.getCount() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable
|
||||
T get() throws InterruptedException, ExecutionException {
|
||||
mReadyLatch.await();
|
||||
if (mException != null) {
|
||||
throw new ExecutionException(mException);
|
||||
}
|
||||
|
||||
return mResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait up to the timeout time for another Thread to set a value on this future. If a value has
|
||||
* already been set, this method will return immediately.
|
||||
*
|
||||
* <p>NB: For simplicity, we catch and wrap InterruptedException. Do NOT use this class if you are
|
||||
* in the 1% of cases where you actually want to handle that.
|
||||
*/
|
||||
@Override
|
||||
public @Nullable
|
||||
T get(long timeout, TimeUnit unit)
|
||||
throws InterruptedException, ExecutionException, TimeoutException {
|
||||
if (!mReadyLatch.await(timeout, unit)) {
|
||||
throw new TimeoutException("Timed out waiting for result");
|
||||
}
|
||||
if (mException != null) {
|
||||
throw new ExecutionException(mException);
|
||||
}
|
||||
|
||||
return mResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience wrapper for {@link #get()} that re-throws get()'s Exceptions as RuntimeExceptions.
|
||||
*/
|
||||
public @Nullable
|
||||
T getOrThrow() {
|
||||
try {
|
||||
return get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience wrapper for {@link #get(long, TimeUnit)} that re-throws get()'s Exceptions as
|
||||
* RuntimeExceptions.
|
||||
*/
|
||||
public @Nullable
|
||||
T getOrThrow(long timeout, TimeUnit unit) {
|
||||
try {
|
||||
return get(timeout, unit);
|
||||
} catch (InterruptedException | ExecutionException | TimeoutException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkNotSet() {
|
||||
if (mReadyLatch.getCount() == 0) {
|
||||
throw new RuntimeException("Result has already been set!");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user