diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/fresco/FrescoModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/fresco/FrescoModule.java index 161aa8248..36cced20e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/fresco/FrescoModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/fresco/FrescoModule.java @@ -111,14 +111,23 @@ public class FrescoModule extends ReactContextBaseJavaModule implements } private static ImagePipelineConfig getDefaultConfig(Context context) { + return getDefaultConfigBuilder(context).build(); + } + + /** + * Get the default Fresco configuration builder. + * Allows adding of configuration options in addition to the default values. + * + * @return {@link ImagePipelineConfig.Builder} that has been initialized with default values + */ + public static ImagePipelineConfig.Builder getDefaultConfigBuilder(Context context) { HashSet requestListeners = new HashSet<>(); requestListeners.add(new SystraceRequestListener()); return OkHttpImagePipelineConfigFactory .newBuilder(context.getApplicationContext(), OkHttpClientProvider.getOkHttpClient()) .setDownsampleEnabled(false) - .setRequestListeners(requestListeners) - .build(); + .setRequestListeners(requestListeners); } private static class FrescoHandler implements SoLoaderShim.Handler { diff --git a/ReactAndroid/src/main/java/com/facebook/react/shell/BUCK b/ReactAndroid/src/main/java/com/facebook/react/shell/BUCK index 72b75d2d6..87d211e81 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/shell/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/shell/BUCK @@ -4,6 +4,7 @@ android_library( name = 'shell', srcs = glob(['**/*.java']), deps = [ + react_native_dep('libraries/fresco/fresco-react-native:imagepipeline'), react_native_dep('libraries/soloader/java/com/facebook/soloader:soloader'), react_native_dep('third-party/android/support/v4:lib-support-v4'), react_native_dep('third-party/java/infer-annotations:infer-annotations'), diff --git a/ReactAndroid/src/main/java/com/facebook/react/shell/MainPackageConfig.java b/ReactAndroid/src/main/java/com/facebook/react/shell/MainPackageConfig.java new file mode 100644 index 000000000..a5fd60a15 --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/react/shell/MainPackageConfig.java @@ -0,0 +1,42 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +package com.facebook.react.shell; + +import com.facebook.imagepipeline.core.ImagePipelineConfig; + +/** + * Configuration for {@link MainReactPackage} + */ +public class MainPackageConfig { + + private ImagePipelineConfig mFrescoConfig; + + private MainPackageConfig(Builder builder) { + mFrescoConfig = builder.mFrescoConfig; + } + + public ImagePipelineConfig getFrescoConfig() { + return mFrescoConfig; + } + + public static class Builder { + + private ImagePipelineConfig mFrescoConfig; + + public Builder setFrescoConfig(ImagePipelineConfig frescoConfig) { + mFrescoConfig = frescoConfig; + return this; + } + + public MainPackageConfig build() { + return new MainPackageConfig(this); + } + } +} diff --git a/ReactAndroid/src/main/java/com/facebook/react/shell/MainReactPackage.java b/ReactAndroid/src/main/java/com/facebook/react/shell/MainReactPackage.java index d2daf6f26..9bb4a0de5 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/shell/MainReactPackage.java +++ b/ReactAndroid/src/main/java/com/facebook/react/shell/MainReactPackage.java @@ -74,6 +74,18 @@ import com.facebook.react.views.webview.ReactWebViewManager; */ public class MainReactPackage extends LazyReactPackage { + private MainPackageConfig mConfig; + + public MainReactPackage() { + } + + /** + * Create a new package with configuration + */ + public MainReactPackage(MainPackageConfig config) { + mConfig = config; + } + @Override public List getNativeModules(final ReactApplicationContext context) { return Arrays.asList( @@ -116,7 +128,7 @@ public class MainReactPackage extends LazyReactPackage { new ModuleSpec(FrescoModule.class, new Provider() { @Override public NativeModule get() { - return new FrescoModule(context); + return new FrescoModule(context, mConfig != null ? mConfig.getFrescoConfig() : null); } }), new ModuleSpec(I18nManagerModule.class, new Provider() {